app/soc/modules/ghop/views/helper/access.py
changeset 3088 08b9f4de6675
parent 3070 afd98e17a2b2
equal deleted inserted replaced
3087:9de33dfd6220 3088:08b9f4de6675
    35 from soc.views.helper import access
    35 from soc.views.helper import access
    36 
    36 
    37 from soc.modules.ghop.logic.models import mentor as ghop_mentor_logic
    37 from soc.modules.ghop.logic.models import mentor as ghop_mentor_logic
    38 from soc.modules.ghop.logic.models import org_admin as ghop_org_admin_logic
    38 from soc.modules.ghop.logic.models import org_admin as ghop_org_admin_logic
    39 from soc.modules.ghop.logic.models import program as ghop_program_logic
    39 from soc.modules.ghop.logic.models import program as ghop_program_logic
       
    40 from soc.modules.ghop.logic.models.student import logic as ghop_student_logic
    40 from soc.modules.ghop.logic.models import task as ghop_task_logic
    41 from soc.modules.ghop.logic.models import task as ghop_task_logic
    41 
    42 
    42 
    43 
    43 DEF_CANT_EDIT_MSG = ugettext(
    44 DEF_CANT_EDIT_MSG = ugettext(
    44     'This task cannot be edited since it has been claimed at least '
    45     'This task cannot be edited since it has been claimed at least '
    63 DEF_PAGE_INACTIVE_MSG = ugettext(
    64 DEF_PAGE_INACTIVE_MSG = ugettext(
    64     'This page is inactive at this time.')
    65     'This page is inactive at this time.')
    65 
    66 
    66 DEF_SIGN_UP_AS_OA_MENTOR_MSG = ugettext(
    67 DEF_SIGN_UP_AS_OA_MENTOR_MSG = ugettext(
    67     'You first need to sign up as an Org Admin or a Mentor.')
    68     'You first need to sign up as an Org Admin or a Mentor.')
       
    69 
       
    70 DEF_NO_TASKS_ASSIGNED = ugettext(
       
    71     'There are no tasks which have been assigned to you.')
    68 
    72 
    69 
    73 
    70 class GHOPChecker(access.Checker):
    74 class GHOPChecker(access.Checker):
    71   """See soc.views.helper.access.Checker.
    75   """See soc.views.helper.access.Checker.
    72   """
    76   """
   265       return
   269       return
   266 
   270 
   267     # no completed tasks found, access denied
   271     # no completed tasks found, access denied
   268     raise out_of_band.AccessViolation(
   272     raise out_of_band.AccessViolation(
   269         message_fmt=DEF_CANT_REGISTER)
   273         message_fmt=DEF_CANT_REGISTER)
       
   274 
       
   275   def checkCanOpenTaskList(self, django_args):
       
   276     """Checks if the current user is allowed to see a list of his tasks.
       
   277 
       
   278     Args:
       
   279       django_args: a dictionary with django's arguments
       
   280 
       
   281     Raises:
       
   282       AccessViolationResponse:
       
   283         - if the user is not registered as a student; and
       
   284         - if the user has not claimed a single task
       
   285     """
       
   286 
       
   287     try:
       
   288       return self.checkHasActiveRoleForScope(django_args, ghop_student_logic)
       
   289     except out_of_band.Error:
       
   290       pass
       
   291 
       
   292     program = ghop_program_logic.logic.getFromKeyNameOr404(
       
   293         django_args['scope_path'])
       
   294 
       
   295     filter = {
       
   296         'user': self.user,
       
   297         'program': program,
       
   298         'status': ['ClaimRequested', 'Claimed', 'ActionNeeded', 'NeedsWork',
       
   299             'AwaitingRegistration', 'NeedsReview']
       
   300         }
       
   301 
       
   302     if not ghop_task_logic.logic.getForFields(filter, unique=True):
       
   303       raise out_of_band.AccessViolation(message_fmt=DEF_NO_TASKS_ASSIGNED)