-
Notifications
You must be signed in to change notification settings - Fork 4
/
user_access.py
executable file
·65 lines (57 loc) · 1.88 KB
/
user_access.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
#!/usr/bin/env python3
from sys import stdin, stdout, exit
from sqlalchemy.exc import IntegrityError
from hades import db
from hades.models.event import Events
from hades.models.user import Users
from hades.models.user_access import Access
def send_help():
print(
'Enter to continue, g to grant access to a user, h for help, Ctrl C/D to exit'
)
tables = db.engine.table_names()
for i in range(len(tables)):
table = tables[i]
current_event = db.session.query(Events).get(table)
if current_event is None:
print('Please run `db_setup.py` prior to using this!')
exit(1)
else:
print(f'{i + 1}. {current_event.name} - {current_event.full_name}')
try:
while True:
ch = int(
input(
'Enter the number of the table you wish to interact with, enter/Ctrl C/D to exit\ntable: '
)
)
table = tables[ch - 1]
send_help()
current_event = db.session.query(Events).get(table)
stdout.write(f'{table} -> ')
stdout.flush()
ch = input()[0]
if ch == 'h':
send_help()
elif ch == 'g':
username = input(f'Enter username that needs access to {table}: ')
user = db.session.query(Users).get(username)
if user is None:
print(f'User {username} does not seem to exist!')
break
access = Access(event=table, user=username)
try:
db.session.add(access)
db.session.commit()
except IntegrityError:
print('IntegrityError, what did you do!')
break
print(f'Granted access on {table} to {username}')
except EOFError:
print('Exiting!')
except KeyboardInterrupt:
print('Exiting!')
except IndexError:
print('No such table, exiting!')
except ValueError:
print('Exiting!')