Changed checkIsClubAppAccepted into a more generic checkIsApplicationAccepted.
authorLennard de Rijk <ljvderijk@gmail.com>
Wed, 21 Jan 2009 19:45:13 +0000
changeset 884 ded4850776c8
parent 883 1e0af43577ee
child 885 f46b689e19eb
Changed checkIsClubAppAccepted into a more generic checkIsApplicationAccepted. Also fixed a minor bug in club_app view. Patch by: Lennard de Rijk
app/soc/views/helper/access.py
app/soc/views/models/club.py
app/soc/views/models/club_app.py
--- a/app/soc/views/helper/access.py	Wed Jan 21 19:40:39 2009 +0000
+++ b/app/soc/views/helper/access.py	Wed Jan 21 19:45:13 2009 +0000
@@ -40,7 +40,6 @@
 from soc.logic import dicts
 from soc.logic.models import host as host_logic
 from soc.logic.models import notification as notification_logic
-from soc.logic.models import club_app  as club_app_logic
 from soc.logic.models import user as user_logic
 from soc.logic.models import request as request_logic
 from soc.views import helper
@@ -356,7 +355,7 @@
   raise out_of_band.LoginRequest(message_fmt=login_message_fmt)
 
 
-def checkIsClubAppAccepted(request, args, kwargs):
+def checkIsApplicationAccepted(app_logic):
   """Returns an alternate HTTP response if Google Account has no Club App
      entity for the specified Club.
 
@@ -372,31 +371,34 @@
     should be returned by the calling view.
   """
 
-  try:
-    # if the current user is a developer we allow access
-    checkIsDeveloper(request, args, kwargs)
-    return
-  except out_of_band.Error:
-    pass
+  def wrapper(request, args, kwargs):
+    try:
+      # if the current user is a developer we allow access
+      checkIsDeveloper(request, args, kwargs)
+      return
+    except out_of_band.Error:
+      pass
 
-  checkIsUser(request, args, kwargs)
+    checkIsUser(request, args, kwargs)
 
-  user = user_logic.logic.getForCurrentAccount()
+    user = user_logic.logic.getForCurrentAccount()
 
-  properties = {
-      'applicant': user,
-      'reviewed': True,
-      'accepted': True,
-      'application_completed': False,
-      }
+    properties = {
+        'applicant': user,
+        'reviewed': True,
+        'accepted': True,
+        'application_completed': False,
+        }
 
-  club_app = club_app_logic.logic.getForFields(properties, unique=True)
+    application = app_logic.logic.getForFields(properties, unique=True)
+
+    if application:
+      return
 
-  if club_app:
-    return
+    # TODO(srabbelier) Make this give a proper error message
+    deny(request, args, kwargs)
 
-  # TODO(srabbelier) Make this give a proper error message
-  deny(request, args, kwargs)
+  return wrapper
 
 
 def checkIsMyNotification(request, args, kwargs):
@@ -470,6 +472,10 @@
     properties = dicts.filter(kwargs, ['link_id'])
 
     application = app_logic.logic.getForFields(properties, unique=True)
+    
+    if not application:
+      deny(request, args, kwargs)
+    
     user = user_logic.logic.getForCurrentAccount()
 
     # We need to check to see if the key's are equal since the User
--- a/app/soc/views/models/club.py	Wed Jan 21 19:40:39 2009 +0000
+++ b/app/soc/views/models/club.py	Wed Jan 21 19:45:13 2009 +0000
@@ -61,7 +61,7 @@
     rights['edit'] = [access.checkIsClubAdminForClub]
     rights['delete'] = [access.checkIsHost]
     rights['list'] = [access.checkIsHost]
-    rights['applicant'] = [access.checkIsClubAppAccepted]
+    rights['applicant'] = [access.checkIsApplicationAccepted(club_app_logic)]
 
     new_params = {}
     new_params['logic'] = soc.logic.models.club.logic
--- a/app/soc/views/models/club_app.py	Wed Jan 21 19:40:39 2009 +0000
+++ b/app/soc/views/models/club_app.py	Wed Jan 21 19:45:13 2009 +0000
@@ -57,10 +57,10 @@
 
     rights = {}
     rights['create'] = [access.checkIsUser]
-    rights['delete'] = [access.checkIsMyApplication(club_app_logic.logic)]
-    rights['edit'] = [access.checkIsMyApplication(club_app_logic.logic)]
+    rights['delete'] = [access.checkIsMyApplication(club_app_logic)]
+    rights['edit'] = [access.checkIsMyApplication(club_app_logic)]
     rights['list'] = [access.checkIsUser]
-    rights['public'] = [access.checkIsMyApplication(club_app_logic.logic)]
+    rights['public'] = [access.checkIsMyApplication(club_app_logic)]
     rights['review'] = [access.checkIsDeveloper]
 
     new_params = {}