author | Sverre Rabbelier <srabbelier@gmail.com> |
Fri, 13 Feb 2009 21:54:10 +0000 | |
changeset 1305 | 9567bb475d6d |
parent 1299 | e209bda5addb |
child 1307 | 091a21cf3627 |
permissions | -rw-r--r-- |
1133 | 1 |
#!/usr/bin/python2.5 |
2 |
# |
|
3 |
# Copyright 2008 the Melange authors. |
|
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 |
|
1133 | 27 |
class Checker(object): |
1136
aaf75aa8eca5
Added two forgotten comments in rights.Checker
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1133
diff
changeset
|
28 |
"""Checker class that maps from prefix and status to membership. |
1133 | 29 |
""" |
30 |
||
31 |
SITE_MEMBERSHIP = { |
|
32 |
'admin': [], |
|
33 |
'restricted': ['host'], |
|
34 |
'member': ['user'], |
|
35 |
} |
|
36 |
||
37 |
CLUB_MEMBERSHIP = { |
|
38 |
'admin': ['host', 'club_admin'], |
|
39 |
'restricted': ['host', 'club_admin'], |
|
40 |
'member': ['host', 'club_admin', 'club_member'], |
|
41 |
} |
|
42 |
||
43 |
SPONSOR_MEMBERSHIP = { |
|
44 |
'admin': ['host'], |
|
45 |
'restricted': ['host'], |
|
46 |
'member': ['host'], |
|
47 |
} |
|
48 |
||
49 |
PROGRAM_MEMBERSHIP = { |
|
50 |
'admin': ['host'], |
|
51 |
'restricted': ['host', 'org_admin'], |
|
52 |
'member': ['host', 'org_admin', 'org_mentor', 'org_student'], |
|
53 |
} |
|
54 |
||
55 |
ORGANIZATION_MEMBERSHIP = { |
|
56 |
'admin': ['host', 'org_admin'], |
|
57 |
'restricted': ['host', 'org_admin', 'org_mentor'], |
|
58 |
'member': ['host', 'org_admin', 'org_mentor', 'org_student'], |
|
59 |
} |
|
60 |
||
61 |
USER_MEMBERSHIP = { |
|
62 |
'admin': ['user_self'], |
|
63 |
'restricted': ['user_self'], # ,'friends' |
|
64 |
'member': ['user'], |
|
65 |
} |
|
66 |
||
67 |
RIGHTS = { |
|
68 |
'site': SITE_MEMBERSHIP, |
|
69 |
'club': CLUB_MEMBERSHIP, |
|
70 |
'sponsor': SPONSOR_MEMBERSHIP, |
|
71 |
'program': PROGRAM_MEMBERSHIP, |
|
72 |
'organization': ORGANIZATION_MEMBERSHIP, |
|
73 |
'user': USER_MEMBERSHIP, |
|
74 |
} |
|
75 |
||
76 |
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
|
77 |
"""Constructs a Checker for the specified prefix. |
1133 | 78 |
""" |
79 |
||
80 |
self.prefix = prefix |
|
81 |
self.rights = self.RIGHTS[prefix] |
|
82 |
||
83 |
def getMembership(self, status): |
|
1136
aaf75aa8eca5
Added two forgotten comments in rights.Checker
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1133
diff
changeset
|
84 |
"""Retrieves the membership list for the specified status. |
1133 | 85 |
""" |
86 |
||
87 |
if status == 'user': |
|
88 |
return ['user'] |
|
89 |
||
90 |
if status == 'public': |
|
91 |
return ['anyone'] |
|
92 |
||
93 |
return self.rights[status] |
|
1299
e209bda5addb
Add a getMemberships method to logic/rights.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1143
diff
changeset
|
94 |
|
e209bda5addb
Add a getMemberships method to logic/rights.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1143
diff
changeset
|
95 |
def getMemberships(self): |
e209bda5addb
Add a getMemberships method to logic/rights.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1143
diff
changeset
|
96 |
"""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
|
97 |
""" |
e209bda5addb
Add a getMemberships method to logic/rights.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1143
diff
changeset
|
98 |
|
e209bda5addb
Add a getMemberships method to logic/rights.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1143
diff
changeset
|
99 |
return dicts.merge(self.rights, {'user': ['user'], 'public': ['anyone']}) |