# HG changeset patch # User Lennard de Rijk # Date 1232886173 0 # Node ID 789e709410550bbb16954b0148c709356a69581c # Parent e05b09b53486491e99c3e04a767c74fb591ff1c3 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 diff -r e05b09b53486 -r 789e70941055 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 sign out 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.