'For convenience, in_users and in_groups can be encoded IDs or emails/group names in the API.'

def validate_in_users_and_groups(self, trans, payload):

    def get_id(item, model_class, column):
        try:
            return trans.security.decode_id(item)
        except Exception:
            pass
        return trans.sa_session.query(model_class).filter((column == item)).first().id
    new_in_users = []
    new_in_groups = []
    invalid = []
    for item in util.listify(payload.get('in_users', [])):
        try:
            new_in_users.append(get_id(item, trans.app.model.User, trans.app.model.User.table.c.email))
        except Exception:
            invalid.append(item)
    for item in util.listify(payload.get('in_groups', [])):
        try:
            new_in_groups.append(get_id(item, trans.app.model.Group, trans.app.model.Group.table.c.name))
        except Exception:
            invalid.append(item)
    if invalid:
        msg = ('The    following    value(s)    for    associated    users    and/or    groups    could    not    be    parsed:    %s.' % ',    '.join(invalid))
        msg += '        Valid    values    are    email    addresses    of    users,    names    of    groups,    or    IDs    of    both.'
        raise Exception(msg)
    payload['in_users'] = list(map(str, new_in_users))
    payload['in_groups'] = list(map(str, new_in_groups))
