Changeset 12240


Ignore:
Timestamp:
15 Dec 2014, 07:44:01 (10 years ago)
Author:
Henrik Bettermann
Message:

Protect pdf download if document has not been published.

Add workflow transition 'retract'.

Location:
main/waeup.ikoba/trunk/src/waeup/ikoba/documents
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/fileviewlets.py

    r12225 r12240  
    1919import grok
    2020from waeup.ikoba.interfaces import MessageFactory as _
    21 
     21from waeup.ikoba.interfaces import PUBLISHED
     22from waeup.ikoba.browser.layout import UtilityView
    2223from waeup.ikoba.browser.fileviewlets import (
    2324    FileDisplay, FileUpload, Image)
     
    5556
    5657
    57 class PDFScanImage(Image):
     58class PDFScanImage(Image, UtilityView):
    5859    """Scan document.
    5960    """
     
    6465    download_name = u'sample.pdf'
    6566
     67    def render(self):
     68        if self.context.state != PUBLISHED:
     69            self.flash(_('The document requested has not yet been published.'),
     70                type="warning")
     71            self.redirect(self.url(self.context))
     72            return
     73        return super(PDFScanImage, self).render()
     74
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/tests/test_browser.py

    r12239 r12240  
    3737from waeup.ikoba.app import Company
    3838from waeup.ikoba.interfaces import (
    39     IUserAccount, IJobManager, APPROVED, SUBMITTED,
     39    IUserAccount, IJobManager, APPROVED, SUBMITTED, PUBLISHED,
    4040    IFileStoreNameChooser, IExtFileStore, IFileStoreHandler)
    4141from waeup.ikoba.imagestorage import (
     
    151151            'href="http://localhost/app/documents/d101/sample.pdf">PDF File</a>'
    152152            in self.browser.contents)
    153         # Browsing the link shows a real pdf
    154         self.browser.open('sample.pdf')
     153        # Browsing the link shows a real pdf only if the document
     154        # has been published
     155        self.browser.getLink("PDF File").click()
     156        self.assertTrue(
     157            'The document requested has not yet been published'
     158            in self.browser.contents)
     159        IWorkflowState(document).setState(PUBLISHED)
     160        self.browser.getLink("sample.pdf").click()
    155161        self.assertEqual(
    156162            self.browser.headers['content-type'], 'application/pdf')
    157163
    158164        # Transitions can be performed
     165        self.assertEqual(document.state, 'published')
    159166        self.browser.open(self.container_path + '/d101')
    160167        self.browser.getLink("Transition").click()
    161         self.browser.getControl(name="transition").value = ['publish']
     168        self.browser.getControl(name="transition").value = ['retract']
    162169        self.browser.getControl("Save").click()
    163         self.assertEqual(document.state, 'published')
     170        self.assertEqual(document.state, 'created')
    164171
    165172        # Documents can be removed
     
    189196            % document.document_id in logcontent)
    190197        self.assertTrue(
    191             'INFO - zope.mgr - %s - Document published' % document.document_id
     198            'INFO - zope.mgr - %s - Document retracted' % document.document_id
    192199            in logcontent)
    193200        self.assertTrue(
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/workflow.py

    r12222 r12240  
    4848        msg = _('Document published'),
    4949        destination = PUBLISHED),
     50
     51    Transition(
     52        transition_id = 'retract',
     53        title = _('Retract documet'),
     54        source = PUBLISHED,
     55        condition = NullCondition,
     56        msg = _('Document retracted'),
     57        destination = CREATED),
    5058    )
    5159
Note: See TracChangeset for help on using the changeset viewer.