app/soc/views/helper/access.py
changeset 1201 0a4c1af700a0
parent 1200 e68fd70ba076
child 1203 38225f2ad3a6
equal deleted inserted replaced
1200:e68fd70ba076 1201:0a4c1af700a0
    90   'There is no accepted request that would allow you to visit this page.')
    90   'There is no accepted request that would allow you to visit this page.')
    91 
    91 
    92 DEF_NEED_PICK_ARGS_MSG = ugettext(
    92 DEF_NEED_PICK_ARGS_MSG = ugettext(
    93   'The "continue" and "field" args are not both present.')
    93   'The "continue" and "field" args are not both present.')
    94 
    94 
       
    95 DEF_REVIEW_COMPLETED_MSG = ugettext(
       
    96     'This Application can not be reviewed anymore (it has been completed or rejected)')
       
    97 
    95 DEF_REQUEST_COMPLETED_MSG = ugettext(
    98 DEF_REQUEST_COMPLETED_MSG = ugettext(
    96   'This request cannot be accepted (it is either completed or denied).')
    99   'This request cannot be accepted (it is either completed or denied).')
    97 
   100 
    98 DEF_SCOPE_INACTIVE_MSG = ugettext(
   101 DEF_SCOPE_INACTIVE_MSG = ugettext(
    99   'The scope for this request is not active.')
   102   'The scope for this request is not active.')
   114     ' <li>the account is invalid</li>'
   117     ' <li>the account is invalid</li>'
   115     ' <li>the account is already attached to a User profile and cannot be'
   118     ' <li>the account is already attached to a User profile and cannot be'
   116     ' used to create another one</li>'
   119     ' used to create another one</li>'
   117     ' <li>the account is a former account that cannot be used again</li>'
   120     ' <li>the account is a former account that cannot be used again</li>'
   118     '</ul>')
   121     '</ul>')
       
   122 
       
   123 
       
   124 def allowSidebar(fun):
       
   125   """Decorator that allows access if the sidebar is calling.
       
   126   """
       
   127 
       
   128   from functools import wraps
       
   129 
       
   130   @wraps(fun)
       
   131   def wrapper(self, django_args, *args, **kwargs):
       
   132     if django_args.get('SIDEBAR_CALLING'):
       
   133       return
       
   134     return fun(self, django_args, *args, **kwargs)
       
   135   return wrapper
       
   136 
   119 
   137 
   120 def denySidebar(fun):
   138 def denySidebar(fun):
   121   """Decorator that denies access if the sidebar is calling.
   139   """Decorator that denies access if the sidebar is calling.
   122   """
   140   """
   123 
   141 
   659     self.checkHasRole(new_args, host_logic)
   677     self.checkHasRole(new_args, host_logic)
   660 
   678 
   661 
   679 
   662   @allowDeveloper
   680   @allowDeveloper
   663   def checkCanEditGroupApp(self, django_args, group_app_logic):
   681   def checkCanEditGroupApp(self, django_args, group_app_logic):
   664     """Checks if the group_app in args is valid to be edited.
   682     """Checks if the group_app in args is valid to be edited by the current user.
   665 
   683 
   666     Args:
   684     Args:
   667       group_app_logic: A logic instance for the Group Application
   685       group_app_logic: A logic instance for the Group Application
   668     """
   686     """
   669 
   687 
   682 
   700 
   683     if entity:
   701     if entity:
   684       return
   702       return
   685 
   703 
   686     raise out_of_band.AccessViolation(message_fmt=DEF_NOT_YOUR_ENTITY_MSG)
   704     raise out_of_band.AccessViolation(message_fmt=DEF_NOT_YOUR_ENTITY_MSG)
       
   705 
       
   706 
       
   707   @allowSidebar
       
   708   def checkCanReviewGroupApp(self, django_args, group_app_logic):
       
   709     """Checks if the group_app in args is valid to be reviewed.
       
   710 
       
   711     Args:
       
   712       group_app_logic: A logic instance for the Group Application
       
   713     """
       
   714 
       
   715     if 'link_id' not in django_args:
       
   716       # calling review overview, so we can't check a specified entity
       
   717       return
       
   718 
       
   719     fields = {
       
   720         'link_id': django_args['link_id'],
       
   721         'status' : ['needs review', 'accepted', 'rejected', 'ignored']
       
   722         }
       
   723 
       
   724     if 'scope_path' in django_args:
       
   725       fields['scope_path'] = django_args['scope_path']
       
   726 
       
   727     entity = group_app_logic.getForFields(fields)
       
   728 
       
   729     if entity:
       
   730       return
       
   731 
       
   732     raise out_of_band.AccessViolation(message_fmt=DEF_REVIEW_COMPLETED_MSG)
   687 
   733 
   688 
   734 
   689   @allowDeveloper
   735   @allowDeveloper
   690   def checkIsApplicationAccepted(self, django_args, app_logic):
   736   def checkIsApplicationAccepted(self, django_args, app_logic):
   691     """Returns an alternate HTTP response if Google Account has no Club App
   737     """Returns an alternate HTTP response if Google Account has no Club App