Added rights check to sponsor.py.
authorLennard de Rijk <ljvderijk@gmail.com>
Sun, 25 Jan 2009 22:30:42 +0000
changeset 995 886c981fda2c
parent 994 f05c02ba40fc
child 996 a6f67d4c297f
Added rights check to sponsor.py. In the process of doing so also fixed checkIsHostForProgram method in access.py. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed
app/soc/views/helper/access.py
app/soc/views/models/sponsor.py
--- a/app/soc/views/helper/access.py	Sun Jan 25 22:15:13 2009 +0000
+++ b/app/soc/views/helper/access.py	Sun Jan 25 22:30:42 2009 +0000
@@ -385,7 +385,7 @@
 
 def checkIsHostForProgram(kwargs):
   """Raises an alternate HTTP response if Google Account has no Host entity
-     for the specified program.
+     for the specified Sponsor.
 
   Args:
     request: a Django HTTP request
@@ -402,8 +402,13 @@
 
   user = user_logic.getForCurrentAccount()
 
+  if kwargs.get('scope_path'):
+    scope_path = kwargs['scope_path']
+  else:
+    scope_path = kwargs['link_id']
+
   fields = {'user': user,
-            'scope_path': kwargs['scope_path'],
+            'scope_path': scope_path,
             'state': 'active'}
 
   host = host_logic.getForFields(fields, unique=True)
--- a/app/soc/views/models/sponsor.py	Sun Jan 25 22:15:13 2009 +0000
+++ b/app/soc/views/models/sponsor.py	Sun Jan 25 22:30:42 2009 +0000
@@ -25,6 +25,7 @@
 
 
 from soc.logic import dicts
+from soc.views.helper import access
 from soc.views.models import group
 
 import soc.models.sponsor
@@ -45,10 +46,16 @@
       params: a dict with params for this View
     """    
 
+    rights = {}
+    rights['create'] = [access.checkIsDeveloper]
+    rights['edit'] = [access.checkIsHostForProgram]
+    rights['delete'] = [access.checkIsDeveloper]
+    rights['list'] = [access.checkIsDeveloper]
+    rights['list_requests'] = [access.checkIsHostForProgram]
+
     new_params = {}
     new_params['logic'] = soc.logic.models.sponsor.logic
-
-    # TODO(ljvderijk) Set rights for the different views including list_requests
+    new_params['rights'] = rights
 
     new_params['name'] = "Program Owner"
     new_params['module_name'] = "sponsor"