Changeset 6927


Ignore:
Timestamp:
23 Oct 2011, 18:30:07 (13 years ago)
Author:
Henrik Bettermann
Message:

Clearance ACs (and also upcoming school fee ACs) might have been purchased online. Thus we need an AC owner attribute which has to be checked before clearance is being started.

Location:
main/waeup.sirp/trunk/src/waeup/sirp
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/accesscode.py

    r6632 r6927  
    6767        self.batch_serial = batch_serial
    6868        self.random_num = random_num
     69        self.owner = None
    6970        IWorkflowInfo(self).fireTransition('init')
    7071
     
    419420    return code
    420421
    421 def fire_transition(access_code, arg, toward=False, comment=None):
     422def fire_transition(access_code, arg, toward=False, comment=None, owner=None):
    422423    """Fire workflow transition for access code.
    423424
     
    437438    history of the changed access code. You can use this to place
    438439    remarks like for which object the access code was used or similar.
     440
     441    If `owner` is specified, the owner attribute of the access code is checked.
     442    If the owner is different :func:`fire_transition` fails and returns False.
    439443
    440444    :func:`fire_transition` might raise exceptions depending on the
     
    469473        raise KeyError(
    470474            'No site available for looking up accesscodes')
     475    if owner:
     476        ac_owner = getattr(ac, 'owner', None)
     477        if ac_owner and ac_owner != owner:
     478            return False
    471479    info = IWorkflowInfo(ac)
    472480    if toward:
     
    476484    return True
    477485
    478 def invalidate_accesscode(access_code, comment=None):
     486def invalidate_accesscode(access_code, comment=None, owner=None):
    479487    """Invalidate AccessCode denoted by string ``access_code``.
    480488
     
    488496    """
    489497    try:
    490         fire_transition(access_code, 'use', comment=comment)
    491         return True
     498        return fire_transition(access_code, 'use', comment=comment, owner=owner)
    492499    except:
    493500        return False
  • main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/interfaces.py

    r6470 r6927  
    2929    representation = schema.TextLine(
    3030        title = u'Complete title of access code',
     31        )
     32    owner = schema.TextLine(
     33        title = u'Purchaser',
    3134        )
    3235    history = schema.Text(
  • main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py

    r6920 r6927  
    10661066            comment = u"AC invalidated for %s" % self.context.student_id
    10671067            # Here we know that the ac is in state initialized so we do not
    1068             # expect an exception
    1069             invalidate_accesscode(pin,comment)
     1068            # expect an exception, but the owner might be different
     1069            if not invalidate_accesscode(pin,comment,self.context.student_id):
     1070                self.flash('You are not the owner of this access code.')
     1071                return
    10701072            self.context.clr_code = pin
    10711073        IWorkflowInfo(self.context).fireTransition('start_clearance')
  • main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py

    r6922 r6927  
    124124            datetime.now(), 'some_userid', 'CLR', 9.99, 5)
    125125        pins = pin_container[pin_container.keys()[0]].values()
    126         self.clrpins = [x.representation for x in pins]
    127         self.existing_clrpin = self.clrpins[0]
    128         self.existing_clrpin
     126        pins[0].owner = u'Hans Wurst'
     127        self.existing_clrac = pins[0]
     128        self.existing_clrpin = pins[0].representation
    129129        parts = self.existing_clrpin.split('-')[1:]
    130130        self.existing_clrseries, self.existing_clrnumber = parts
     
    584584        self.browser.getControl(name="ac_series").value = self.existing_clrseries
    585585        self.browser.getControl(name="ac_number").value = self.existing_clrnumber
     586        # Owner is Hans Wurst, AC can't be invalidated
     587        self.browser.getControl("Start clearance now").click()
     588        self.assertMatches('...You are not the owner of this access code...',
     589                           self.browser.contents)
     590        # Set the correct owner
     591        self.existing_clrac.owner = self.student_id
    586592        self.browser.getControl("Start clearance now").click()
    587593        self.assertMatches('...Clearance process has been started...',
Note: See TracChangeset for help on using the changeset viewer.