app/soc/views/helper/access.py
changeset 979 789e70941055
parent 974 2f86cbc90b65
child 992 e9f7d8e96b20
equal deleted inserted replaced
978:e05b09b53486 979:789e70941055
    40 from soc.logic import dicts
    40 from soc.logic import dicts
    41 from soc.logic.models.club_admin import logic as club_admin_logic
    41 from soc.logic.models.club_admin import logic as club_admin_logic
    42 from soc.logic.models.host import logic as host_logic
    42 from soc.logic.models.host import logic as host_logic
    43 from soc.logic.models.notification import logic as notification_logic
    43 from soc.logic.models.notification import logic as notification_logic
    44 from soc.logic.models.request import logic as request_logic
    44 from soc.logic.models.request import logic as request_logic
       
    45 from soc.logic.models.role import logic as role_logic
    45 from soc.logic.models.site import logic as site_logic
    46 from soc.logic.models.site import logic as site_logic
    46 from soc.logic.models.user import logic as user_logic
    47 from soc.logic.models.user import logic as user_logic
    47 from soc.views import helper
    48 from soc.views import helper
    48 from soc.views import out_of_band
    49 from soc.views import out_of_band
    49 from soc.views.helper import redirects
    50 from soc.views.helper import redirects
    66 DEF_PAGE_DENIED_MSG = ugettext(
    67 DEF_PAGE_DENIED_MSG = ugettext(
    67   'Access to this page has been restricted')
    68   'Access to this page has been restricted')
    68 
    69 
    69 DEF_LOGOUT_MSG_FMT = ugettext(
    70 DEF_LOGOUT_MSG_FMT = ugettext(
    70     'Please <a href="%(sign_out)s">sign out</a> in order to view this page')
    71     'Please <a href="%(sign_out)s">sign out</a> in order to view this page')
       
    72 
       
    73 DEF_GROUP_NOT_FOUND_MSG = ugettext(
       
    74     'The requested Group can not be found')
    71 
    75 
    72 
    76 
    73 def checkAccess(access_type, rights, kwargs=None):
    77 def checkAccess(access_type, rights, kwargs=None):
    74   """Runs all the defined checks for the specified type.
    78   """Runs all the defined checks for the specified type.
    75 
    79 
   235 
   239 
   236   login_message_fmt = DEF_DEV_LOGOUT_LOGIN_MSG_FMT % {
   240   login_message_fmt = DEF_DEV_LOGOUT_LOGIN_MSG_FMT % {
   237       'role': 'a Site Developer '}
   241       'role': 'a Site Developer '}
   238 
   242 
   239   raise out_of_band.LoginRequest(message_fmt=login_message_fmt)
   243   raise out_of_band.LoginRequest(message_fmt=login_message_fmt)
       
   244 
       
   245 
       
   246 def checkCanMakeRequestToGroup(group_logic):
       
   247   """Raises an alternate HTTP response if the specified group is not in an
       
   248   active state.
       
   249   
       
   250   Note that state hasn't been implemented yet
       
   251   
       
   252   Args:
       
   253     group_logic: Logic module for the type of group which the request is for
       
   254   """
       
   255 
       
   256   def wrapper(kwargs):
       
   257     group_entity = role_logic.getGroupEntityFromScopePath(
       
   258         group_logic.logic, kwargs['scope_path'])
       
   259 
       
   260     if not group_entity:
       
   261       raise out_of_band.Error(DEF_GROUP_NOT_FOUND_MSG, status=404)
       
   262 
       
   263     # TODO(ljvderijk) check if the group is active
       
   264     return
       
   265   return wrapper
   240 
   266 
   241 
   267 
   242 def checkCanCreateFromRequest(role_name):
   268 def checkCanCreateFromRequest(role_name):
   243   """Raises an alternate HTTP response if the specified request does not exist
   269   """Raises an alternate HTTP response if the specified request does not exist
   244      or if it's state is not group_accepted. 
   270      or if it's state is not group_accepted.