Add scope view for GradingSurveyGroup and set access checks.
authorLennard de Rijk <ljvderijk@gmail.com>
Sun, 12 Jul 2009 14:03:35 +0200
changeset 2610 95949d4c45d9
parent 2609 dc0d4c3d9d2e
child 2611 0fe19187a3bb
Add scope view for GradingSurveyGroup and set access checks. The access checks are now properly set for create, edit and show. To facilitate the scope view the access check have an extra check built in to ensure that a scope is actually present before cheking for an existing Program.
app/soc/views/helper/access.py
app/soc/views/models/grading_survey_group.py
--- a/app/soc/views/helper/access.py	Sun Jul 12 13:55:21 2009 +0200
+++ b/app/soc/views/helper/access.py	Sun Jul 12 14:03:35 2009 +0200
@@ -939,7 +939,7 @@
   @denySidebar
   def checkIsHostForProgram(self, django_args):
     """Checks if the user is a host for the specified program.
-    
+
     Args:
       django_args: a dictionary with django's arguments
     """
@@ -956,12 +956,17 @@
   @denySidebar
   def checkIsHostForProgramInScope(self, django_args):
     """Checks if the user is a host for the specified program.
-    
+
     Args:
       django_args: a dictionary with django's arguments
     """
 
-    program = program_logic.getFromKeyName(django_args['scope_path'])
+    scope_path = django_args.get('scope_path')
+
+    if not scope_path:
+      raise out_of_band.AccessViolation(message_fmt=DEF_PAGE_DENIED_MSG)
+
+    program = program_logic.getFromKeyName(scope_path)
 
     if not program or program.status == 'invalid':
       raise out_of_band.AccessViolation(message_fmt=DEF_NO_ACTIVE_PROGRAM_MSG)
--- a/app/soc/views/models/grading_survey_group.py	Sun Jul 12 13:55:21 2009 +0200
+++ b/app/soc/views/models/grading_survey_group.py	Sun Jul 12 14:03:35 2009 +0200
@@ -42,6 +42,7 @@
 from soc.views.helper import decorators
 from soc.views.helper import redirects
 from soc.views.models import base
+from soc.views.models import program as program_view
 
 
 class View(base.View):
@@ -57,10 +58,10 @@
     """
 
     rights = access.Checker(params)
-    rights['create'] = ['checkIsDeveloper']
-    rights['edit'] = ['checkIsDeveloper']
+    rights['create'] = ['checkIsHostForProgramInScope']
+    rights['edit'] = ['checkIsHostForProgramInScope']
     rights['delete'] = ['checkIsDeveloper']
-    rights['show'] = ['checkIsDeveloper']
+    rights['show'] = ['checkIsHostForProgramInScope']
     rights['list'] = ['checkIsDeveloper']
 
     new_params = {}
@@ -69,8 +70,10 @@
     new_params['name'] = "Grading Survey Group"
     new_params['sidebar_grouping'] = "Surveys"
 
+    new_params['scope_view'] = program_view
+    new_params['scope_redirect'] = redirects.getCreateRedirect
+
     new_params['no_admin'] = True
-    new_params['no_create_raw'] = True
     new_params['no_create_with_key_fields'] = True
 
     new_params['create_extra_dynaproperties'] = {
@@ -101,7 +104,8 @@
     For params see base.View.create().
     """
 
-    self.setQueries(kwargs['scope_path'], params['create_form'])
+    if kwargs.get('scope_path'):
+      self.setQueries(kwargs['scope_path'], params['create_form'])
 
     return super(View, self).create(request, access_type, page_name=page_name,
                                     params=params, **kwargs)