--- a/app/soc/modules/ghop/views/helper/access.py Fri Nov 13 19:02:38 2009 +0100
+++ b/app/soc/modules/ghop/views/helper/access.py Sat Nov 14 17:22:44 2009 +0100
@@ -37,6 +37,7 @@
from soc.modules.ghop.logic.models import mentor as ghop_mentor_logic
from soc.modules.ghop.logic.models import org_admin as ghop_org_admin_logic
from soc.modules.ghop.logic.models import program as ghop_program_logic
+from soc.modules.ghop.logic.models.student import logic as ghop_student_logic
from soc.modules.ghop.logic.models import task as ghop_task_logic
@@ -66,6 +67,9 @@
DEF_SIGN_UP_AS_OA_MENTOR_MSG = ugettext(
'You first need to sign up as an Org Admin or a Mentor.')
+DEF_NO_TASKS_ASSIGNED = ugettext(
+ 'There are no tasks which have been assigned to you.')
+
class GHOPChecker(access.Checker):
"""See soc.views.helper.access.Checker.
@@ -267,3 +271,33 @@
# no completed tasks found, access denied
raise out_of_band.AccessViolation(
message_fmt=DEF_CANT_REGISTER)
+
+ def checkCanOpenTaskList(self, django_args):
+ """Checks if the current user is allowed to see a list of his tasks.
+
+ Args:
+ django_args: a dictionary with django's arguments
+
+ Raises:
+ AccessViolationResponse:
+ - if the user is not registered as a student; and
+ - if the user has not claimed a single task
+ """
+
+ try:
+ return self.checkHasActiveRoleForScope(django_args, ghop_student_logic)
+ except out_of_band.Error:
+ pass
+
+ program = ghop_program_logic.logic.getFromKeyNameOr404(
+ django_args['scope_path'])
+
+ filter = {
+ 'user': self.user,
+ 'program': program,
+ 'status': ['ClaimRequested', 'Claimed', 'ActionNeeded', 'NeedsWork',
+ 'AwaitingRegistration', 'NeedsReview']
+ }
+
+ if not ghop_task_logic.logic.getForFields(filter, unique=True):
+ raise out_of_band.AccessViolation(message_fmt=DEF_NO_TASKS_ASSIGNED)