forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorganizations.py
More file actions
87 lines (72 loc) · 2.95 KB
/
organizations.py
File metadata and controls
87 lines (72 loc) · 2.95 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import graphene
from graphene import relay
from graphene_sqlalchemy import SQLAlchemyObjectType
from schemas.shared_structures.domain import Domain as DomainsSchema
from schemas.user_affiliations import UserAffClass
from scalars.organization_acronym import Acronym
from scalars.slug import Slug
from models import Domains as DomainsModel
from models import Organizations as OrgModel
from models import User_affiliations as UserAffModel
from functions.auth_functions import is_admin
from functions.auth_wrappers import require_token
class Organizations(SQLAlchemyObjectType):
class Meta:
model = OrgModel
interfaces = (relay.Node,)
exclude_fields = (
"id",
"acronym",
"org_tags",
"domains",
"users",
"slug",
"name",
)
acronym = Acronym(description="The acronym of the organization.")
name = graphene.String(description="The full name of the organization.")
slug = Slug(description="Slug of the organizations name")
zone = graphene.String(description="The zone which the organization belongs to.")
sector = graphene.String(description="The sector which the organizaion belongs to.")
province = graphene.String(
description="The province in which the organization resides."
)
city = graphene.String(description="The city in which the organization resides.")
domains = graphene.ConnectionField(
DomainsSchema._meta.connection,
description="The domains which belong to this organization.",
)
affiliated_users = graphene.ConnectionField(
UserAffClass._meta.connection,
description="The users that have an affiliation with the organization.",
)
def resolve_acronym(self: OrgModel, info):
return self.acronym
def resolve_name(self: OrgModel, info):
return self.name
def resolve_slug(self: OrgModel, info):
return self.slug
def resolve_zone(self: OrgModel, info):
return self.org_tags.get("zone", None)
def resolve_sector(self: OrgModel, info):
return self.org_tags.get("sector", None)
def resolve_province(self: OrgModel, info):
return self.org_tags.get("province", None)
def resolve_city(self: OrgModel, info):
return self.org_tags.get("city", None)
def resolve_domains(self: OrgModel, info, **kwargs):
query = DomainsSchema.get_query(info)
query = query.filter(DomainsModel.organization_id == self.id).all()
return query
@require_token
def resolve_affiliated_users(self: OrgModel, info, **kwargs):
user_roles = kwargs.get("user_roles")
if is_admin(user_roles=user_roles, org_id=self.id):
query = UserAffClass.get_query(info)
query = query.filter(UserAffModel.organization_id == self.id).all()
return query
else:
return []
class OrganizationConnection(relay.Connection):
class Meta:
node = Organizations