Users who claim or work on tasks may list them without having student role.
--- 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)
--- a/app/soc/modules/ghop/views/models/program.py Fri Nov 13 19:02:38 2009 +0100
+++ b/app/soc/modules/ghop/views/models/program.py Sat Nov 14 17:22:44 2009 +0100
@@ -398,6 +398,20 @@
if student_entity:
items += self._getStudentEntries(ghop_program_entity, student_entity,
params, id, user)
+ else:
+ # if a user has a task assigned, he or she still may list it
+ filter = {
+ 'user': user,
+ 'program': ghop_program_entity,
+ 'status': ['ClaimRequested', 'Claimed', 'ActionNeeded', 'NeedsWork',
+ 'AwaitingRegistration', 'NeedsReview']
+ }
+ tasks = ghop_task_logic.logic.getForFields(filter)
+
+ if tasks:
+ items += [(ghop_redirects.getListStudentTasksRedirect(
+ ghop_program_entity, {'url_name':'ghop/student'}),
+ "List my Tasks", 'any_access')]
# get mentor and org_admin entity for this user and program
filter = {'user': user,
--- a/app/soc/modules/ghop/views/models/student.py Fri Nov 13 19:02:38 2009 +0100
+++ b/app/soc/modules/ghop/views/models/student.py Sat Nov 14 17:22:44 2009 +0100
@@ -79,8 +79,7 @@
ghop_org_admin_logic.logic, ghop_mentor_logic.logic]),
'checkCanApply']
rights['manage'] = [('checkIsMyActiveRole', ghop_student_logic.logic)]
- rights['list_student_tasks'] = [('checkHasActiveRoleForScope',
- ghop_student_logic.logic)]
+ rights['list_student_tasks'] = ['checkCanOpenTaskList']
new_params = {}
new_params['logic'] = soc.modules.ghop.logic.models.student.logic