Added checkCanMakeRequestToGroup to access.py.
authorLennard de Rijk <ljvderijk@gmail.com>
Sun, 25 Jan 2009 12:22:53 +0000
changeset 979 789e70941055
parent 978 e05b09b53486
child 980 3f3f7ec251bf
Added checkCanMakeRequestToGroup to access.py. Note that states for a group have not been implemented yet, so a TODO has been added for this check. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed
app/soc/views/helper/access.py
--- a/app/soc/views/helper/access.py	Sun Jan 25 12:20:35 2009 +0000
+++ b/app/soc/views/helper/access.py	Sun Jan 25 12:22:53 2009 +0000
@@ -42,6 +42,7 @@
 from soc.logic.models.host import logic as host_logic
 from soc.logic.models.notification import logic as notification_logic
 from soc.logic.models.request import logic as request_logic
+from soc.logic.models.role import logic as role_logic
 from soc.logic.models.site import logic as site_logic
 from soc.logic.models.user import logic as user_logic
 from soc.views import helper
@@ -69,6 +70,9 @@
 DEF_LOGOUT_MSG_FMT = ugettext(
     'Please <a href="%(sign_out)s">sign out</a> in order to view this page')
 
+DEF_GROUP_NOT_FOUND_MSG = ugettext(
+    'The requested Group can not be found')
+
 
 def checkAccess(access_type, rights, kwargs=None):
   """Runs all the defined checks for the specified type.
@@ -239,6 +243,28 @@
   raise out_of_band.LoginRequest(message_fmt=login_message_fmt)
 
 
+def checkCanMakeRequestToGroup(group_logic):
+  """Raises an alternate HTTP response if the specified group is not in an
+  active state.
+  
+  Note that state hasn't been implemented yet
+  
+  Args:
+    group_logic: Logic module for the type of group which the request is for
+  """
+
+  def wrapper(kwargs):
+    group_entity = role_logic.getGroupEntityFromScopePath(
+        group_logic.logic, kwargs['scope_path'])
+
+    if not group_entity:
+      raise out_of_band.Error(DEF_GROUP_NOT_FOUND_MSG, status=404)
+
+    # TODO(ljvderijk) check if the group is active
+    return
+  return wrapper
+
+
 def checkCanCreateFromRequest(role_name):
   """Raises an alternate HTTP response if the specified request does not exist
      or if it's state is not group_accepted.