--- a/app/soc/views/helper/access.py Tue Jan 27 21:56:32 2009 +0000
+++ b/app/soc/views/helper/access.py Tue Jan 27 22:57:19 2009 +0000
@@ -88,6 +88,22 @@
return wrapper
+def allowDeveloper(fun):
+ """Decorator that allows access if the current user is a Developer.
+ """
+
+ from functools import wraps
+
+ @wraps(fun)
+ def wrapper(self, django_args, *args, **kwargs):
+ try:
+ # if the current user is a developer we allow access
+ return self.checkIsDeveloper(django_args)
+ except out_of_band.Error:
+ return fun(self, django_args, *args, **kwargs)
+ return wrapper
+
+
class Checker(object):
"""
The __setitem__() and __getitem__() methods are overloaded to DTRT
@@ -364,6 +380,7 @@
return
@denySidebar
+ @allowDeveloper
def checkIsHost(self, django_args):
"""Raises an alternate HTTP response if Google Account has no Host entity.
@@ -378,13 +395,6 @@
* if the user is not even logged in
"""
- try:
- # if the current user is a developer we allow access
- self.checkIsDeveloper(django_args)
- return
- except out_of_band.Error:
- pass
-
self.checkIsUser(django_args)
user = user_logic.getForCurrentAccount()
@@ -455,6 +465,7 @@
raise out_of_band.LoginRequest(message_fmt=login_message_fmt)
+ @allowDeveloper
def checkIsClubAdminForClub(self, django_args):
"""Returns an alternate HTTP response if Google Account has no Club Admin
entity for the specified club.
@@ -471,13 +482,6 @@
should be returned by the calling view.
"""
- try:
- # if the current user is invited to create a host profile we allow access
- checkIsDeveloper(django_args)
- return
- except out_of_band.Error:
- pass
-
self.checkIsUser(django_args)
user = user_logic.getForCurrentAccount()
@@ -501,6 +505,7 @@
raise out_of_band.LoginRequest(message_fmt=login_message_fmt)
+ @allowDeveloper
def checkIsApplicationAccepted(self, django_args, app_logic):
"""Returns an alternate HTTP response if Google Account has no Club App
entity for the specified Club.
@@ -517,13 +522,6 @@
should be returned by the calling view.
"""
- try:
- # if the current user is a developer we allow access
- checkIsDeveloper(django_args)
- return
- except out_of_band.Error:
- pass
-
self.checkIsUser(django_args)
user = user_logic.getForCurrentAccount()
@@ -541,6 +539,7 @@
# TODO(srabbelier) Make this give a proper error message
deny(django_args)
+ @allowDeveloper
def checkIsMyNotification(self, django_args):
"""Returns an alternate HTTP response if this request is for
a Notification belonging to the current user.
@@ -555,13 +554,6 @@
None if the current User is allowed to access this Notification.
"""
- try:
- # if the current user is a developer we allow access
- checkIsDeveloper(django_args)
- return
- except out_of_band.Error:
- pass
-
self.checkIsUser(django_args)
properties = dicts.filter(django_args, ['link_id', 'scope_path'])
@@ -578,6 +570,7 @@
# TODO(ljvderijk) Make this give a proper error message
deny(django_args)
+ @allowDeveloper
def checkIsMyApplication(self, django_args, app_logic):
"""Returns an alternate HTTP response if this request is for
a Application belonging to the current user.
@@ -592,13 +585,6 @@
None if the current User is allowed to access this Application.
"""
- try:
- # if the current user is a developer we allow access
- self.checkIsDeveloper(django_args)
- return
- except out_of_band.Error:
- pass
-
self.checkIsUser(django_args)
properties = dicts.filter(django_args, ['link_id'])
@@ -619,6 +605,7 @@
# TODO(srabbelier) Make this give a proper error message
deny(django_args)
+ @allowDeveloper
def checkIsMyActiveRole(self, django_args, role_logic):
"""Returns an alternate HTTP response if there is no active role found for
the current user using the given role_logic.
@@ -630,13 +617,6 @@
None if the current User has no active role for the given role_logic.
"""
- try:
- # if the current user is a developer we allow access
- checkIsDeveloper(django_args)
- return
- except out_of_band.Error:
- pass
-
user = user_logic.getForCurrentAccount()
if not user or user.link_id != django_args['link_id']: