forked from aluchici/cmi-portfolio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython-oop-desing.py
More file actions
208 lines (160 loc) · 5.49 KB
/
Copy pathpython-oop-desing.py
File metadata and controls
208 lines (160 loc) · 5.49 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
"""
Vreau un sistem pentru managementul utilizatorilor.
Un utilizator are urmatoarele detalii:
- nume
--> cum arata numele? first si last, first last in acelasi camp?
= first name si last name
- adresa de email
- parola
--> lungime minima?
= 10 caractere
--> caractere obligatorii?
= nu
- token
- fingerprint
- image
- ...
- tier
- parent
- companie
--> doar numele companiei sau si alte detalii?
= doar numele
- tip
--> ce tipuri de utilizatori exista?
= super admin, admin, employee
= super admin (per aplicatie), admin (per subscriptie), manager (per admin), employee (per admin)
= admin e unic per subscriptie
Sistemul de management al utilizatorilor vreau sa imi ofere urmatoarele functionalitati:
- creez un utilizator nou
--> ce detalii sunt obligatorii?
= nume, email, parola, tip, secret
--> creez utilizatori de orice tip?
= nu, doar manager si employee
--> cui ofera functionalitatea de a creea utilizatori noi?
= admin sau manager
= admin -> manager -> employee
= super admin -> admin
--> orice tip de utilizator poate create orice alt tip de utilizator?
= nu (vezi intrebarea anterioara)
--> am un numar limitat de noi utilizatori pe care ii pot crea?
= da, depinde de subscriptie
= tier 1: 2 managers si 10 employee per manager
= tier 2: 5 managers si 100 employee per manager
--> simultaneous login + sync?
= nu
- editez un utilizator existent
--> ce anume editez?
= tot
--> cine are voie sa editeze?
= user curent + admin + manager
= super admin -> admin
--> poate oricine sa editeze?
= da
= employee -> self
= manager -> self + employee care ii apartin lui
= admin -> self + manager care ii apartin lui
= super admin -> admin
--> vreau sa am o verificare inainte de a permite editarea?
= da
--> vreau sa trimit notificari despre ultima editare?
= da
--> putem sa schimbam tipul de user? (tip3 --> tip1)
= da
= doar admin poate schimba tipul
= pot trece din manager in employee sau din employee in manager
= super admin poate face alti admin
- schimb parola unui utilizator
--> poti refolosi o parola?
= nu
--> ce informatii sunt necesare pt schimbarea parolei?
= confirmarea parolei vechi
--> vrem sa avem 2 factor auth pt schimbarea parolei?
= nu
--> poate si alt user sa schimbe parola userului curent (exceptand userul curent)?
= super admin -> admin
= admin -> manager sau employee
--> doresc schimbarea parolei periodic?
= nu
- recuperez parola unui utilizator
--> se doreste folosirea unei informatii personale pentru recuperare?
= da, numele mamei
--> de cate ori?
= nu exista limita
--> cat de des?
= de 3 ori la 1h
--> cum fac asta?
= temporary password --> needs changing in 10m
= change password
- stergerea utilizatorilor (dezactivarea)
--> cine are voie sa ii stearga?
= manager sau admin
--> permanent sau temporar?
= temporar
--> pot reactiva un user?
= da
--> stergem / dezactivam utlizatori dupa X zile de inactivitate?
= nu
"""
from enum import Enum
class User:
def __init__(self, firstname, lastname, email, password, secret, user_type, company=None, tier=None, parent=None):
self.firstname = firstname
self.lastname = lastname
self.email = email
self.password = password
self.user_type = user_type
self.company = company
self.tier = tier
self.parent = parent
self.secret = secret
def edit_user(self):
pass
def change_password(self):
pass
def remind_password(self):
pass
def delete(self):
pass
def change_tier(self):
pass
@staticmethod
def validate_password(password):
if len(password) >= 10:
return password
else:
raise Exception("Invalid password provided")
@staticmethod
def validate_user_creation_by_tier(user_type, tier, parent):
if user_type is None or tier is None or parent is None:
raise Exception("Invalid user type, tier, or parent provided.")
# get user tree --> based on parent --> get all managers + employees
# get from database!
admins_num = 1
managers_num = 1
employees_num = 2
if user_type == UserTypeEnum.ADMIN and admins_num + 1 > 1:
raise Exception("Too many admins.")
if user_type == UserTypeEnum.MANAGER and managers_num + 1 > tier.max_number_of_managers:
raise Exception("Too many managers.")
if user_type == UserTypeEnum.EMPLOYEE and employees_num + 1 > tier.max_number_of_employees:
raise Exception("Too many employees.")
return True
@classmethod
def create_user(cls, firstname, lastname, email, password, secret, user_type, company=None, tier=None, parent=None):
password = cls.validate_password(password)
if cls.validate_user_creation_by_tier(user_type, tier, parent):
return cls(firstname, lastname, email, password, secret, user_type, company, tier, parent)
class Tier:
def __init__(self, max_number_of_managers, max_number_of_employees, name=None):
self.max_number_of_managers = max_number_of_managers
self.max_number_of_employees = max_number_of_employees
self.name = name
class UserTypeEnum(Enum):
SUPERADMIN = 1
ADMIN = 2
MANAGER = 3
EMPLOYEE = 4
if __name__ == "__main__":
tier1 = Tier(2, 10)
user = User.create_user('andrei', 'luchici', 'a@c.com', 'password1234456', '23423423', UserTypeEnum.ADMIN, tier=tier1)
manager = user.create_user('bogdan', 'vaduva', 'b@c.com', 'pasasrereqwqwq', '2daslfj', UserTypeEnum.MANAGER, tier=tier1)