-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin_give_role_to_user.py
More file actions
123 lines (93 loc) · 5.18 KB
/
Copy pathadmin_give_role_to_user.py
File metadata and controls
123 lines (93 loc) · 5.18 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
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.spinner import Spinner
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from function import manage_roles, determine_all_role, search_user_role
class GiveRole(BoxLayout):
def build(self):
self.orientation = "vertical"
self.welcome()
self.id_admin()
self.admin_user()
self.id_user_to_up()
self.user()
self.button_search_user()
self.role_from_user()
self.list_role()
self.role()
self.list_option_role()
self.validation_button()
def welcome(self):
self.label_welcome = Label(text="Welcome in the Admin Page", color=[0.59, 0.239, 0.89, 1],
pos_hint={'x': 0.25, 'y': 0.9}, size_hint=(.5, .01))
self.add_widget(self.label_welcome)
def warning(self):
self.label_warning = Label(text="If you are not a admin, you can not do everything", color=[0.59, 0.239, 0.89, 1],
pos_hint={'x': 0.25, 'y': 0.9}, size_hint=(.5, .01))
self.add_widget(self.label_warning)
def id_admin(self):
self.label_id_admin = Label(text="Please enter your username", color=[0.59, 0.239, 0.89, 1],
pos_hint={'x': 0.25, 'y': 0.9}, size_hint=(.5, .01))
self.add_widget(self.label_id_admin)
def admin_user(self):
self.input_admin_user = TextInput(pos_hint={'x': 0.25, 'y': 0.9}, size_hint=(.5, .01))
self.add_widget(self.input_admin_user)
def id_user_to_up(self):
self.label_id_user_to_up = Label(text="Enter the name of the user to whom to give a role", color=[0.59, 0.239, 0.89, 1],
pos_hint={'x': 0.25, 'y': 0.9}, size_hint=(.5, .01))
self.add_widget(self.label_id_user_to_up)
def user(self):
self.input_user = TextInput(pos_hint={'x': 0.25, 'y': 0.9}, size_hint=(.5, .01))
self.add_widget(self.input_user)
def button_search_user(self):
self.button_search_username = Button(text="Search user", size_hint=(.3, .02),
pos_hint={'x': 0.35, 'y' :0.1}, color=[1, 1, 1, 1], background_color=[0.59,0.239,0.89,1])
self.button_search_username.bind(on_press=self.search_role_user)
self.add_widget(self.button_search_username)
def role_from_user(self):
self.user_roles_label = Label(text="This is the role(s) that the user already has", color=[0.59, 0.239, 0.89, 1],
pos_hint={'x': 0.25, 'y': 0.9}, size_hint=(.5, .01))
self.add_widget(self.user_roles_label)
def id_role(self):
self.label_id_role = Label(text="Enter the name of the role you want to give", color=[0.59, 0.239, 0.89, 1],
pos_hint={'x': 0.25, 'y': 0.9}, size_hint=(.5, .01))
self.add_widget(self.label_id_role)
def list_role(self):
self.label_list_role = Label(text="Enter the name of the user to whom to give a role \n You can choose one if this : " + str(determine_all_role()), color=[0.59, 0.239, 0.89, 1],
pos_hint={'x': 0.25, 'y': 0.9}, size_hint=(.5, .01))
self.add_widget(self.label_list_role)
def role(self):
self.input_role = TextInput(pos_hint={'x': 0.25, 'y': 0.9}, size_hint=(.5, .01))
self.add_widget(self.input_role)
def list_option_role(self):
self.option_list = Spinner(text="Choose do remove or add",
values=("Add role", "Remove role"),
size_hint=(0.4, .01), pos_hint={'x': 0.3, 'y': 0.8}, background_color=[0.59,0.239,0.89,1])
self.add_widget(self.option_list)
def validation_button(self):
self.button_of_validation = Button(text="Give role", size_hint=(.3, .02),
pos_hint={'x': 0.35, 'y' :0.1}, color=[1, 1, 1, 1], background_color=[0.59,0.239,0.89,1])
self.button_of_validation.bind(on_press=self.give_role)
self.add_widget(self.button_of_validation)
# ----------------------------------------------------------- Space Graphic -----------------------------------------------------------#
def black_space(self):
self.black = Label(size_hint=(.4, .1))
self.add_widget(self.black)
def search_role_user(self, instance):
self.user_roles_label.text = "This is the role(s) that the user already has " + str(search_user_role(self.input_admin_user.text, self.input_user.text))
def give_role(self, instance):
admin = self.input_admin_user.text
user = self.input_user.text
role = self.input_role.text.upper()
add_remove = self.option_list.text
response = manage_roles(admin, user, add_remove, role)
self.label_welcome.text = str(response)
class Window(App):
def build(self):
Layout = GiveRole()
Layout.build()
return Layout
if __name__ == '__main__':
Window().run()