program_logic is passed as a parameter to three checkers than hard coding it.
authorMadhusudan.C.S <madhusudancs@gmail.com>
Sat, 22 Aug 2009 03:44:13 +0530
changeset 2781 8f6c0a5a7491
parent 2780 0362fb7e3b3c
child 2782 3944749338d3
program_logic is passed as a parameter to three checkers than hard coding it. program_logic is added as a parameter to checkIsActivePeriod checkCanCreateOrgApp checkIsNotParticipatingInProgramInScope access check methods and the corresponding arguments are added in all the places they are used.
app/soc/views/helper/access.py
app/soc/views/models/org_app.py
app/soc/views/models/student.py
--- a/app/soc/views/helper/access.py	Mon Aug 17 18:47:48 2009 +0200
+++ b/app/soc/views/helper/access.py	Sat Aug 22 03:44:13 2009 +0530
@@ -982,7 +982,8 @@
 
   @allowDeveloper
   @denySidebar
-  def checkIsActivePeriod(self, django_args, period_name, key_name_arg):
+  def checkIsActivePeriod(self, django_args, period_name, 
+                          key_name_arg, program_logic):
     """Checks if the given period is active for the given program.
 
     Args:
@@ -991,6 +992,7 @@
       key_name_arg: the entry in django_args that specifies the given program
         keyname. If none is given the key_name is constructed from django_args
         itself.
+      program_logic: Program Logic instance
 
     Raises:
       AccessViolationResponse:
@@ -1050,17 +1052,18 @@
 
     raise out_of_band.AccessViolation(message_fmt=DEF_PAGE_INACTIVE_MSG)
 
-  def checkCanCreateOrgApp(self, django_args, period_name):
+  def checkCanCreateOrgApp(self, django_args, period_name, program_logic):
     """Checks to see if the program in the scope_path is accepting org apps
     
     Args:
       django_args: a dictionary with django's arguments
       period_name: the name of the period which is checked
+      program_logic: Program Logic instance
     """
 
     if 'seed' in django_args:
       return self.checkIsActivePeriod(django_args['seed'],
-          period_name, 'scope_path')
+          period_name, 'scope_path', program_logic)
     else:
       return
 
@@ -1161,12 +1164,13 @@
 
     raise out_of_band.AccessViolation(message_fmt=DEF_NO_APPLICATION_MSG)
 
-  def checkIsNotParticipatingInProgramInScope(self, django_args):
+  def checkIsNotParticipatingInProgramInScope(self, django_args, program_logic):
     """Checks if the current user has no roles for the given 
        program in django_args.
 
     Args:
       django_args: a dictionary with django's arguments
+      program_logic: Program Logic instance
 
      Raises:
        AccessViolationResponse: if the current user has a student, mentor or
@@ -1213,12 +1217,13 @@
     # no roles found, access granted
     return
 
-  def checkIsNotStudentForProgramInScope(self, django_args):
+  def checkIsNotStudentForProgramInScope(self, django_args, program_logic):
     """Checks if the current user is not a student for the given
        program in django_args.
 
     Args:
       django_args: a dictionary with django's arguments
+      program_logic: Program Logic instance
 
      Raises:
        AccessViolationResponse: if the current user has a student
--- a/app/soc/views/models/org_app.py	Mon Aug 17 18:47:48 2009 +0200
+++ b/app/soc/views/models/org_app.py	Sat Aug 22 03:44:13 2009 +0530
@@ -60,10 +60,12 @@
     rights['create'] = ['checkIsDeveloper']
     rights['delete'] = [('checkCanEditGroupApp',
                        [org_app_logic.logic]),
-                       ('checkIsActivePeriod', ['org_signup', 'scope_path'])]
+                       ('checkIsActivePeriod',
+                        ['org_signup', 'scope_path', program_logic.logic])]
     rights['edit'] = [('checkCanEditGroupApp',
                        [org_app_logic.logic]),
-                       ('checkIsActivePeriod', ['org_signup', 'scope_path'])]
+                       ('checkIsActivePeriod', 
+                        ['org_signup', 'scope_path', program_logic.logic])]
     rights['list'] = ['checkIsDeveloper']
     rights['list_self'] = ['checkIsUser']
     rights['show'] = ['allow']
@@ -73,7 +75,8 @@
     rights['bulk_accept'] = ['checkIsHostForProgramInScope']
     rights['bulk_reject'] = ['checkIsHostForProgramInScope']
     rights['apply'] = ['checkIsUser',
-                             ('checkCanCreateOrgApp', ['org_signup']),
+                             ('checkCanCreateOrgApp', 
+                              ['org_signup', program_logic.logic]),
                        'checkIsNotStudentForProgramInScope']
 
     new_params = {}
--- a/app/soc/views/models/student.py	Mon Aug 17 18:47:48 2009 +0200
+++ b/app/soc/views/models/student.py	Sat Aug 22 03:44:13 2009 +0530
@@ -65,8 +65,9 @@
     rights['delete'] = ['checkIsDeveloper']
     rights['apply'] = [
         'checkIsUser',
-        ('checkIsActivePeriod', ['student_signup', 'scope_path']),
-        'checkIsNotParticipatingInProgramInScope',
+        ('checkIsActivePeriod', 
+         ['student_signup', 'scope_path', program_logic.logic]),
+        ('checkIsNotParticipatingInProgramInScope', [program_logic.logic]),
         ]
     rights['manage'] = [('checkHasActiveRoleForScope', student_logic.logic),
         ('checkIsMyEntity', [student_logic.logic, 'user', True])]