Changeset 13806 for main/waeup.ikoba/trunk/src/waeup/ikoba/browser
- Timestamp:
- 6 Apr 2016, 10:27:11 (9 years ago)
- Location:
- main/waeup.ikoba/trunk/src/waeup/ikoba/browser
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.ikoba/trunk/src/waeup/ikoba/browser/pages.py
r13804 r13806 308 308 309 309 def update(self, SUBMIT=None, camefrom=None): 310 blocker = grok.getSite()['configuration'].maintmode_enabled_by 311 if blocker: 312 self.flash(_('The portal is in maintenance mode ' 313 'and authentication (login) temporarily disabled.'), 314 type='warning') 310 315 self.camefrom = camefrom 311 316 if SUBMIT is not None: … … 335 340 return 336 341 self.redirect(self.camefrom) 342 return 343 # Display second warning message and remind user that 344 # s/he can't login. 345 if blocker: 346 self.flash(_('The portal is in maintenance mode. ' 347 'You can\'t login!'), 348 type='danger') 337 349 return 338 350 # Display appropriate flash message if credentials are correct … … 638 650 639 651 def render(self): 640 #ob_class = self.__implemented__.__name__.replace('waeup. kofa.','')652 #ob_class = self.__implemented__.__name__.replace('waeup.ikoba.','') 641 653 #self.context.logger.info( 642 654 # '%s - skeleton downloaded: %s' % (ob_class, self.filename)) … … 921 933 form_fields = grok.AutoFields(IConfigurationContainer).omit( 922 934 'frontpage_dict') 935 form_fields['maintmode_enabled_by'].for_display = True 923 936 924 937 @action(_('Save'), style='primary') … … 1193 1206 1194 1207 def update(self, filename=None, select=None, cancel=None): 1208 if not grok.getSite()['configuration'].maintmode_enabled_by and \ 1209 not self.request.principal.id == 'admin': 1210 self.flash( 1211 _('Portal must be in maintenance mode for data import.'), 1212 type='warning') 1213 self.redirect(self.url(self.context)) 1214 return 1195 1215 if cancel is not None: 1196 1216 self.redirect(self.url(self.context)) … … 1201 1221 session['import_filename'] = select 1202 1222 self.redirect(self.url(self.context, '@@import2')) 1223 return 1203 1224 1204 1225 class DatacenterImportStep2(IkobaPage): … … 1440 1461 self.redirect(self.url(self.context, '@@import1')) 1441 1462 return 1463 if not grok.getSite()['configuration'].maintmode_enabled_by and \ 1464 not self.request.principal.id == 'admin': 1465 self.flash( 1466 _('File has not been imported. ' 1467 'Portal must be in maintenance mode for data import.'), 1468 type='danger') 1469 self.redirect(self.url(self.context)) 1470 return 1442 1471 session = ISession(self.request)['waeup.ikoba'] 1443 1472 self.filename = session.get('import_filename', None) … … 1476 1505 self.warn_num == 0, self.fullpath, fin_path, pending_path, 1477 1506 self.mode) 1507 # Disable maintenance mode if set. 1508 if grok.getSite()['configuration'].maintmode_enabled_by: 1509 grok.getSite()['configuration'].maintmode_enabled_by = None 1510 self.flash(_('Maintenance mode disabled.')) 1478 1511 1479 1512 if self.warn_num: … … 1659 1692 return result 1660 1693 1694 class SwitchMaintModePage(UtilityView, grok.View): 1695 """Import managers must disable authentication for all other users 1696 before starting an import. This pages switches maintenance mode 1697 on and off. 1698 """ 1699 grok.context(IDataCenter) 1700 grok.name('switchmaintmode') 1701 grok.require('waeup.importData') 1702 1703 def update(self): 1704 ob_class = self.__implemented__.__name__.replace('waeup.ikoba.','') 1705 if grok.getSite()['configuration'].maintmode_enabled_by: 1706 grok.getSite()['configuration'].maintmode_enabled_by = None 1707 self.context.logger.info('%s - maintmode disabled' % ob_class) 1708 self.flash(_('Maintenance mode disabled.')) 1709 self.redirect(self.url(self.context)) 1710 else: 1711 grok.getSite()['configuration'].maintmode_enabled_by = unicode( 1712 self.request.principal.id) 1713 self.context.logger.info('%s - maintmode enabled' % ob_class) 1714 self.flash(_('Maintenance mode enabled.'), type='warning') 1715 self.redirect(self.url(self.context, 'import1')) 1716 return 1717 1718 def render(self): 1719 return 1720 1721 1661 1722 class ChangePasswordRequestPage(IkobaFormPage): 1662 1723 """Captcha'd page for all kind of users to request a password change. -
main/waeup.ikoba/trunk/src/waeup/ikoba/browser/tests/test_browser.py
r13804 r13806 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 … … 215 216 return 216 217 218 def test_maintenance_mode(self): 219 config = grok.getSite()['configuration'] 220 self.app['users'].addUser( 221 'officer', 'secret', title='Bob Officer', email='bob@abcd.ng') 222 self.browser.open('http://localhost/app/login') 223 self.browser.getControl(name="form.login").value = 'officer' 224 self.browser.getControl(name="form.password").value = 'secret' 225 self.browser.getControl("Login").click() 226 # Officer logged in. 227 self.assertMatches('...You logged in...', self.browser.contents) 228 self.assertTrue("Bob Officer" in self.browser.contents) 229 # If maintenance mode is enabled, officer is immediately logged out. 230 config.maintmode_enabled_by = u'any_user' 231 self.assertRaises( 232 Unauthorized, self.browser.open, 'http://localhost/app/customers') 233 self.browser.open('http://localhost/app/login') 234 self.assertMatches( 235 '...The portal is in maintenance mode...', 236 self.browser.contents) 237 # Officers really can't login if maintenance mode is enabled. 238 self.browser.getControl(name="form.login").value = 'officer' 239 self.browser.getControl(name="form.password").value = 'secret' 240 self.browser.getControl("Login").click() 241 # A second warning is raised. 242 self.assertMatches( 243 '...The portal is in maintenance mode. You can\'t login!...', 244 self.browser.contents) 245 # Offficer can login if s/he is the blocker. 246 config.maintmode_enabled_by = u'officer' 247 self.browser.getControl(name="form.login").value = 'officer' 248 self.browser.getControl(name="form.password").value = 'secret' 249 self.browser.getControl("Login").click() 250 self.assertTrue('You logged in' in self.browser.contents) 251 self.assertTrue('Logout' in self.browser.contents) 252 return 253 217 254 def test_sources_overview(self): 218 255 self.browser.open('http://localhost/app/sources') -
main/waeup.ikoba/trunk/src/waeup/ikoba/browser/viewlets.py
r13804 r13806 454 454 text = _('View processed files') 455 455 456 class SwitchMaintMode(ActionButton): 457 grok.context(IDataCenter) 458 grok.require('waeup.importData') 459 #grok.view(DatacenterImportStep1) 460 grok.order(7) 461 icon = 'actionicon_stop.png' 462 target = 'switchmaintmode' 463 text = _('Switch maintenance mode') 464 465 @property 466 def onclick(self): 467 if grok.getSite()['configuration'].maintmode_enabled_by: 468 return 469 return "return window.confirm(%s);" % _( 470 "'In maintenance mode no other user can login, and " 471 "already logged-in users will be automatically logged out. " 472 "You will be the only logged-in user and you can safely start " 473 "any import. Please wait a few seconds before starting the import " 474 "so that all running processes are finished. " 475 "If the import is done, maintenance mode will " 476 "be automatically disabled. \\n\\n" 477 "You really want to enable maintenance mode?'") 478 456 479 # 457 480 # Primary navigation tabs (in upper left navigation bar)...
Note: See TracChangeset for help on using the changeset viewer.