Changeset 13394 for main/waeup.kofa/trunk/src/waeup/kofa/browser
- Timestamp:
- 6 Nov 2015, 05:43:37 (9 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/browser
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
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)...
Note: See TracChangeset for help on using the changeset viewer.