Ignore:
Timestamp:
12 Dec 2011, 14:11:21 (13 years ago)
Author:
Henrik Bettermann
Message:

Implement local CourseAdviser? roles. These roles can be assigned in departments and certificates. There are 6 different roles, one for each study level. getRolesForPrincipal grants the additional waeup.StudentsCourseAdviser? role only if the current level of a student corresponds with the level number in the external role name.

To do: Assign local roles on CertificateManageFormPage?. Add browser tests.

Location:
main/waeup.sirp/trunk/src/waeup/sirp/students
Files:
3 edited

Legend:

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

    r7329 r7334  
    594594
    595595    def render(self):
    596         self.redirect(self.url(self.context, 'view_clearance'))
    597596        return
    598597
     
    615614        else:
    616615            self.flash('Student is in the wrong state.')
     616            self.redirect(self.url(self.context,'view_clearance'))
    617617            return
    618618        args = {'subject':message}
     
    857857    target = 'manage'
    858858
     859class StudentValidateCoursesActionButton(ManageActionButton):
     860    grok.order(3)
     861    grok.context(IStudentStudyLevel)
     862    grok.view(StudyLevelDisplayFormPage)
     863    grok.require('waeup.validateStudent')
     864    text = 'Validate courses'
     865    target = 'validate_courses'
     866    icon = 'actionicon_accept.png'
     867
     868    @property
     869    def target_url(self):
     870        if self.context.getStudent().state != REGISTERED or \
     871            str(self.context.__parent__.current_level) != self.context.__name__:
     872            return ''
     873        return self.view.url(self.view.context, self.target)
     874
     875class StudentRejectCoursesActionButton(ManageActionButton):
     876    grok.order(4)
     877    grok.context(IStudentStudyLevel)
     878    grok.view(StudyLevelDisplayFormPage)
     879    grok.require('waeup.validateStudent')
     880    text = 'Reject courses'
     881    target = 'reject_courses'
     882    icon = 'actionicon_reject.png'
     883
     884    @property
     885    def target_url(self):
     886        if self.context.getStudent().state not in (VALIDATED, REGISTERED) or \
     887            str(self.context.__parent__.current_level) != self.context.__name__:
     888            return ''
     889        return self.view.url(self.view.context, self.target)
     890
    859891class StudyLevelManageFormPage(SIRPEditFormPage):
    860892    """ Page to edit the student study level data
     
    915947            self.flash('Successfully removed: %s' % ', '.join(deleted))
    916948        self.redirect(self.url(self.context, u'@@manage')+'#tab-2')
     949        return
     950
     951class ValidateCoursesPage(grok.View):
     952    """ Validate course list by course adviser
     953    """
     954    grok.context(IStudentStudyLevel)
     955    grok.name('validate_courses')
     956    grok.require('waeup.validateStudent')
     957
     958    def update(self):
     959        if str(self.context.__parent__.current_level) != self.context.__name__:
     960            self.flash('This level does not correspond current level.')
     961        elif self.context.getStudent().state == REGISTERED:
     962            IWorkflowInfo(self.context.getStudent()).fireTransition('validate_courses')
     963            self.flash('Course list has been registered.')
     964        else:
     965            self.flash('Student is in the wrong state.')
     966        self.redirect(self.url(self.context))
     967        return
     968
     969    def render(self):
     970        return
     971
     972class RejectCoursesPage(grok.View):
     973    """ Reject course list by course adviser
     974    """
     975    grok.context(IStudentStudyLevel)
     976    grok.name('reject_courses')
     977    grok.require('waeup.validateStudent')
     978
     979    def update(self):
     980        if str(self.context.__parent__.current_level) != self.context.__name__:
     981            self.flash('This level does not correspond current level.')
     982            self.redirect(self.url(self.context))
     983            return
     984        elif self.context.getStudent().state == VALIDATED:
     985            IWorkflowInfo(self.context.getStudent()).fireTransition('reset8')
     986            message = 'Course list request has been annulled'
     987            self.flash(message)
     988        elif self.context.getStudent().state == REGISTERED:
     989            IWorkflowInfo(self.context.getStudent()).fireTransition('reset7')
     990            message = 'Course list request has been rejected'
     991            self.flash(message)
     992        else:
     993            self.flash('Student is in the wrong state.')
     994            self.redirect(self.url(self.context))
     995            return
     996        args = {'subject':message}
     997        self.redirect(self.url(self.context.getStudent()) +
     998            '/contactstudent?%s' % urlencode(args))
     999        return
     1000
     1001    def render(self):
    9171002        return
    9181003
  • main/waeup.sirp/trunk/src/waeup/sirp/students/dynamicroles.py

    r7256 r7334  
    4646    rolename_mapping = {
    4747        'waeup.local.ClearanceOfficer':'waeup.StudentsClearanceOfficer',
    48         'waeup.local.CourseAdviser100':'waeup.StudentsCourseAdviser100',
    49         'waeup.local.CourseAdviser200':'waeup.StudentsCourseAdviser200',
    50         'waeup.local.CourseAdviser300':'waeup.StudentsCourseAdviser300',
    51         'waeup.local.CourseAdviser400':'waeup.StudentsCourseAdviser400',
    52         'waeup.local.CourseAdviser500':'waeup.StudentsCourseAdviser500',
    53         'waeup.local.CourseAdviser600':'waeup.StudentsCourseAdviser600'
     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'
    5454        }
    5555
     
    100100            obj = getattr(
    101101                self._context[self.subcontainer], self.extra_attrib, None)
     102            current_level = getattr(
     103                self._context[self.subcontainer], 'current_level', None)
    102104        else:
    103105            obj = getattr(self._context, self.extra_attrib, None)
     106            current_level = None
    104107        # lookup local roles for connected course and all parent
    105108        # objects. This way we fake 'role inheritance'.
     
    113116                    # permissions (allow, deny or unset) for the
    114117                    # passed in principal id.
    115                     result.append(
    116                         (self.rolename_mapping[role_id], setting))
     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:
     124                        result.append(
     125                            (self.rolename_mapping[role_id], setting))
    117126                    return result
    118127            obj = getattr(obj, '__parent__', None)
  • main/waeup.sirp/trunk/src/waeup/sirp/students/permissions.py

    r7240 r7334  
    5353    grok.name('waeup.clearStudent')
    5454
     55class ValidateStudent(grok.Permission):
     56    grok.name('waeup.validateStudent')
     57
    5558# Local role
    5659class StudentRecordOwner(grok.Role):
     
    8386    grok.title(u'Clearance Officer (all students)')
    8487    grok.permissions('waeup.clearStudent','waeup.viewStudent')
     88
     89class StudentsCourseAdviser(grok.Role):
     90    grok.name('waeup.StudentsCourseAdviser')
     91    grok.title(u'Course Adviser (all students)')
     92    grok.permissions('waeup.validateStudent','waeup.viewStudent')
Note: See TracChangeset for help on using the changeset viewer.