55 |
55 |
56 DEF_LOGOUT_MSG_FMT = ugettext_lazy( |
56 DEF_LOGOUT_MSG_FMT = ugettext_lazy( |
57 'Please <a href="%(sign_out)s">sign out</a> in order to view this page') |
57 'Please <a href="%(sign_out)s">sign out</a> in order to view this page') |
58 |
58 |
59 |
59 |
|
60 def checkAccess(access_type, request, rights): |
|
61 """Runs all the defined checks for the specified type |
|
62 |
|
63 Args: |
|
64 access_type: the type of request (such as 'list' or 'edit') |
|
65 request: the Django request object |
|
66 rights: A dictionary containing access check functions |
|
67 |
|
68 Rights usage: The rights dictionary is used to check if the |
|
69 current user is allowed to view the page specified. The |
|
70 functions defined in this dictionary are always called with the |
|
71 django request object as argument. |
|
72 On any request, regardless of what type, the functions in the |
|
73 'any_access' value are called. |
|
74 If the specified type is not in the rights dictionary, all the |
|
75 functions in the 'unspecified' value are called. |
|
76 When the specified type _is_ in the rights dictionary, all the |
|
77 functions in that access_type's value are called. |
|
78 |
|
79 Returns: |
|
80 True: If all the required access checks have been made successfully |
|
81 False: If a check failed, in this case self._response will contain |
|
82 the response provided by the failed access check. |
|
83 """ |
|
84 |
|
85 # Call each access checker |
|
86 for check in rights['any_access']: |
|
87 check(request) |
|
88 |
|
89 if access_type not in rights: |
|
90 for check in rights['unspecified']: |
|
91 # No checks defined, so do the 'generic' checks and bail out |
|
92 check(request) |
|
93 return |
|
94 |
|
95 for check in rights[access_type]: |
|
96 check(request) |
|
97 |
|
98 |
60 def allow(request): |
99 def allow(request): |
61 """Never returns an alternate HTTP response |
100 """Never returns an alternate HTTP response |
62 |
101 |
63 Args: |
102 Args: |
64 request: a Django HTTP request |
103 request: a Django HTTP request |