-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.py
More file actions
44 lines (34 loc) · 1.3 KB
/
Copy pathUser.py
File metadata and controls
44 lines (34 loc) · 1.3 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
from pymongo import MongoClient
from Connection import Connection
cluster = MongoClient(
"mongodb+srv://Logan:lolo123@cluster0.igyjs.mongodb.net/ecole?retryWrites=true&w=majority")
db = cluster.testdb
collection = db.testcollection
roles = db.roles
class User:
def __init__(self):
pass
@property
def determine_role_user(self):
self.role_user = roles.find({"Role": "User"})
for i in self.role_user:
permissions = i['Permissions']
return permissions
def add_role_to_user(self, role):
self.role_user = roles.find({"Role": "User"})
for i in self.role_user:
self.permissions = i['Permissions']
self.permissions.append(role)
i["Permissions"] = self.permissions
roles.replace_one({"Role": "User"}, i)
return True
def remove_role_to_user(self, role):
self.role_user = roles.find({"Role": "User"})
for i in self.role_user:
self.permissions = i['Permissions']
if role in self.permissions:
self.permissions.remove(role)
i["Permissions"] = self.permissions
roles.replace_one({"Role": "User"}, i)
return True
return False