forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusers.py
More file actions
61 lines (50 loc) · 2.04 KB
/
users.py
File metadata and controls
61 lines (50 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import graphene
from graphene import relay
from graphene_sqlalchemy import SQLAlchemyObjectType
from schemas.user import User
from schemas.shared_structures.organizations import Organizations
from models import Users as UserModel
from models import User_affiliations
from models import Organizations as OrgModel
from scalars.email_address import EmailAddress
from enums.roles import RoleEnums
class Users(SQLAlchemyObjectType):
"""
This object is used to return a list of users with their user name, display
name and their permission for the requested organization
"""
class Meta:
model = User_affiliations
interfaces = (relay.Node,)
exclude_fields = (
"id",
"user_id",
"organization_id",
"permission",
"user",
"user_organization",
)
user_name = EmailAddress(description="Email that the user signed up with")
display_name = graphene.String(description="Name displayed to other users")
permission = RoleEnums(
description="The level of access this user has to the requested " "organization"
)
def resolve_user_name(self: User_affiliations, info, **kwargs):
query = User.get_query(info)
query = query.filter(Organizations.id == self.organization_id)
query = query.filter(UserModel.id == self.user_id).first()
return query.user_name
def resolve_display_name(self: User_affiliations, info, **kwargs):
query = User.get_query(info)
query = query.filter(Organizations.id == self.organization_id)
query = query.filter(UserModel.id == self.user_id).first()
return query.display_name
def resolve_permission(self: User_affiliations, info, **kwargs):
return self.permission
def resolve_affiliations(self: User_affiliations, info, **kwargs):
query = Organizations.get_query(info)
query = query.filter(OrgModel.users.user_id == self.id)
return query.all()
class UserConnection(relay.Connection):
class Meta:
node = Users