-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathrole.py
More file actions
111 lines (88 loc) · 2.33 KB
/
role.py
File metadata and controls
111 lines (88 loc) · 2.33 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
class Role:
"""Helper class to generate role strings for `Permission`."""
@staticmethod
def any():
"""Grants access to anyone.
This includes authenticated and unauthenticated users.
"""
return 'any'
@staticmethod
def user(id, status = ""):
"""Grants access to a specific user by user ID.
You can optionally pass verified or unverified for
`status` to target specific types of users.
Parameters
----------
id : str
status : str, optional
Returns
-------
str
"""
if status:
return f'user:{id}/{status}'
return f'user:{id}'
@staticmethod
def users(status = ""):
"""Grants access to any authenticated or anonymous user.
You can optionally pass verified or unverified for
`status` to target specific types of users.
Parameters
----------
status : str, optional
Returns
-------
str
"""
if status:
return f'users/{status}'
return 'users'
@staticmethod
def guests():
"""Grants access to any guest user without a session.
Authenticated users don't have access to this role.
Returns
-------
str
"""
return 'guests'
@staticmethod
def team(id, role = ""):
"""Grants access to a team by team ID.
You can optionally pass a role for `role` to target
team members with the specified role.
Parameters
----------
id : str
role : str, optional
Returns
-------
str
"""
if role:
return f'team:{id}/{role}'
return f'team:{id}'
@staticmethod
def member(id):
"""Grants access to a specific member of a team.
When the member is removed from the team, they will
no longer have access.
Parameters
----------
id : str
Returns
-------
str
"""
return f'member:{id}'
@staticmethod
def label(name):
"""Grants access to a user with the specified label.
Parameters
----------
name : str
Returns
-------
str
"""
return f'label:{name}'