Changeset 12356


Ignore:
Timestamp:
1 Jan 2015, 07:44:44 (10 years ago)
Author:
Henrik Bettermann
Message:

Do not allow to add documents if customer has not yet been approved.

Rename pagetemplate.

Location:
main/waeup.ikoba/trunk/src/waeup/ikoba/customers
Files:
3 edited
1 moved

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/browser.py

    r12353 r12356  
    863863    grok.context(ICustomerDocumentsContainer)
    864864    grok.name('adddoc')
    865     grok.template('documentaddform')
     865    grok.template('documentaddpage')
    866866    grok.require('waeup.editCustomerDocuments')
    867867    label = _('Add document')
     
    874874        doctypes = getUtility(ICustomersUtils).SELECTABLE_DOCTYPES_DICT
    875875        return sorted(doctypes.items())
     876
     877    @property
     878    def edit_documents_allowed(self):
     879        right_customer_state = self.context.customer.state in getUtility(
     880            ICustomersUtils).DOCMANAGE_CUSTOMER_STATES
     881        if isCustomer(self.request.principal) and not right_customer_state:
     882            return False
     883        return True
     884
     885    def update(self):
     886        if not self.edit_documents_allowed:
     887            emit_lock_message(self)
     888            return
     889        return super(DocumentAddFormPage, self).update()
    876890
    877891    @action(_('Add document'), style='primary')
     
    889903        self.context.writeLogMessage(
    890904            self,'added: %s %s' % (doctype, document.document_id))
    891         self.redirect(self.url(self.context))
     905        isCustomer = getattr(
     906            self.request.principal, 'user_type', None) == 'customer'
     907        if isCustomer:
     908            self.redirect(self.url(document, 'edit') + '#tab2')
     909        else:
     910            self.redirect(self.url(document, 'manage') + '#tab2')
    892911        return
    893912
     
    12071226
    12081227
    1209 class ContractAddPage(IkobaAddFormPage):
     1228class ContractAddFormPage(IkobaAddFormPage):
    12101229    """ Page to add an contract
    12111230
     
    12341253            emit_lock_message(self)
    12351254            return
    1236         return super(ContractAddPage, self).update()
     1255        return super(ContractAddFormPage, self).update()
    12371256
    12381257    @property
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/documents.py

    r12352 r12356  
    6565    """This is a customer document baseclass.
    6666    """
    67     grok.implements(ICustomerDocument, ICustomerNavigation)
    68     grok.provides(ICustomerDocument)
    6967    grok.baseclass()
    7068
     
    189187    """This is a sample customer document.
    190188    """
     189
     190    grok.implements(ICustomerDocument, ICustomerNavigation)
     191    grok.provides(ICustomerDocument)
    191192
    192193    # Ikoba can store any number of files per Document object.
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py

    r12353 r12356  
    931931        self.browser.getLink("Documents").click()
    932932        self.browser.getControl("Add document").click()
     933        self.assertTrue('The requested form is locked' in self.browser.contents)
     934        # Customer is in wrong state
     935        IWorkflowState(self.customer).setState(APPROVED)
     936        self.browser.getControl("Add document").click()
    933937        self.browser.getControl(name="doctype").value = ['CustomerSampleDocument']
    934938        self.browser.getControl(name="form.title").value = 'My Sample Document'
     
    937941        docid = [i for i in self.customer['documents'].keys() if len(i) > 10][0]
    938942        document = self.customer['documents'][docid]
    939 
    940         # Document can be edited ...
    941         self.browser.getLink(docid[:6]).click()
    942         self.browser.open(self.documents_path + '/' + docid + '/edit')
    943         #self.browser.getLink("Edit").click()
    944         self.assertTrue('The requested form is locked' in self.browser.contents)
    945         # Customer is in wrong state
    946         IWorkflowState(self.customer).setState(APPROVED)
    947         self.browser.open(self.documents_path + '/' + docid + '/edit')
    948943        self.browser.getControl(name="form.title").value = 'My second doc'
    949944        self.browser.getControl("Save").click()
     
    953948        self.assertEqual(
    954949            self.browser.url, self.documents_path + '/%s/index' % docid)
    955         # Costumer can upload a document.
     950        # Customer can upload a document.
    956951        self.browser.getLink("Edit").click()
    957952        ctrl = self.browser.getControl(name='samplescaneditupload')
     
    964959            'href="http://localhost/app/customers/K1000000/documents/%s/sample"'
    965960            % docid in self.browser.contents)
    966         # Costumer can submit the form. The form is also saved.
     961        # Customer can submit the form. The form is also saved.
    967962        self.browser.getControl(name="form.title").value = 'My third doc'
    968963        self.browser.getControl("Final Submit").click()
     
    12171212            in logcontent)
    12181213        self.assertTrue(
    1219             'INFO - zope.mgr - customers.browser.ContractAddPage '
     1214            'INFO - zope.mgr - customers.browser.ContractAddFormPage '
    12201215            '- K1000000 - added: Sample Contract %s'
    12211216            % contract.contract_id in logcontent)
Note: See TracChangeset for help on using the changeset viewer.