author | Sverre Rabbelier <srabbelier@gmail.com> |
Sat, 24 Oct 2009 16:23:31 -0700 | |
changeset 3043 | 187c1709756b |
parent 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 |
||
2956
50ce8ac13932
Use the new rights code in core
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1528
diff
changeset
|
32 |
def __init__(self, rights, prefix): |
1143
b07b7d5b3e27
Fix missing dots and blank lines to soc.logic modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
1136
diff
changeset
|
33 |
"""Constructs a Checker for the specified prefix. |
1133 | 34 |
""" |
35 |
||
2956
50ce8ac13932
Use the new rights code in core
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1528
diff
changeset
|
36 |
self.rights = rights[prefix] |
1133 | 37 |
self.prefix = prefix |
38 |
||
39 |
def getMembership(self, status): |
|
1136
aaf75aa8eca5
Added two forgotten comments in rights.Checker
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1133
diff
changeset
|
40 |
"""Retrieves the membership list for the specified status. |
1133 | 41 |
""" |
42 |
||
43 |
if status == 'user': |
|
44 |
return ['user'] |
|
45 |
||
46 |
if status == 'public': |
|
47 |
return ['anyone'] |
|
48 |
||
49 |
return self.rights[status] |
|
1299
e209bda5addb
Add a getMemberships method to logic/rights.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1143
diff
changeset
|
50 |
|
e209bda5addb
Add a getMemberships method to logic/rights.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1143
diff
changeset
|
51 |
def getMemberships(self): |
e209bda5addb
Add a getMemberships method to logic/rights.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1143
diff
changeset
|
52 |
"""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
|
53 |
""" |
e209bda5addb
Add a getMemberships method to logic/rights.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1143
diff
changeset
|
54 |
|
1318
3f41f33a4ad2
Add custom access check for document listing
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1314
diff
changeset
|
55 |
extra_rights = { |
3f41f33a4ad2
Add custom access check for document listing
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1314
diff
changeset
|
56 |
'user': ['user'], |
3f41f33a4ad2
Add custom access check for document listing
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1314
diff
changeset
|
57 |
'public': ['anyone'], |
3f41f33a4ad2
Add custom access check for document listing
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1314
diff
changeset
|
58 |
'list': [], |
3f41f33a4ad2
Add custom access check for document listing
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1314
diff
changeset
|
59 |
} |
3f41f33a4ad2
Add custom access check for document listing
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1314
diff
changeset
|
60 |
|
3f41f33a4ad2
Add custom access check for document listing
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1314
diff
changeset
|
61 |
return dicts.merge(extra_rights, self.rights) |