author | Sverre Rabbelier <srabbelier@gmail.com> |
Thu, 19 Mar 2009 17:10:26 +0000 | |
changeset 1939 | a1c53f546603 |
parent 1528 | abbdf42ab322 |
child 2956 | 50ce8ac13932 |
permissions | -rw-r--r-- |
1133 | 1 |
#!/usr/bin/python2.5 |
2 |
# |
|
1307
091a21cf3627
Update the copyright notice for 2009.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1299
diff
changeset
|
3 |
# Copyright 2009 the Melange authors. |
1133 | 4 |
# |
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
|
6 |
# you may not use this file except in compliance with the License. |
|
7 |
# You may obtain a copy of the License at |
|
8 |
# |
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
|
10 |
# |
|
11 |
# Unless required by applicable law or agreed to in writing, software |
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 |
# See the License for the specific language governing permissions and |
|
15 |
# limitations under the License. |
|
16 |
||
17 |
"""Module with rights related methods. |
|
18 |
""" |
|
19 |
||
20 |
__authors__ = [ |
|
21 |
'"Sverre Rabbelier" <sverre@rabbelier.nl>', |
|
22 |
] |
|
23 |
||
24 |
||
1299
e209bda5addb
Add a getMemberships method to logic/rights.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1143
diff
changeset
|
25 |
from soc.logic import dicts |
e209bda5addb
Add a getMemberships method to logic/rights.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1143
diff
changeset
|
26 |
|
1353
14a024c71415
Add missing blank line in soc.logic.rights module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
1318
diff
changeset
|
27 |
|
1133 | 28 |
class Checker(object): |
1136
aaf75aa8eca5
Added two forgotten comments in rights.Checker
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1133
diff
changeset
|
29 |
"""Checker class that maps from prefix and status to membership. |
1133 | 30 |
""" |
31 |
||
32 |
SITE_MEMBERSHIP = { |
|
33 |
'admin': [], |
|
34 |
'restricted': ['host'], |
|
35 |
'member': ['user'], |
|
1528
abbdf42ab322
Allow to do 'checkHasActiveRole' checks for document access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1353
diff
changeset
|
36 |
'list': ['host'], |
1133 | 37 |
} |
38 |
||
39 |
CLUB_MEMBERSHIP = { |
|
40 |
'admin': ['host', 'club_admin'], |
|
41 |
'restricted': ['host', 'club_admin'], |
|
42 |
'member': ['host', 'club_admin', 'club_member'], |
|
1318
3f41f33a4ad2
Add custom access check for document listing
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1314
diff
changeset
|
43 |
'list': ['host', 'club_admin', 'club_member'], |
1133 | 44 |
} |
45 |
||
46 |
SPONSOR_MEMBERSHIP = { |
|
47 |
'admin': ['host'], |
|
48 |
'restricted': ['host'], |
|
49 |
'member': ['host'], |
|
1318
3f41f33a4ad2
Add custom access check for document listing
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1314
diff
changeset
|
50 |
'list': ['host'], |
1133 | 51 |
} |
52 |
||
53 |
PROGRAM_MEMBERSHIP = { |
|
54 |
'admin': ['host'], |
|
55 |
'restricted': ['host', 'org_admin'], |
|
56 |
'member': ['host', 'org_admin', 'org_mentor', 'org_student'], |
|
1318
3f41f33a4ad2
Add custom access check for document listing
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1314
diff
changeset
|
57 |
'list': ['host', 'org_admin', 'org_mentor'], |
1133 | 58 |
} |
59 |
||
60 |
ORGANIZATION_MEMBERSHIP = { |
|
61 |
'admin': ['host', 'org_admin'], |
|
62 |
'restricted': ['host', 'org_admin', 'org_mentor'], |
|
63 |
'member': ['host', 'org_admin', 'org_mentor', 'org_student'], |
|
1318
3f41f33a4ad2
Add custom access check for document listing
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1314
diff
changeset
|
64 |
'list': ['host', 'org_admin', 'org_mentor'], |
1133 | 65 |
} |
66 |
||
67 |
USER_MEMBERSHIP = { |
|
68 |
'admin': ['user_self'], |
|
69 |
'restricted': ['user_self'], # ,'friends' |
|
70 |
'member': ['user'], |
|
1318
3f41f33a4ad2
Add custom access check for document listing
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1314
diff
changeset
|
71 |
'list': ['user_self'], |
1133 | 72 |
} |
73 |
||
74 |
RIGHTS = { |
|
75 |
'site': SITE_MEMBERSHIP, |
|
76 |
'club': CLUB_MEMBERSHIP, |
|
77 |
'sponsor': SPONSOR_MEMBERSHIP, |
|
78 |
'program': PROGRAM_MEMBERSHIP, |
|
1314
b832e02d70c1
Organization prefix was renamed to 'org'
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1307
diff
changeset
|
79 |
'org': ORGANIZATION_MEMBERSHIP, |
1133 | 80 |
'user': USER_MEMBERSHIP, |
81 |
} |
|
82 |
||
83 |
def __init__(self, prefix): |
|
1143
b07b7d5b3e27
Fix missing dots and blank lines to soc.logic modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
1136
diff
changeset
|
84 |
"""Constructs a Checker for the specified prefix. |
1133 | 85 |
""" |
86 |
||
87 |
self.prefix = prefix |
|
88 |
self.rights = self.RIGHTS[prefix] |
|
89 |
||
90 |
def getMembership(self, status): |
|
1136
aaf75aa8eca5
Added two forgotten comments in rights.Checker
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1133
diff
changeset
|
91 |
"""Retrieves the membership list for the specified status. |
1133 | 92 |
""" |
93 |
||
94 |
if status == 'user': |
|
95 |
return ['user'] |
|
96 |
||
97 |
if status == 'public': |
|
98 |
return ['anyone'] |
|
99 |
||
100 |
return self.rights[status] |
|
1299
e209bda5addb
Add a getMemberships method to logic/rights.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1143
diff
changeset
|
101 |
|
e209bda5addb
Add a getMemberships method to logic/rights.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1143
diff
changeset
|
102 |
def getMemberships(self): |
e209bda5addb
Add a getMemberships method to logic/rights.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1143
diff
changeset
|
103 |
"""Returns all memberships for the configured prefix. |
e209bda5addb
Add a getMemberships method to logic/rights.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1143
diff
changeset
|
104 |
""" |
e209bda5addb
Add a getMemberships method to logic/rights.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1143
diff
changeset
|
105 |
|
1318
3f41f33a4ad2
Add custom access check for document listing
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1314
diff
changeset
|
106 |
extra_rights = { |
3f41f33a4ad2
Add custom access check for document listing
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1314
diff
changeset
|
107 |
'user': ['user'], |
3f41f33a4ad2
Add custom access check for document listing
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1314
diff
changeset
|
108 |
'public': ['anyone'], |
3f41f33a4ad2
Add custom access check for document listing
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1314
diff
changeset
|
109 |
'list': [], |
3f41f33a4ad2
Add custom access check for document listing
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1314
diff
changeset
|
110 |
} |
3f41f33a4ad2
Add custom access check for document listing
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1314
diff
changeset
|
111 |
|
3f41f33a4ad2
Add custom access check for document listing
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1314
diff
changeset
|
112 |
return dicts.merge(extra_rights, self.rights) |