Changeset 13803


Ignore:
Timestamp:
6 Apr 2016, 05:04:26 (9 years ago)
Author:
Henrik Bettermann
Message:

Enable temporary suspension of officer accounts. Plugins must be
updated after restart.

See r12926.

Location:
main/waeup.ikoba/trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/CHANGES.txt

    r13802 r13803  
    440.2.dev0 (unreleased)
    55=====================
     6
     7* Enable temporary suspension of officer accounts. Plugins must be
     8  updated after restart.
    69
    710* Do only allow one running export job.
  • main/waeup.ikoba/trunk/src/waeup/ikoba/authentication.py

    r13801 r13803  
    210210        self.phone = phone
    211211        self.public_name = public_name
     212        self.suspended = False
    212213        self.setPassword(password)
    213214        self.setSiteRolesForPrincipal(roles)
     
    226227        if not self.password:
    227228            # unset/empty passwords do never match
     229            return False
     230        if self.suspended == True:
    228231            return False
    229232        passwordmanager = getUtility(IPasswordManager, 'SSHA')
  • main/waeup.ikoba/trunk/src/waeup/ikoba/browser/pages.py

    r13802 r13803  
    336336                                   type='warning')
    337337                    return
     338            # Display appropriate flash message if credentials are correct
     339            # but officer has been deactivated.
     340            login = self.request.form['form.login']
     341            if login in grok.getSite()['users']:
     342                user = grok.getSite()['users'][login]
     343                password = self.request.form['form.password']
     344                passwordmanager = getUtility(IPasswordManager, 'SSHA')
     345                if user.password is not None and \
     346                    passwordmanager.checkPassword(user.password, password):
     347                    self.flash(_('Your user name and password are correct '
     348                                 'but yor account has been temporarily '
     349                                 'deactivated.'),
     350                               type='warning')
     351                    return
    338352            self.flash(_('You entered invalid credentials.'), type='danger')
    339353            return
  • main/waeup.ikoba/trunk/src/waeup/ikoba/browser/templates/usereditformpage.pt

    r11949 r13803  
     1<p class="alert alert-danger"  i18n:domain="waeup.kofa"
     2   i18n:translate="officer_suspended_warning"
     3   tal:condition="python: getattr(context, 'suspended', False)">
     4  <strong>ATTENTION:</strong>
     5  This account has been suspended. The officer can't login.
     6</p>
     7
    18<form action="." tal:attributes="action request/URL" method="post"
    29      i18n:domain="waeup.ikoba" enctype="multipart/form-data"
  • main/waeup.ikoba/trunk/src/waeup/ikoba/browser/templates/userscontainerpage.pt

    r11949 r13803  
    1212    <tr tal:repeat="account context/values">
    1313      <td tal:content="account/name">USERNAME</td>
    14       <td tal:content="account/title">TITLE</td>
     14      <td>
     15        <span tal:content="account/title">TITLE</span>
     16        <span style="color:red" tal:condition="account/suspended">(suspended)</span>
     17      </td>
    1518      <td nowrap tal:content="structure python:view.getSiteRoles(account)">SITE ROLES</td>
    1619      <td tal:content="structure python:view.getLocalRoles(account)">LOCAL ROLES</td>
  • main/waeup.ikoba/trunk/src/waeup/ikoba/browser/tests/test_browser.py

    r13802 r13803  
    3030from waeup.ikoba.testing import FunctionalLayer, FunctionalTestCase
    3131from waeup.ikoba.app import Company
    32 from waeup.ikoba.interfaces import IJobManager
     32from waeup.ikoba.interfaces import IJobManager, IUserAccount
    3333from waeup.ikoba.tests.test_async import FunctionalAsyncTestCase
    3434
     
    160160        return
    161161
     162
     163class SupplementaryBrowserTests(CompanySetup):
     164    # These are additional tests to browser.txt
     165
     166    def test_suspended_officer(self):
     167        self.app['users'].addUser(
     168            'officer', 'secret', title='Bob Officer', email='aa@aa.ng')
     169        # Officer can't login if their password is not set
     170        self.app['users']['officer'].password = None
     171        self.browser.open('http://localhost/app/login')
     172        self.browser.getControl(name="form.login").value = 'officer'
     173        self.browser.getControl(name="form.password").value = 'secret'
     174        self.browser.getControl("Login").click()
     175        self.assertTrue(
     176            'You entered invalid credentials.' in self.browser.contents)
     177        # We set the password again
     178        IUserAccount(
     179            self.app['users']['officer']).setPassword('secret')
     180        # Officers can't login if their account is suspended/deactivated
     181        self.app['users']['officer'].suspended = True
     182        self.browser.open('http://localhost/app/login')
     183        self.browser.getControl(name="form.login").value = 'officer'
     184        self.browser.getControl(name="form.password").value = 'secret'
     185        self.browser.getControl("Login").click()
     186        self.assertMatches(
     187            '...but yor account has been temporarily deactivated...',
     188            self.browser.contents)
     189        self.assertFalse("Bob Officer" in self.browser.contents)
     190        self.app['users']['officer'].suspended = False
     191        self.browser.open('http://localhost/app/login')
     192        self.browser.getControl(name="form.login").value = 'officer'
     193        self.browser.getControl(name="form.password").value = 'secret'
     194        self.browser.getControl("Login").click()
     195        self.assertMatches(
     196            '...You logged in...', self.browser.contents)
     197        self.assertTrue("Bob Officer" in self.browser.contents)
     198        self.browser.getLink("Logout").click()
     199        # Suspended accounts are marked
     200        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     201        self.browser.open('http://localhost/app/users')
     202        self.assertFalse('(suspended)' in self.browser.contents)
     203        self.app['users']['officer'].suspended = True
     204        self.browser.open('http://localhost/app/users')
     205        self.assertTrue(
     206            '<span style="color:red">(suspended)</span>'
     207            in self.browser.contents)
     208        self.browser.open('http://localhost/app/users/officer')
     209        self.assertTrue(
     210            'This account has been suspended.' in self.browser.contents)
     211        self.app['users']['officer'].suspended = False
     212        self.browser.open('http://localhost/app/users/officer')
     213        self.assertFalse(
     214            'This account has been suspended.' in self.browser.contents)
     215        return
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/authentication.py

    r12809 r13803  
    7373        return self.title
    7474
     75    def suspended(self):
     76        return self.context.suspended
     77
    7578    @property
    7679    def failed_logins(self):
  • main/waeup.ikoba/trunk/src/waeup/ikoba/interfaces.py

    r13802 r13803  
    482482    """
    483483
    484     failed_logins = Attribute("""FailedLoginInfo for this account""")
     484    failed_logins = Attribute('FailedLoginInfo for this account')
    485485
    486486    name = schema.TextLine(
    487487        title = _(u'User Id'),
    488         description = u'Login name of user',
     488        description = _(u'Login name of user'),
    489489        required = True,)
    490490
     
    495495    public_name = schema.TextLine(
    496496        title = _(u'Public Name'),
    497         description = u"Substitute for officer's real name "
    498                        "in object histories.",
     497        description = _(u"Substitute for officer's real name "
     498                       "in student object histories."),
    499499        required = False,)
    500500
     
    522522        )
    523523
     524    suspended = schema.Bool(
     525        title = _(u'Account suspended'),
     526        description = _(u'If set, the account is immediately blocked.'),
     527        default = False,
     528        required = False,
     529        )
    524530
    525531
Note: See TracChangeset for help on using the changeset viewer.