app/soc/views/helper/access.py
changeset 979 789e70941055
parent 974 2f86cbc90b65
child 992 e9f7d8e96b20
--- 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.