Added org taking access to Surveys.
authorLennard de Rijk <ljvderijk@gmail.com>
Mon, 24 Aug 2009 18:43:38 +0200
changeset 2792 14a62fcf4e02
parent 2791 c62f45595b8d
child 2793 8c88226b27e7
Added org taking access to Surveys. This taking access means that everyone with an active role for any organization for a given program can take the Survey. This will allow one Survey to be taken by both Org Admins and Mentors.
app/soc/models/survey.py
app/soc/views/helper/access.py
--- a/app/soc/models/survey.py	Mon Aug 24 20:22:45 2009 +0530
+++ b/app/soc/models/survey.py	Mon Aug 24 18:43:38 2009 +0200
@@ -98,11 +98,8 @@
   SURVEY_ACCESS = ['admin', 'restricted', 'member', 'user']
 
   # these are GSoC specific, so eventually we can subclass this
-  SURVEY_TAKING_ACCESS = ['student',
-                          'mentor',
-                          'org_admin',
-                          'user']
-  
+  SURVEY_TAKING_ACCESS = ['student', 'mentor', 'org_admin', 'org', 'user']
+
   GRADE_OPTIONS = {'midterm':['mid_term_passed', 'mid_term_failed'],
                    'final':['final_passed', 'final_failed'],
                    'N/A':[] }
--- a/app/soc/views/helper/access.py	Mon Aug 24 20:22:45 2009 +0530
+++ b/app/soc/views/helper/access.py	Mon Aug 24 18:43:38 2009 +0200
@@ -1698,12 +1698,27 @@
       return self._checkHasActiveRoleFor(django_args, mentor_logic, 'program')
 
     if role == 'org_admin':
-      # check if the current user is a mentor for the program in survey.scope
+      # check if the current user is an org admin for the program
       django_args['program'] = survey_scope
       # program is the 'program' attribute for mentors and org_admins
       return self._checkHasActiveRoleFor(django_args, org_admin_logic,
                                          'program')
 
+    if role == 'org':
+      # check if the current user is an org admin or mentor for the program
+      django_args['program'] = survey_scope
+
+      try:
+        # program is the 'program' attribute for mentors and org_admins
+        return self._checkHasActiveRoleFor(django_args, org_admin_logic,
+                                          'program')
+      except:
+        # the current user is no org admin
+        pass
+
+      # try to check if the current user is a mentor instead
+      return self._checkHasActiveRoleFor(django_args, mentor_logic, 'program')
+
     if role == 'student':
       # check if the current user is a student for the program in survey.scope
       django_args['scope'] = survey_scope