def users(self, name=None, *args, **kwargs): def modifier(roles): return [ dict(as_user=role.as_user, servers=role.servers) for role in roles ] if name: user = User.visible(request).filter(User.username == name).first() return O.user( user.serialize(skip=['id', 'org_id', 'password'], rel=[('groups.name', 'groups')])) else: users = [ u.serialize(skip=['id', 'org_id', 'password'], rel=[('groups.name', 'groups')]) for u in User.visible(request).options(joinedload(User.groups)).all() ] groups = [ u.serialize(skip=['id', 'org_id'], rel=[ ('roles', 'roles', modifier), ('users', 'users', lambda us: [u.username for u in us]), ]) for u in Group.visible(request).options(joinedload( Group.users)).options(joinedload(Group.roles)).all() ] return O._anon(users=users, groups=groups, quota=dict(users=request.user.tier.users, groups=request.user.tier.groups))
def profile(self, *args, **kwargs): user = User.visible(request).filter( User.username == request.user.username).one() used = { 'total_repos': 0, 'cron_jobs': 0, 'api_keys': 0, 'users': 0, 'groups': 0, 'nodes': 0 } used['total_repos'] = Repository.count(request) used['cron_jobs'] = Job.count(request) used['api_keys'] = ApiKey.count(request) used['users'] = User.count(request) used['groups'] = Group.count(request) used['nodes'] = Node.count(request) used['deployments'] = Deployment.count(request) used['cloud_profiles'] = CloudProfile.count(request) quotas = dict((k, dict(allowed=v, used=used[k])) for k, v in request.user.tier._items.items() if k in used) return O.user(quotas=quotas, plan=request.user.tier.name, **user.serialize(skip=['id', 'org_id', 'password'], rel=[('groups.name', 'groups')]))
def profile(self, *args, **kwargs): user = User.visible(request).filter( User.username == request.user.username).one() used = {'total_repos': 0, 'cron_jobs': 0, 'api_keys': 0, 'users': 0, 'groups': 0, 'nodes': 0} used['total_repos'] = Repository.count(request) used['cron_jobs'] = Job.count(request) used['api_keys'] = ApiKey.count(request) used['users'] = User.count(request) used['groups'] = Group.count(request) used['nodes'] = Node.count(request) used['deployments'] = Deployment.count(request) used['cloud_profiles'] = CloudProfile.count(request) quotas = dict((k, dict(allowed=v, used=used[k])) for k, v in request.user.tier._items.items() if k in used) return O.user(quotas=quotas, plan=request.user.tier.name, **user.serialize( skip=['id', 'org_id', 'password'], rel=[('groups.name', 'groups')]))