forked from fossasia/open-event-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
populate_db.py
88 lines (69 loc) · 3.45 KB
/
populate_db.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from app import current_app
from app.models.role import Role
from app.models.service import Service
from app.models.permission import Permission
from app.models.track import Track
from app.models.session import Session
from app.models.speaker import Speaker
from app.models.sponsor import Sponsor
from app.models.microlocation import Microlocation
from app.helpers.data import get_or_create
from app.models.user import ORGANIZER, COORGANIZER, TRACK_ORGANIZER, MODERATOR
def create_roles():
get_or_create(Role, name=ORGANIZER, title_name='Organizer')
get_or_create(Role, name=COORGANIZER, title_name='Co-organizer')
get_or_create(
Role, name=TRACK_ORGANIZER,
title_name='Track Organizer')
get_or_create(Role, name=MODERATOR, title_name='Moderator')
def create_services():
track = Track.get_service_name()
session = Session.get_service_name()
speaker = Speaker.get_service_name()
sponsor = Sponsor.get_service_name()
microlocation = Microlocation.get_service_name()
get_or_create(Service, name=track)
get_or_create(Service, name=session)
get_or_create(Service, name=speaker)
get_or_create(Service, name=sponsor)
get_or_create(Service, name=microlocation)
def create_permissions():
orgr = Role.query.get(1)
coorgr = Role.query.get(2)
track_orgr = Role.query.get(3)
mod = Role.query.get(4)
track = Service.query.get(1)
session = Service.query.get(2)
speaker = Service.query.get(3)
sponsor = Service.query.get(4)
microlocation = Service.query.get(5)
# For ORGANIZER
get_or_create(Permission, role=orgr, service=track, can_create=True, can_read=True, can_update=True, can_delete=True)
get_or_create(Permission, role=orgr, service=session, can_create=True, can_read=True, can_update=True, can_delete=True)
get_or_create(Permission, role=orgr, service=speaker, can_create=True, can_read=True, can_update=True, can_delete=True)
get_or_create(Permission, role=orgr, service=sponsor, can_create=True, can_read=True, can_update=True, can_delete=True)
get_or_create(Permission, role=orgr, service=microlocation, can_create=True, can_read=True, can_update=True, can_delete=True)
# For COORGANIZER
get_or_create(Permission, role=coorgr, service=track, can_create=False, can_read=True, can_update=True, can_delete=False)
get_or_create(Permission, role=coorgr, service=session, can_create=False, can_read=True, can_update=True, can_delete=False)
get_or_create(Permission, role=coorgr, service=speaker, can_create=False, can_read=True, can_update=True, can_delete=False)
get_or_create(Permission, role=coorgr, service=sponsor, can_create=False, can_read=True, can_update=True, can_delete=False)
get_or_create(Permission, role=coorgr, service=microlocation, can_create=False, can_read=True, can_update=True, can_delete=False)
# For TRACK_ORGANIZER
get_or_create(Permission, role=track_orgr, service=track, can_create=False, can_read=True, can_update=True, can_delete=False)
# For MODERATOR
get_or_create(Permission, role=mod, service=track, can_create=False, can_read=True, can_update=False, can_delete=False)
def populate():
"""
Create defined Roles, Services and Permissions.
"""
print
print 'Creating roles...'
create_roles()
print 'Creating services...'
create_services()
print 'Creating permissions...'
create_permissions()
if __name__ == '__main__':
with current_app.app_context():
populate()