Ignore:
Timestamp:
6 Nov 2015, 05:43:37 (9 years ago)
Author:
Henrik Bettermann
Message:

Implement portal maintenance mode.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/students
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/students/authentication.py

    r12926 r13394  
    113113        """Check whether the given `password` matches the one stored by
    114114        students or the temporary password set by officers.
    115 
    116         We additionally check if student account has been suspended.
    117         """
     115        We additionally check if student account has been suspended
     116        or if the portal is blocked.
     117        """
     118        try:
     119            blocker = grok.getSite()['configuration'].maintmode_enabled_by
     120            if blocker:
     121                return False
     122        except TypeError:  # in unit tests
     123            pass
    118124        if not isinstance(password, basestring):
    119125            return False
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py

    r13349 r13394  
    13871387        filewidget.add_file(filecontents, 'text/plain', 'students.csv')
    13881388        self.browser.getControl(name='SUBMIT').click()
     1389        self.browser.getLink("Switch maintenance mode").click()
    13891390        self.browser.getLink('Process data').click()
    13901391        button = lookup_submit_value(
     
    14131414        filewidget.add_file(filecontents, 'text/plain', 'studycourses.csv')
    14141415        self.browser.getControl(name='SUBMIT').click()
     1416        # Meanwhile maintenance mode is disabled again.
     1417        self.browser.getLink("Switch maintenance mode").click()
    14151418        self.browser.getLink('Process data').click()
    14161419        button = lookup_submit_value(
     
    23762379            '...You logged in...', self.browser.contents)
    23772380
     2381    def test_maintenance_mode(self):
     2382        config = grok.getSite()['configuration']
     2383        self.browser.open(self.login_path)
     2384        self.browser.getControl(name="form.login").value = self.student_id
     2385        self.browser.getControl(name="form.password").value = 'spwd'
     2386        self.browser.getControl("Login").click()
     2387        # Student logged in.
     2388        self.assertTrue('You logged in' in self.browser.contents)
     2389        self.assertTrue("Anna Tester" in self.browser.contents)
     2390        # If maintenance mode is enabled, student is immediately logged out.
     2391        config.maintmode_enabled_by = u'any_user'
     2392        self.assertRaises(
     2393            Unauthorized, self.browser.open, 'http://localhost/app/faculties')
     2394        self.browser.open('http://localhost/app/login')
     2395        self.assertTrue('The portal is in maintenance mode' in self.browser.contents)
     2396        # Student really can't login if maintenance mode is enabled.
     2397        self.browser.open(self.login_path)
     2398        self.browser.getControl(name="form.login").value = self.student_id
     2399        self.browser.getControl(name="form.password").value = 'spwd'
     2400        self.browser.getControl("Login").click()
     2401        # A second warning is raised.
     2402        self.assertTrue(
     2403            'The portal is in maintenance mode. You can\'t login!'
     2404            in self.browser.contents)
     2405        return
     2406
    23782407    def test_student_clearance(self):
    23792408        # Student cant login if their password is not set
Note: See TracChangeset for help on using the changeset viewer.