Ignore:
Timestamp:
5 Aug 2020, 13:55:44 (4 years ago)
Author:
Henrik Bettermann
Message:

Implement temporarily clearance.

Location:
main/waeup.kofa/trunk/src/waeup/kofa
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/tests/test_browser.py

    r15918 r16187  
    442442            'phone,reg_number,sex,student_id,suspended,suspended_comment,'
    443443            'password,state,history,certcode,is_postgrad,current_level,'
    444             'current_session\r\n')
     444            'current_session,entry_session\r\n')
    445445        logfile = os.path.join(
    446446            self.app['datacenter'].storage, 'logs', 'datacenter.log')
  • main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py

    r16170 r16187  
    858858        return
    859859
     860class StudentTempClearancePage(KofaEditFormPage):
     861    """ Temporarily clearance by clearance officers.
     862    """
     863    grok.context(IStudent)
     864    grok.name('temp_clearance')
     865    label = _('Clear student temporarily')
     866    grok.require('waeup.clearStudent')
     867    form_fields = grok.AutoFields(
     868        IUGStudentClearance).select('officer_comment')
     869
     870    def update(self):
     871        cdm = getUtility(IStudentsUtils).clearance_disabled_message(
     872            self.context)
     873        if cdm:
     874            self.flash(cdm, type="warning")
     875            self.redirect(self.url(self.context,'view_clearance'))
     876            return
     877        return super(StudentTempClearancePage, self).update()
     878
     879    @action(_('Save comment and clear student temporarily now'), style='primary')
     880    def temp_clear(self, **data):
     881        if self.context.state == REQUESTED:
     882            if self.context.officer_comment \
     883                and self.context.officer_comment.startswith('Temporarily cleared'):
     884                self.flash(
     885                    _('Not allowed: student has already been '
     886                      'temporarily cleared.'),
     887                    type="warning")
     888                self.redirect(self.url(self.context,'view_clearance'))
     889                return
     890            if not data['officer_comment']:
     891                self.flash(_('Please write a comment.'), type="warning")
     892                self.redirect(self.url(self.context,'view_clearance'))
     893                return
     894            message = _('Student has been temporarily cleared.')
     895            self.flash(message)
     896        else:
     897            self.flash(_('Student is in wrong state.'), type="warning")
     898            self.redirect(self.url(self.context,'view_clearance'))
     899            return
     900        user = get_current_principal()
     901        if user is None:
     902            usertitle = 'system'
     903        else:
     904            usertitle = getattr(user, 'public_name', None)
     905            if not usertitle:
     906                usertitle = user.title
     907        comment = data['officer_comment']
     908        data['officer_comment'] = translate(
     909            _('Temporarily cleared by ${a}. Officers comment:\n${b}',
     910            mapping = {'a':usertitle, 'b':comment}))
     911        self.applyData(self.context, **data)
     912        self.context.writeLogMessage(
     913            self, 'comment: %s' % comment.replace('\n', '<br>'))
     914        args = {'subject':'You have been temporarily cleared.', 'body':comment}
     915        self.redirect(self.url(self.context) +
     916            '/contactstudent?%s' % urlencode(args))
     917        return
     918
    860919class StudentRejectClearancePage(KofaEditFormPage):
    861920    """ Reject clearance by clearance officers.
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py

    r16186 r16187  
    16771677        IWorkflowInfo(self.student).fireTransition('clear')
    16781678        self.assertEqual(self.student.officer_comment, None)
     1679        return
     1680
     1681    def test_handle_temp_clearance_by_co(self):
     1682        self.app['configuration']['2004'].clearance_enabled = True
     1683        self.init_clearance_officer()
     1684        # Hide real name.
     1685        self.app['users']['mrclear'].public_name = 'My Public Name'
     1686        IWorkflowInfo(self.student).fireTransition('request_clearance')
     1687        #notify(LocalRoleSetEvent(
     1688        #    self.department, 'waeup.local.ClearanceOfficer', 'mrclear',
     1689        #    granted=True))
     1690        # CO can view the student ...
     1691        self.browser.open(self.clearance_path)
     1692        self.browser.getLink("Clear student temporarily").click()
     1693        self.assertEqual(
     1694            self.browser.url, self.student_path + '/temp_clearance')
     1695        # Type comment why.
     1696        self.browser.getControl(name="form.officer_comment").value = (
     1697            'Dear Student,\n'
     1698            'Your birth cert is missing.')
     1699        self.browser.getControl(
     1700            'Save comment and clear student temporarily now').click()
     1701        self.assertTrue('Student has been temporarily cleared.'
     1702            in self.browser.contents)
     1703        url = ('http://localhost/app/students/K1000000/'
     1704              'contactstudent?body=Dear+Student%2C%0AYour+birth+cert+is+missing.'
     1705              '&subject=You+have+been+temporarily+cleared.')
     1706        # CO does now see the prefilled contact form and can send a message.
     1707        self.assertEqual(self.browser.url, url)
     1708        self.assertTrue('clearance requested' in self.browser.contents)
     1709        self.assertTrue('name="form.subject" size="20" type="text" '
     1710            'value="You have been temporarily cleared."'
     1711            in self.browser.contents)
     1712        self.assertTrue('name="form.body" rows="10" >Dear Student,'
     1713            in self.browser.contents)
     1714        self.browser.getControl("Send message now").click()
     1715        self.assertTrue('Your message has been sent' in self.browser.contents)
     1716        # The comment has been stored ...
     1717        self.assertEqual(self.student.officer_comment,
     1718            'Temporarily cleared by My Public Name. Officers comment:\n'
     1719            'Dear Student,\nYour birth cert is missing.')
     1720        # ... and logged.
     1721        logfile = os.path.join(
     1722            self.app['datacenter'].storage, 'logs', 'students.log')
     1723        logcontent = open(logfile).read()
     1724        self.assertTrue(
     1725            'INFO - mrclear - students.browser.StudentTempClearancePage - '
     1726            'K1000000 - comment: Dear Student,<br>Your birth cert is '
     1727            'missing.\n' in logcontent)
     1728        # CO can view the student bus no longer see the temp clearance button ...
     1729        self.browser.open(self.clearance_path)
     1730        self.assertFalse('Clear student temporarily' in self.browser.contents)
    16791731        return
    16801732
  • main/waeup.kofa/trunk/src/waeup/kofa/students/viewlets.py

    r16170 r16187  
    306306        return self.view.url(self.view.context, self.target)
    307307
     308class StudentTemporarilyClearActionButton(ManageActionButton):
     309    grok.order(3)
     310    grok.context(IStudent)
     311    grok.view(StudentClearanceDisplayFormPage)
     312    grok.require('waeup.clearStudent')
     313    text = _('Clear student temporarily')
     314    target = 'temp_clearance'
     315    icon = 'actionicon_accept.png'
     316
     317    @property
     318    def target_url(self):
     319        cdm = getUtility(
     320            IStudentsUtils).clearance_disabled_message(self.context)
     321        if cdm:
     322            return ''
     323        if self.context.officer_comment \
     324            and self.context.officer_comment.startswith('Temporarily cleared'):
     325            return ''
     326        if self.context.state != REQUESTED:
     327            return ''
     328        return self.view.url(self.view.context, self.target)
     329
    308330
    309331class StudentRejectClearanceActionButton(ManageActionButton):
    310     grok.order(3)
     332    grok.order(4)
    311333    grok.context(IStudent)
    312334    grok.view(StudentClearanceDisplayFormPage)
     
    328350
    329351class ClearanceSlipActionButton(ManageActionButton):
    330     grok.order(4)
     352    grok.order(5)
    331353    grok.context(IStudent)
    332354    grok.view(StudentClearanceDisplayFormPage)
Note: See TracChangeset for help on using the changeset viewer.