Changeset 13394
- Timestamp:
- 6 Nov 2015, 05:43:37 (9 years ago)
- Location:
- main/waeup.kofa/trunk
- Files:
-
- 1 added
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/CHANGES.txt
r13363 r13394 4 4 1.3.4.dev0 (unreleased) 5 5 ======================= 6 7 * Add portal maintenance mode. 6 8 7 9 * Allow also reg_number on public page to check application status -
main/waeup.kofa/trunk/src/waeup/kofa/applicants/authentication.py
r9335 r13394 48 48 def checkPassword(self, password): 49 49 """Check whether the given `password` matches the one stored by 50 students. 51 52 We additionally check if student account has been suspended. 50 students. We additionally check if applicant account has been suspended 51 or if the portal is blocked. 53 52 """ 53 try: 54 blocker = grok.getSite()['configuration'].maintmode_enabled_by 55 if blocker: 56 return False 57 except TypeError: # in unit tests 58 pass 54 59 if not isinstance(password, basestring): 55 60 return False -
main/waeup.kofa/trunk/src/waeup/kofa/applicants/browser.py
r13365 r13394 1199 1199 if self.context.expired: 1200 1200 self.flash(_('Outside application period.'), type='warning') 1201 self.redirect(self.url(self.context)) 1202 return 1203 blocker = grok.getSite()['configuration'].maintmode_enabled_by 1204 if blocker: 1205 self.flash(_('The portal is in maintenance mode ' 1206 'and registration temporarily disabled.'), 1207 type='warning') 1201 1208 self.redirect(self.url(self.context)) 1202 1209 return -
main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_browser.py
r13365 r13394 609 609 self.assertTrue( 610 610 'You logged in.' in self.browser.contents) 611 612 def test_maintenance_mode(self): 613 config = grok.getSite()['configuration'] 614 self.login() 615 # Applicant logged in. 616 self.assertTrue('You logged in' in self.browser.contents) 617 self.assertTrue("Joan None" in self.browser.contents) 618 # If maintenance mode is enabled, applicant is immediately logged out. 619 config.maintmode_enabled_by = u'any_user' 620 self.assertRaises( 621 Unauthorized, self.browser.open, 'http://localhost/app/faculties') 622 self.browser.open('http://localhost/app/login') 623 self.assertTrue('The portal is in maintenance mode' in self.browser.contents) 624 # Applicant really can't login if maintenance mode is enabled. 625 self.login() 626 # A second warning is raised. 627 self.assertTrue( 628 'The portal is in maintenance mode. You can\'t login!' 629 in self.browser.contents) 630 return 611 631 612 632 def test_applicant_access(self): … … 1250 1270 1251 1271 def test_register_applicant_create(self): 1272 config = grok.getSite()['configuration'] 1273 config.maintmode_enabled_by = u'any_user' 1252 1274 self.assertEqual(len(self.app['applicants'][container_name_1]), 1) 1253 1275 # An applicant can register himself. 1254 1276 self.browser.open(self.container_path) 1255 1277 self.browser.getLink("Register for application").click() 1256 # Fill the edit form with suitable values 1278 self.assertTrue( 1279 'The portal is in maintenance mode' in self.browser.contents) 1280 config.maintmode_enabled_by = None 1281 self.browser.getLink("Register for application").click() 1282 # The edit form now opens and can be filled with suitable values 1257 1283 self.browser.getControl(name="form.firstname").value = 'Anna' 1258 1284 self.browser.getControl(name="form.lastname").value = 'Kurios' -
main/waeup.kofa/trunk/src/waeup/kofa/authentication.py
r13182 r13394 223 223 224 224 def checkPassword(self, password): 225 try: 226 blocker = grok.getSite()['configuration'].maintmode_enabled_by 227 if blocker and blocker != self.name: 228 return False 229 except (TypeError, KeyError): # in unit tests 230 pass 225 231 if not isinstance(password, basestring): 226 232 return False -
main/waeup.kofa/trunk/src/waeup/kofa/browser/pages.py
r13354 r13394 337 337 338 338 def update(self, SUBMIT=None, camefrom=None): 339 blocker = grok.getSite()['configuration'].maintmode_enabled_by 340 if blocker: 341 self.flash(_('The portal is in maintenance mode ' 342 'and authentication (login) temporarily disabled.'), 343 type='warning') 339 344 self.camefrom = camefrom 340 345 if SUBMIT is not None: … … 363 368 return 364 369 self.redirect(self.camefrom) 370 return 371 # Display second warning message and remind user that 372 # s/he can't login. 373 if blocker: 374 self.flash(_('The portal is in maintenance mode. ' 375 'You can\'t login!'), 376 type='danger') 365 377 return 366 378 # Display appropriate flash message if credentials are correct … … 1001 1013 form_fields = grok.AutoFields(IConfigurationContainer).omit( 1002 1014 'frontpage_dict', 'next_matric_integer', 'next_matric_integer_2') 1015 form_fields['maintmode_enabled_by'].for_display = True 1003 1016 1004 1017 @action(_('Save'), style='primary') … … 1354 1367 1355 1368 def update(self, filename=None, select=None, cancel=None): 1369 if not grok.getSite()['configuration'].maintmode_enabled_by and \ 1370 not self.request.principal.id == 'admin': 1371 self.flash( 1372 _('Portal must be in maintenance mode for data import.'), 1373 type='warning') 1374 self.redirect(self.url(self.context)) 1375 return 1356 1376 if cancel is not None: 1357 1377 self.redirect(self.url(self.context)) … … 1362 1382 session['import_filename'] = select 1363 1383 self.redirect(self.url(self.context, '@@import2')) 1384 return 1364 1385 1365 1386 class DatacenterImportStep2(KofaPage): … … 1639 1660 self.mode) 1640 1661 1662 # Disable maintenance mode if set. 1663 if grok.getSite()['configuration'].maintmode_enabled_by: 1664 grok.getSite()['configuration'].maintmode_enabled_by = None 1665 self.flash(_('Maintenance mode disabled.')) 1666 1641 1667 if self.warn_num: 1642 1668 self.flash(_('Processing of ${a} rows failed.', … … 1823 1849 '%s - downloaded: %s, job_id=%s' % (ob_class, filename, job_id)) 1824 1850 return result 1851 1852 class SwitchMaintModePage(UtilityView, grok.View): 1853 """Import managers must disable authentication for all other users 1854 before starting an import. This pages switches maintenance mode 1855 on and off. 1856 """ 1857 grok.context(IDataCenter) 1858 grok.name('switchmaintmode') 1859 grok.require('waeup.importData') 1860 1861 def update(self): 1862 ob_class = self.__implemented__.__name__.replace('waeup.kofa.','') 1863 if grok.getSite()['configuration'].maintmode_enabled_by: 1864 grok.getSite()['configuration'].maintmode_enabled_by = None 1865 self.context.logger.info('%s - maintmode disabled' % ob_class) 1866 self.flash(_('Maintenance mode disabled.')) 1867 else: 1868 grok.getSite()['configuration'].maintmode_enabled_by = unicode( 1869 self.request.principal.id) 1870 self.context.logger.info('%s - maintmode enabled' % ob_class) 1871 self.flash(_('Maintenance mode enabled.'), type='warning') 1872 self.redirect(self.url(self.context)) 1873 return 1874 1875 def render(self): 1876 return 1825 1877 1826 1878 # -
main/waeup.kofa/trunk/src/waeup/kofa/browser/templates/configurationmanagepage.pt
r11254 r13394 18 18 </tbody> 19 19 </table> 20 <br /> 20 21 <div tal:condition="view/availableActions"> 21 22 <span tal:repeat="action view/actions" tal:omit-tag=""> -
main/waeup.kofa/trunk/src/waeup/kofa/browser/tests/test_browser.py
r13199 r13394 22 22 import tempfile 23 23 import os 24 import grok 24 25 from zc.async.testing import wait_for_result 25 26 from zope.component import createObject, getUtility … … 506 507 self.browser.getControl(name="form.password").value = 'secret' 507 508 self.browser.getControl("Login").click() 508 # Yeah, office logged in.509 # Yeah, officer logged in. 509 510 self.assertMatches( 510 511 '...You logged in...', self.browser.contents) … … 531 532 return 532 533 534 def test_maintenance_mode(self): 535 config = grok.getSite()['configuration'] 536 self.app['users'].addUser( 537 'officer', 'secret', title='Bob Officer', email='bob@abcd.ng') 538 self.browser.open('http://localhost/app/login') 539 self.browser.getControl(name="form.login").value = 'officer' 540 self.browser.getControl(name="form.password").value = 'secret' 541 self.browser.getControl("Login").click() 542 # Officer logged in. 543 self.assertMatches('...You logged in...', self.browser.contents) 544 self.assertTrue("Bob Officer" in self.browser.contents) 545 # If maintenance mode is enabled, officer is immediately logged out. 546 config.maintmode_enabled_by = u'any_user' 547 self.assertRaises( 548 Unauthorized, self.browser.open, 'http://localhost/app/faculties') 549 self.browser.open('http://localhost/app/login') 550 self.assertMatches( 551 '...The portal is in maintenance mode...', 552 self.browser.contents) 553 # Officers really can't login if maintenance mode is enabled. 554 self.browser.getControl(name="form.login").value = 'officer' 555 self.browser.getControl(name="form.password").value = 'secret' 556 self.browser.getControl("Login").click() 557 # A second warning is raised. 558 self.assertMatches( 559 '...The portal is in maintenance mode. You can\'t login!...', 560 self.browser.contents) 561 # Offficer can login if s/he is the blocker. 562 config.maintmode_enabled_by = u'officer' 563 self.browser.getControl(name="form.login").value = 'officer' 564 self.browser.getControl(name="form.password").value = 'secret' 565 self.browser.getControl("Login").click() 566 self.assertTrue('You logged in' in self.browser.contents) 567 self.assertTrue('Logout' in self.browser.contents) 568 return 569 533 570 def test_sources_overview(self): 534 571 self.browser.open('http://localhost/app/sources') -
main/waeup.kofa/trunk/src/waeup/kofa/browser/viewlets.py
r13119 r13394 628 628 text = _('View processed files') 629 629 630 class SwitchMaintMode(ActionButton): 631 grok.context(IDataCenter) 632 grok.require('waeup.importData') 633 grok.view(DatacenterPage) 634 grok.order(7) 635 icon = 'actionicon_stop.png' 636 target = 'switchmaintmode' 637 text = _('Switch maintenance mode') 638 639 @property 640 def onclick(self): 641 if grok.getSite()['configuration'].maintmode_enabled_by: 642 return 643 return "return window.confirm(%s);" % _( 644 "'In maintenance mode no other user can login, and " 645 "already logged-in users will be automatically logged out. " 646 "You will be the only logged-in user and you can safely start " 647 "any import. Please wait a few seconds before starting the import " 648 "so that all running processes are finished. " 649 "If the import is done, maintenance mode will " 650 "be automatically disabled. \\n\\n" 651 "You really want to enable maintenance mode?'") 652 630 653 # 631 654 # Primary navigation tabs (in upper left navigation bar)... -
main/waeup.kofa/trunk/src/waeup/kofa/doctests/batchprocessing_browser.txt
r12981 r13394 86 86 Step 1: start batch processing: 87 87 88 >>> browser.getLink('Switch maintenance mode').click() 88 89 >>> browser.getLink('Process data').click() 89 90 >>> button = lookup_submit_value( … … 191 192 Step 1: start batch processing: 192 193 194 >>> browser.getLink('Switch maintenance mode').click() 193 195 >>> browser.getLink('Process data').click() 194 196 >>> button = lookup_submit_value( … … 256 258 Step 1: start batch processing: 257 259 260 >>> browser.getLink('Switch maintenance mode').click() 258 261 >>> browser.getLink('Process data').click() 259 262 >>> button = lookup_submit_value( … … 321 324 Step 1: start batch processing: 322 325 326 >>> browser.getLink('Switch maintenance mode').click() 323 327 >>> browser.getLink('Process data').click() 324 328 >>> button = lookup_submit_value( … … 387 391 Step 1: start batch processing: 388 392 393 >>> browser.getLink('Switch maintenance mode').click() 389 394 >>> browser.getLink('Process data').click() 390 395 >>> button = lookup_submit_value( … … 453 458 Step 1: start batch processing: 454 459 460 >>> browser.getLink('Switch maintenance mode').click() 455 461 >>> browser.getLink('Process data').click() 456 462 >>> button = lookup_submit_value( … … 539 545 Step 1: start batch processing: 540 546 547 >>> browser.getLink('Switch maintenance mode').click() 541 548 >>> browser.getLink('Process data').click() 542 549 >>> button = lookup_submit_value( … … 602 609 603 610 >>> browser.open('http://localhost/app/datacenter') 611 >>> browser.getLink('Switch maintenance mode').click() 604 612 >>> browser.getLink('Process data').click() 605 613 >>> button = lookup_submit_value( -
main/waeup.kofa/trunk/src/waeup/kofa/interfaces.py
r13354 r13394 741 741 ) 742 742 743 maintmode_enabled_by = schema.TextLine( 744 title = _(u'Maintenance Mode enabled by'), 745 default = None, 746 required = False, 747 ) 743 748 744 749 def addSessionConfiguration(sessionconfiguration): -
main/waeup.kofa/trunk/src/waeup/kofa/students/authentication.py
r12926 r13394 113 113 """Check whether the given `password` matches the one stored by 114 114 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 118 124 if not isinstance(password, basestring): 119 125 return False -
main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py
r13349 r13394 1387 1387 filewidget.add_file(filecontents, 'text/plain', 'students.csv') 1388 1388 self.browser.getControl(name='SUBMIT').click() 1389 self.browser.getLink("Switch maintenance mode").click() 1389 1390 self.browser.getLink('Process data').click() 1390 1391 button = lookup_submit_value( … … 1413 1414 filewidget.add_file(filecontents, 'text/plain', 'studycourses.csv') 1414 1415 self.browser.getControl(name='SUBMIT').click() 1416 # Meanwhile maintenance mode is disabled again. 1417 self.browser.getLink("Switch maintenance mode").click() 1415 1418 self.browser.getLink('Process data').click() 1416 1419 button = lookup_submit_value( … … 2376 2379 '...You logged in...', self.browser.contents) 2377 2380 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 2378 2407 def test_student_clearance(self): 2379 2408 # Student cant login if their password is not set -
main/waeup.kofa/trunk/src/waeup/kofa/university/tests/test_batching.py
r12868 r13394 351 351 self.browser.getControl('Upload').click() 352 352 self.browser.getLink('Process data').click() 353 self.assertTrue('Portal must be in maintenance mode for data import.' 354 in self.browser.contents) 355 self.browser.getLink("Switch").click() 356 self.assertTrue('Maintenance mode enabled' in self.browser.contents) 357 # Maintenance mode is now set. 358 self.assertEqual( 359 self.app['configuration'].maintmode_enabled_by, 'zope.mgr') 360 self.browser.getLink('Process data').click() 353 361 self.browser.getControl(name="select").click() 354 362 importerselect = self.browser.getControl(name='importer') … … 360 368 self.browser.getControl('Perform import').click() 361 369 self.assertTrue('Successfully processed 1 rows' in self.browser.contents) 370 self.assertTrue('Maintenance mode disabled' in self.browser.contents) 371 # Maintenance mode is really disabled. 372 self.assertEqual( 373 self.app['configuration'].maintmode_enabled_by, None) 362 374 # We import the same file a second time. 363 375 self.browser.open(self.datacenter_path)
Note: See TracChangeset for help on using the changeset viewer.