This repository has been archived by the owner on Oct 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
cognito_groups.py
72 lines (59 loc) · 1.81 KB
/
cognito_groups.py
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
#!/usr/bin/env python
def get_group_list():
group_map = get_group_map()
groups = group_map.values()
return groups
def get_group_map():
groups = {
"standard-download": {
"preference": 10,
"value": "standard-download",
"display": "Standard download user",
},
"standard-upload": {
"preference": 20,
"value": "standard-upload",
"display": "Standard download and upload user",
},
"admin-view": {
"preference": 70,
"value": "admin-view",
"display": "User administrator read-only",
},
"admin-power": {
"preference": 80,
"value": "admin-power",
"display": "User administrator power (reinvite/disable)",
},
"admin-full": {
"preference": 90,
"value": "admin-full",
"display": "User administrator full access",
},
}
return groups
def get_group_by_name(group_name):
if group_name is None:
group_name = "standard-download"
return get_group_map()[group_name]
def user_groups(group_value=None):
groups = get_group_list()
if group_value is not None:
for group in groups:
if group_value == group["value"]:
return [group]
return user_groups("standard-download")
return groups
def return_users_group(user=None):
"""
Return the users current group or the default
group for new users if not specified
"""
default_group_name = "standard-download"
group_map = get_group_map()
default_group = group_map[default_group_name]
try:
group = user.get("group", default_group)
except (ValueError, KeyError, AttributeError):
group = default_group
return group