def members_add(actor, group_id=None, group_key=None, group=None, user_id=None, user_key=None, user=None): permission_verify(actor, "member", "update") user_key = user_key or build_user_key(user_id) or user.key group_key = group_key or build_group_key(group_id) or group.key user = user or user_key.get() group = group or group_key.get() if not group.users: group.users = [user_key] else: users = set(group.users) users.add(user_key) group.users = users group.put() if user: if not user.groups: user.groups = [group.key] else: groups = set(user.groups) groups.add(group.key) user.groups = groups user.put()
def members_add(actor, group_id=None, group_key=None, group=None, user_id=None, user_key=None, user=None): permission_verify(actor, "member", "update") user_key = user_key or build_user_key( user_id ) or user.key group_key = group_key or build_group_key(group_id) or group.key user = user or user_key.get() group = group or group_key.get() if not group.users: group.users = [ user_key ] else: users = set(group.users) users.add(user_key) group.users = users group.put() if user: if not user.groups: user.groups = [ group.key ] else: groups = set(user.groups) groups.add(group.key) user.groups = groups user.put()
def create(actor, alias_key=None, alias_id=None, user_id=None, user_key=None, user=None, group_id=None, group_key=None, group=None, **kwargs): permission_verify(actor, "alias", "create") user_key = user_key or build_user_key(user or user_id) group_key = group_key or build_group_key(group or group_id) if not user_key and not group_key: raise IllegalError("Aliases must specify either a user or a group") if user_key and group_key: raise IllegalError("Aliases must specify either a user or a group") alias_key = alias_key or key(alias_id) alias = Alias(key=alias_key) alias.alias = users.User(alias_key.id()) alias.user = user_key alias.group = group_key alias.created_by = build_user_key(actor) alias.put() return alias
def get(alias_id=None, alias_key=None, alias=None): permission_verify(actor, "alias", "read") result = alias or (alias_key or key(alias_id)).get() if result: return result else: raise NotFoundError()
def create(actor, user_key=None, user_id=None, active=True, **kwargs): permission_verify(actor, "user", "create") user_key = user_key or key(user_id) user = User(key=user_key) user.user = users.User(user_key.id()) user.created_by = key(actor) return set(actor, user, active=True, **kwargs)
def create(actor, group_id=None, group_key=None, active=True, **kwargs): permission_verify(actor, "group", "create") group_key = group_key or key(group_id) group = Group(key=group_key) group.group = users.User(group_key.id()) group.created_by = build_user_key(actor) return set(actor, group, active=True, **kwargs)
def members_clear(actor, group_id=None, group_key=None, group=None): permission_verify(actor, "member", "update") group = group or (group_key or build_group_key(group_id)).get() for user_key in group.users: user = user_key.get() if user and user.groups and group.key in user.groups: user.groups.remove(group.key) user.put() group.users = [] group.put()
def members_remove(actor, group_id=None, group_key=None, group=None, user_id=None, user_key=None, user=None): permission_verify(actor, "member", "update") user_key = user_key or build_user_key( user_id ) or user.key group_key = group_key or build_group_key(group_id) or group.key user = user or user_key.get() group = group or group_key.get() if group.users: group.users.remove(user_key) if user and user.groups: user.groups.remove(group_key) group.put() user.put()
def get(actor, group_id=None, group_key=None, group=None, silent=False): permission_verify(actor, "group", "read") if group: return group group_key = group_key or key(group_id) if group_key: result = group_key.get() if result: return result if silent: return None else: raise NotFoundError()
def get(actor, user_id=None, user_key=None, user=None, silent=False): if actor: permission_verify(actor, "user", "read") if user: return user user_key = user_key or key(user_id) if user_key: result = user_key.get() if result: return result if silent: return None else: raise NotFoundError()
def members_remove(actor, group_id=None, group_key=None, group=None, user_id=None, user_key=None, user=None): permission_verify(actor, "member", "update") user_key = user_key or build_user_key(user_id) or user.key group_key = group_key or build_group_key(group_id) or group.key user = user or user_key.get() group = group or group_key.get() if group.users: group.users.remove(user_key) if user and user.groups: user.groups.remove(group_key) group.put() user.put()
def delete(actor, alias_id=None, alias_key=None, alias=None, **ignored): permission_verify(actor, "alias", "delete") return get(alias_id, alias_key, alias).delete()
def list(actor): permission_verify(actor, "user", "read") return User.query().filter(User.active == True).fetch()
def deactivate(actor, user_id=None, user_key=None, user=None, **ignored): permission_verify(actor, "user", "update") return set(actor, get(actor, user_id, user_key, user), active=False)
def update(actor, user_id=None, user_key=None, user=None, **kwargs): permission_verify(actor, "user", "update") return set(actor, get(actor, user_id, user_key, user), **kwargs)
def list(actor): permission_verify(actor, "alias", "read") return Alias.query().get()
def update(actor, group_id=None, group_key=None, group=None, **kwargs): permission_verify(actor, "group", "update") return set(actor, get(actor, group_id, group_key, group), **kwargs)
def list(actor): permission_verify(actor, "group", "read") return Group.query().filter(Group.active == True)
def deactivate(actor, group_id=None, group_key=None, group=None, **ignored): permission_verify(actor, "group", "update") return set(actor, get(actor, group_id, group_key, group), active=False)