Fixed issue 205.
authorLennard de Rijk <ljvderijk@gmail.com>
Sat, 28 Feb 2009 13:06:04 +0000
changeset 1559 283046e54c01
parent 1558 5ff25327371e
child 1560 656aace0b15f
Fixed issue 205. Registered students can't apply to become an organization. If for some reason the org sign up period and student sign up period are run in parallel and a student has applied to become an org, the application will still go through the normal system. Although the student won't be able to become an org admin until he has been invalidated as a student. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed
app/soc/views/helper/access.py
app/soc/views/models/org_app.py
--- a/app/soc/views/helper/access.py	Sat Feb 28 12:59:34 2009 +0000
+++ b/app/soc/views/helper/access.py	Sat Feb 28 13:06:04 2009 +0000
@@ -1064,6 +1064,39 @@
     # no roles found, access granted
     return
 
+  def checkIsNotStudentForProgramInScope(self, django_args):
+    """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
+
+     Raises:
+       AccessViolationResponse: if the current user has a student
+                                role for the given program.
+    """
+
+    if django_args.get('seed'):
+      key_name = django_args['seed']['scope_path']
+    else:
+      key_name = django_args['scope_path']
+
+    program_entity = program_logic.getFromKeyName(key_name)
+    user_entity = user_logic.getForCurrentAccount()
+
+    filter = {'user': user_entity,
+              'scope': program_entity,
+              'status': 'active'}
+
+    # check if the current user is already a student for this program
+    student_role = student_logic.getForFields(filter, unique=True)
+
+    if student_role:
+      raise out_of_band.AccessViolation(
+          message_fmt=DEF_ALREADY_PARTICIPATING_MSG)
+
+    return
+
   def checkIsNotStudentForProgramOfOrg(self, django_args):
     """Checks if the current user has no active Student role for the program
        that the organization in the scope_path is participating in.
--- a/app/soc/views/models/org_app.py	Sat Feb 28 12:59:34 2009 +0000
+++ b/app/soc/views/models/org_app.py	Sat Feb 28 13:06:04 2009 +0000
@@ -75,7 +75,8 @@
     rights['bulk_accept'] = ['checkIsHostForProgramInScope']
     rights['bulk_reject'] = ['checkIsHostForProgramInScope']
     rights['apply'] = ['checkIsUser',
-                             ('checkCanCreateOrgApp', ['org_signup'])]
+                             ('checkCanCreateOrgApp', ['org_signup']),
+                       'checkIsNotStudentForProgramInScope']
 
     new_params = {}