Changeset 7336


Ignore:
Timestamp:
13 Dec 2011, 07:30:55 (13 years ago)
Author:
Henrik Bettermann
Message:

Fix logic of dynamic course adviser role assignment.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/students/dynamicroles.py

    r7334 r7336  
    4646    rolename_mapping = {
    4747        'waeup.local.ClearanceOfficer':'waeup.StudentsClearanceOfficer',
    48         'waeup.local.CourseAdviser100':'waeup.StudentsCourseAdviser',
    49         'waeup.local.CourseAdviser200':'waeup.StudentsCourseAdviser',
    50         'waeup.local.CourseAdviser300':'waeup.StudentsCourseAdviser',
    51         'waeup.local.CourseAdviser400':'waeup.StudentsCourseAdviser',
    52         'waeup.local.CourseAdviser500':'waeup.StudentsCourseAdviser',
    53         'waeup.local.CourseAdviser600':'waeup.StudentsCourseAdviser'
    5448        }
    5549
     
    10195                self._context[self.subcontainer], self.extra_attrib, None)
    10296            current_level = getattr(
    103                 self._context[self.subcontainer], 'current_level', None)
     97                self._context[self.subcontainer], 'current_level', 0)
    10498        else:
    10599            obj = getattr(self._context, self.extra_attrib, None)
    106             current_level = None
    107         # lookup local roles for connected course and all parent
     100            current_level = 0
     101        # Lookup local roles for connected course and all parent
    108102        # objects. This way we fake 'role inheritance'.
    109103        while obj is not None:
     
    111105                principal_id)
    112106            for role_id, setting in extra_roles:
    113                 if role_id in self.rolename_mapping.keys():
    114                     # Found role in external attribute or parent
    115                     # thereof. 'Grant' additional role
    116                     # permissions (allow, deny or unset) for the
    117                     # passed in principal id.
    118                     # Make an exception for Course Advisers:
    119                     # Grant additional role only if external role corresponds
    120                     # with current_level of student.
    121                     if not current_level or \
    122                         'CourseAdviser' not in  role_id or \
    123                         str(current_level) in role_id:
     107                if 'CourseAdviser' in role_id:
     108                    # Found a Course Adviser role in external attribute or parent
     109                    # thereof. We need a special treatment for Course Advisers.
     110                    if str(100*(current_level/100)) in role_id:
     111                        # Grant additional role, which allows to validate or reject
     112                        # course lists, only if external role corresponds
     113                        # with current_level of student.
    124114                        result.append(
    125                             (self.rolename_mapping[role_id], setting))
     115                            ('waeup.StudentsCourseAdviser', setting))
     116                    else:
     117                        # Otherwise grant at least view permissions.
     118                        result.append(
     119                            ('waeup.StudentsOfficer', setting))
     120                elif role_id in self.rolename_mapping.keys():
     121                    # Grant additional role
     122                    # permissions (allow, deny or unset)
     123                    # according to the rolename mapping above.
     124                    result.append(
     125                        (self.rolename_mapping[role_id], setting))
    126126                    return result
    127127            obj = getattr(obj, '__parent__', None)
Note: See TracChangeset for help on using the changeset viewer.