96 raise out_of_band.Error("Sidebar Calling") |
96 raise out_of_band.Error("Sidebar Calling") |
97 return fun(self, django_args, *args, **kwargs) |
97 return fun(self, django_args, *args, **kwargs) |
98 return wrapper |
98 return wrapper |
99 |
99 |
100 |
100 |
101 def allowDeveloper(fun): |
101 def allowIfCheckPasses(checker_name): |
102 """Decorator that allows access if the current user is a Developer. |
102 """Returns a decorator that allows access if the specified checker passes. |
103 """ |
103 """ |
104 |
104 |
105 from functools import wraps |
105 from functools import wraps |
106 |
106 |
107 @wraps(fun) |
107 def decorator(fun): |
108 def wrapper(self, django_args, *args, **kwargs): |
108 """Decorator that allows access if the current user is a Developer. |
109 try: |
109 """ |
110 # if the current user is a developer we allow access |
110 |
111 return self.checkIsDeveloper(django_args) |
111 @wraps(fun) |
112 except out_of_band.Error: |
112 def wrapper(self, django_args, *args, **kwargs): |
113 return fun(self, django_args, *args, **kwargs) |
113 try: |
114 return wrapper |
114 # if the check passes we allow access regardless |
|
115 return self.doCheck(checker_name, django_args, []) |
|
116 except out_of_band.Error: |
|
117 # otherwise we run the original check |
|
118 return fun(self, django_args, *args, **kwargs) |
|
119 return wrapper |
|
120 |
|
121 return decorator |
|
122 |
|
123 |
|
124 allowDeveloper = allowIfCheckPasses('checkIsDeveloper') |
115 |
125 |
116 |
126 |
117 class Checker(object): |
127 class Checker(object): |
118 """ |
128 """ |
119 The __setitem__() and __getitem__() methods are overloaded to DTRT |
129 The __setitem__() and __getitem__() methods are overloaded to DTRT |