Changeset 13806 for main/waeup.ikoba/trunk/src/waeup/ikoba
- Timestamp:
- 6 Apr 2016, 10:27:11 (9 years ago)
- Location:
- main/waeup.ikoba/trunk/src/waeup/ikoba
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.ikoba/trunk/src/waeup/ikoba/authentication.py
r13803 r13806 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.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)... -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/authentication.py
r13803 r13806 116 116 customers or the temporary password set by the system. 117 117 118 We additionally check if customer account has been suspended. 119 """ 118 We additionally check if customer account has been suspended 119 or maintenance mode is on. 120 """ 121 try: 122 blocker = grok.getSite()['configuration'].maintmode_enabled_by 123 if blocker and blocker != self.name: 124 return False 125 except (TypeError, KeyError): # in unit tests 126 pass 120 127 if not isinstance(password, basestring): 121 128 return False -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py
r13066 r13806 492 492 self.browser.getControl(name='SUBMIT').click() 493 493 self.browser.getLink('Process data').click() 494 self.browser.getLink("Switch maintenance mode").click() 494 495 button = lookup_submit_value( 495 496 'select', 'customers_zope.mgr.csv', self.browser) -
main/waeup.ikoba/trunk/src/waeup/ikoba/doctests/batchprocessing_browser.txt
r12993 r13806 84 84 85 85 >>> browser.getLink('Process data').click() 86 >>> browser.getLink('Switch maintenance mode').click() 86 87 >>> button = lookup_submit_value( 87 88 ... 'select', 'users_zope.mgr.csv', browser) … … 170 171 171 172 >>> browser.getLink('Process data').click() 173 >>> browser.getLink('Switch maintenance mode').click() 172 174 >>> button = lookup_submit_value( 173 175 ... 'select', 'newusers_zope.mgr.csv', browser) … … 232 234 >>> browser.open('http://localhost/app/datacenter') 233 235 >>> browser.getLink('Process data').click() 236 >>> browser.getLink('Switch maintenance mode').click() 234 237 >>> button = lookup_submit_value( 235 238 ... 'select', 'newusers_zope.mgr.create.pending.csv', browser) -
main/waeup.ikoba/trunk/src/waeup/ikoba/interfaces.py
r13805 r13806 650 650 ) 651 651 652 maintmode_enabled_by = schema.TextLine( 653 title = _(u'Maintenance Mode enabled by'), 654 default = None, 655 required = False, 656 ) 657 652 658 653 659 class IDataCenter(IIkobaObject): -
main/waeup.ikoba/trunk/src/waeup/ikoba/products/tests/test_batching.py
r12490 r13806 33 33 from zope.interface.verify import verifyClass, verifyObject 34 34 from zope.securitypolicy.interfaces import IPrincipalRoleManager 35 from zope.testbrowser.testing import Browser 35 36 36 37 from waeup.ikoba.app import Company … … 64 65 self.workdir = tempfile.mkdtemp() 65 66 app = Company() 67 self.browser = Browser() 68 self.browser.handleErrors = False 69 self.datacenter_path = 'http://localhost/app/datacenter' 66 70 app['datacenter'].setStoragePath(self.dc_root) 67 71 self.getRootFolder()['app'] = app … … 202 206 in failcontent) 203 207 shutil.rmtree(os.path.dirname(fin_file)) 208 209 210 def test_upload_import_reupload(self): 211 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 212 self.browser.open(self.datacenter_path) 213 self.assertEqual(self.browser.headers['Status'], '200 Ok') 214 self.assertEqual(self.browser.url, self.datacenter_path) 215 self.browser.getLink("Upload data").click() 216 file = open(self.csv_file) 217 ctrl = self.browser.getControl(name='uploadfile:file') 218 file_ctrl = ctrl.mech_control 219 file_ctrl.add_file(file, filename='sample_product_data.csv') 220 self.browser.getControl('Upload').click() 221 self.browser.getLink('Process data').click() 222 self.assertTrue('Portal must be in maintenance mode for data import.' 223 in self.browser.contents) 224 self.browser.getLink("Switch").click() 225 self.assertTrue('Maintenance mode enabled' in self.browser.contents) 226 # Maintenance mode is now set. 227 self.assertEqual( 228 self.app['configuration'].maintmode_enabled_by, 'zope.mgr') 229 self.browser.getControl(name="select").click() 230 importerselect = self.browser.getControl(name='importer') 231 importerselect.getControl('Product Processor').selected = True 232 modeselect = self.browser.getControl(name='mode') 233 modeselect.getControl(value='create').selected = True 234 self.browser.getControl('Proceed to step 3').click() 235 self.assertTrue('Header fields OK' in self.browser.contents) 236 self.browser.getControl('Perform import').click() 237 self.assertTrue('Successfully processed 3 rows' in self.browser.contents) 238 self.assertTrue('Maintenance mode disabled' in self.browser.contents) 239 # Maintenance mode is really disabled. 240 self.assertEqual( 241 self.app['configuration'].maintmode_enabled_by, None) 242 # We import the same file a second time. 243 self.browser.open(self.datacenter_path) 244 self.browser.getLink("Upload data").click() 245 file = open(self.csv_file) 246 ctrl = self.browser.getControl(name='uploadfile:file') 247 file_ctrl = ctrl.mech_control 248 file_ctrl.add_file(file, filename='sample_product_data.csv') 249 self.browser.getControl('Upload').click() 250 self.assertTrue( 251 'File with same name was uploaded earlier' in self.browser.contents) 252 return
Note: See TracChangeset for help on using the changeset viewer.