Example #1
0
    def test_error_when_untrashing_removed_document(self, browser):
        self.login(self.manager, browser=browser)

        data = self.make_path_param(self.empty_document)
        data['_authenticator'] = createToken()

        self.trash_documents(self.empty_document)
        Remover([self.empty_document]).remove()

        # Removed document cannot be untrashed
        browser.open(self.empty_dossier, view="untrashed", data=data)

        self.assertTrue(ITrashed.providedBy(self.empty_document))
        self.assertEquals(
            [u'Untrashing {} is forbidden'.format(self.empty_document.title)],
            error_messages())

        # When restored, document can be untrashed
        api.content.transition(
            obj=self.empty_document,
            transition=self.empty_document.restore_transition)

        self.assertEqual(self.empty_document.active_state,
                         api.content.get_state(self.empty_document))

        browser.open(self.empty_dossier, view="untrashed", data=data)
        self.assertFalse(ITrashed.providedBy(self.empty_document))
Example #2
0
    def test_error_when_untrashing_removed_document(self, browser):
        self.login(self.manager, browser=browser)

        data = self.make_path_param(self.empty_document)
        data['_authenticator'] = createToken()

        self.trash_documents(self.empty_document)
        Remover([self.empty_document]).remove()

        # Removed document cannot be untrashed
        browser.open(self.empty_dossier, view="untrashed", data=data)

        self.assertTrue(ITrashed.providedBy(self.empty_document))
        self.assertEquals(
            [u'Untrashing {} is forbidden'.format(self.empty_document.title)],
            error_messages())

        # When restored, document can be untrashed
        api.content.transition(
            obj=self.empty_document,
            transition=self.empty_document.restore_transition)

        self.assertEqual(self.empty_document.active_state,
                         api.content.get_state(self.empty_document))

        browser.open(self.empty_dossier, view="untrashed", data=data)
        self.assertFalse(ITrashed.providedBy(self.empty_document))
Example #3
0
    def test_trash_items_mark_items_as_trashed(self, browser):
        self.login(self.regular_user, browser=browser)

        data = self.make_path_param(self.subdocument)
        data['_authenticator'] = createToken()
        browser.open(self.dossier, view="trashed", data=data)

        self.assertFalse(ITrashed.providedBy(self.document))
        self.assertFalse(obj2brain(self.document).trashed)

        self.assertTrue(ITrashed.providedBy(self.subdocument))
        self.assertTrue(obj2brain(self.subdocument, unrestricted=True).trashed)
Example #4
0
    def test_trash_items_mark_items_as_trashed(self, browser):
        self.login(self.regular_user, browser=browser)

        data = self.make_path_param(self.subdocument)
        data['_authenticator'] = createToken()
        browser.open(self.dossier, view="trashed", data=data)

        self.assertFalse(ITrashed.providedBy(self.document))
        self.assertFalse(obj2brain(self.document).trashed)

        self.assertTrue(ITrashed.providedBy(self.subdocument))
        self.assertTrue(obj2brain(self.subdocument, unrestricted=True).trashed)
Example #5
0
    def is_revert_allowed(self):
        """Return wheter reverting a the document to a previous version is
        allowed.
        """

        # is it already checked out?
        if self.get_checked_out_by():
            return False

        # does a user hold a lock?
        if self.is_locked():
            return False

        # is it versionable?
        if not self.repository.isVersionable(self.context):
            return False

        if not self.check_permission('Modify portal content'):
            return False

        # is it not trashed
        if ITrashed.providedBy(self.context):
            return False

        return True
Example #6
0
    def is_checkout_allowed(self):
        """Checks whether checkout is allowed for the current user on the
        adapted document.
        """

        # is it already checked out?
        if self.checked_out():
            return False

        # does a user hold a lock?
        if self.is_locked():
            return False

        # is it versionable?
        if not self.repository.isVersionable(self.context):
            return False

        # does the user have the necessary permission?
        if not self.check_permission('opengever.document: Checkout'):
            return False

        if not self.check_permission('Modify portal content'):
            return False

        # is it not trashed
        if ITrashed.providedBy(self.context):
            return False

        return True
Example #7
0
    def is_checkout_allowed(self):
        """Checks whether checkout is allowed for the current user on the
        adapted document.
        """
        # is it already checked out?
        if self.get_checked_out_by():
            return False

        # does a user hold a lock?
        if self.is_locked():
            return False

        # is it versionable?
        if not self.repository.isVersionable(self.context):
            return False

        # does the user have the necessary permission?
        if not self.check_permission('opengever.document: Checkout'):
            return False

        if not self.check_permission('Modify portal content'):
            return False

        # is it not trashed
        if ITrashed.providedBy(self.context):
            return False

        return True
Example #8
0
    def test_trash_items_mark_items_as_trashed(self, browser):
        document_a = create(Builder('document')
                            .within(self.dossier)
                            .titled(u'Dokum\xe4nt A'))
        document_b = create(Builder('document')
                            .within(self.dossier)
                            .titled(u'Dokum\xe4nt B'))

        data = {'paths:list': ['/'.join(document_b.getPhysicalPath())],
                '_authenticator': createToken()}
        browser.login().open(self.dossier, view="trashed", data=data)

        self.assertFalse(ITrashed.providedBy(document_a))
        self.assertFalse(obj2brain(document_a).trashed)

        self.assertTrue(ITrashed.providedBy(document_b))
        self.assertTrue(obj2brain(document_b, unrestricted=True).trashed)
Example #9
0
    def test_trash_items_mark_items_as_trashed(self, browser):
        document_a = create(
            Builder('document').within(self.dossier).titled(u'Dokum\xe4nt A'))
        document_b = create(
            Builder('document').within(self.dossier).titled(u'Dokum\xe4nt B'))

        data = {
            'paths:list': ['/'.join(document_b.getPhysicalPath())],
            '_authenticator': createToken()
        }
        browser.login().open(self.dossier, view="trashed", data=data)

        self.assertFalse(ITrashed.providedBy(document_a))
        self.assertFalse(obj2brain(document_a).trashed)

        self.assertTrue(ITrashed.providedBy(document_b))
        self.assertTrue(obj2brain(document_b, unrestricted=True).trashed)
 def test_untrash_document(self, browser):
     self.login(self.regular_user, browser)
     trasher = ITrashable(self.document)
     trasher.trash()
     browser.open(self.document.absolute_url() + '/@untrash',
                  method='POST', headers={'Accept': 'application/json'})
     self.assertEqual(204, browser.status_code)
     self.assertFalse(ITrashed.providedBy(self.document))
    def test_document_is_trashed_when_ad_hoc_agenda_item_is_deleted(self, browser):
        self.login(self.committee_responsible, browser)
        agenda_item = self.schedule_ad_hoc(self.meeting, u'ad-hoc')
        document = agenda_item.resolve_document()

        browser.open(
            self.meeting,
            view='agenda_items/{}/delete'.format(agenda_item.agenda_item_id),
            send_authenticator=True)

        self.assertTrue(ITrashed.providedBy(document))
    def test_delete_agenda_item_does_not_trash_proposal(self, browser):
        self.login(self.committee_responsible, browser)
        agenda_item = self.schedule_proposal(self.meeting,
                                             self.submitted_word_proposal)
        document = agenda_item.resolve_document()

        browser.open(self.meeting,
                     view='agenda_items/{}/delete'.format(
                         agenda_item.agenda_item_id))

        self.assertFalse(ITrashed.providedBy(document))
    def test_delete_agenda_item_does_not_trash_proposal(self, browser):
        self.login(self.committee_responsible, browser)
        agenda_item = self.schedule_proposal(self.meeting,
                                             self.submitted_word_proposal)
        document = agenda_item.resolve_document()

        browser.open(
            self.meeting,
            view='agenda_items/{}/delete'.format(agenda_item.agenda_item_id))

        self.assertFalse(ITrashed.providedBy(document))
Example #14
0
    def get_size(self):
        """Return the current size of the context in bytes.
        """
        if ITrashed.providedBy(self.context):
            return 0

        primary_field_info = IPrimaryFieldInfo(self.context, None)
        if not primary_field_info or not primary_field_info.value:
            return 0

        return primary_field_info.value.size
Example #15
0
    def test_document_is_trashed_when_ad_hoc_agenda_item_is_deleted(
            self, browser):
        self.login(self.committee_responsible, browser)
        agenda_item = self.schedule_ad_hoc(self.meeting, u'ad-hoc')
        document = agenda_item.resolve_document()

        browser.open(self.meeting,
                     view='agenda_items/{}/delete'.format(
                         agenda_item.agenda_item_id),
                     send_authenticator=True)

        self.assertTrue(ITrashed.providedBy(document))
Example #16
0
    def __init__(self, context, request):
        """Slap a warning onto the overview of a trashed mail.

        We're asserting on the request not having a form as the tabs themselves,
        which get requested by AJAX, rely on a form in the request data. If
        we'd also slap the portal warning onto those requests, the next 'full'
        page view would display them, as the tabs do not consume a portal
        warning.
        """
        super(MailTabbedView, self).__init__(context, request)
        if ITrashed.providedBy(self.context):
            if not self.request.form:
                msg = _(u'warning_trashed', default=u'This mail is trashed.')
                api.portal.show_message(msg, self.request, type='warning')
Example #17
0
    def __init__(self, context, request):
        """Slap a warning onto the overview of a trashed mail.

        We're asserting on the request not having a form as the tabs themselves,
        which get requested by AJAX, rely on a form in the request data. If
        we'd also slap the portal warning onto those requests, the next 'full'
        page view would display them, as the tabs do not consume a portal
        warning.
        """
        super(MailTabbedView, self).__init__(context, request)
        if ITrashed.providedBy(self.context):
            if not self.request.form:
                msg = _(u'warning_trashed', default=u'This mail is trashed.')
                api.portal.show_message(msg, self.request, type='warning')
Example #18
0
    def test_error_when_untrashing_removed_document(self, browser):
        document = create(Builder('document')
                          .within(self.dossier)
                          .trashed()
                          .removed()
                          .titled(u'The document'))

        # Removed document cannot be untrashed
        self.grant('Manager')
        data = {'paths:list': ['/'.join(document.getPhysicalPath())],
                '_authenticator': createToken()}
        browser.login().open(self.dossier, view="untrashed", data=data)
        self.assertTrue(ITrashed.providedBy(document))
        self.assertEquals([u'Untrashing The document is forbidden'],
                          error_messages())

        # When restored, document can be untrashed
        api.content.transition(obj=document,
                               transition=document.restore_transition)
        transaction.commit()
        self.assertEqual(document.active_state, api.content.get_state(document))
        browser.login().open(self.dossier, view="untrashed", data=data)
        self.assertFalse(ITrashed.providedBy(document))
Example #19
0
    def get_excerpts(self, unrestricted=False, include_trashed=False):
        """Return a restricted list of document objects which are excerpts
        of the current proposal.

        Sorted per excerpt title_or_id().
        """
        excerpts = []
        checkPermission = getSecurityManager().checkPermission
        for relation_value in getattr(self, 'excerpts', ()):
            obj = relation_value.to_object
            if unrestricted or checkPermission('View', obj):
                excerpts.append(obj)
        if not include_trashed:
            excerpts = filter(lambda obj: not ITrashed.providedBy(obj),
                              excerpts)
        return sorted(excerpts, key=lambda excerpt: excerpt.title_or_id())
Example #20
0
    def test_delete_agenda_item_does_not_trash_proposal_document(
            self, browser):
        self.login(self.committee_responsible, browser)

        agenda_item = self.schedule_proposal(self.meeting,
                                             self.submitted_proposal)
        document = agenda_item.resolve_document()

        browser.open(self.agenda_item_url(agenda_item, 'delete'))

        self.assertEquals([{
            u'message': u'Agenda Item Successfully deleted',
            u'messageClass': u'info',
            u'messageTitle': u'Information'
        }], browser.json.get('messages'))
        self.assertFalse(ITrashed.providedBy(document))
Example #21
0
    def __call__(self):
        if not is_bumblebee_feature_enabled():
            raise NotFound

        overlay_context = self.context
        version_id = self._get_version_id(overlay_context)
        trashed = ITrashed.providedBy(overlay_context)

        if version_id is not None:
            overlay_context = self._retrieve_version(overlay_context, version_id)
            alsoProvides(self.request, IVersionedContextMarker)

        self.overlay = getMultiAdapter((overlay_context, self.request), IBumblebeeOverlay)
        self.overlay.version_id = version_id
        self.overlay.trashed = trashed

        # we only render an html fragment, no reason to waste time on diazo
        self.request.response.setHeader('X-Theme-Disabled', 'True')
        return super(BumblebeeOverlayBaseView, self).__call__()
Example #22
0
    def get_excerpt_documents(self, unrestricted=False, include_trashed=False):
        """Return a list of excerpt documents.

        If the agenda items has a proposal return the proposals excerpt
        documents. Otherwise return the excerpts stored in the meeting
        dossier.
        """
        if self.has_proposal:
            return self.submitted_proposal.get_excerpts(unrestricted=unrestricted,
                                                        include_trashed=include_trashed)

        checkPermission = getSecurityManager().checkPermission
        documents = [excerpt.resolve_document() for excerpt in self.excerpts]
        documents = filter(None, documents)
        if not unrestricted:
            documents = filter(lambda obj: checkPermission('View', obj), documents)
        if not include_trashed:
            documents = filter(lambda obj: not ITrashed.providedBy(obj), documents)
        return documents
Example #23
0
    def __call__(self):
        if not is_bumblebee_feature_enabled():
            raise NotFound

        overlay_context = self.context
        version_id = self._get_version_id(overlay_context)
        trashed = ITrashed.providedBy(overlay_context)

        if version_id is not None:
            overlay_context = self._retrieve_version(overlay_context,
                                                     version_id)
            alsoProvides(self.request, IVersionedContextMarker)

        self.overlay = getMultiAdapter((overlay_context, self.request),
                                       IBumblebeeOverlay)
        self.overlay.version_id = version_id
        self.overlay.trashed = trashed

        # we only render an html fragment, no reason to waste time on diazo
        self.request.response.setHeader('X-Theme-Disabled', 'True')
        return super(BumblebeeOverlayBaseView, self).__call__()
    def get_excerpt_documents(self, unrestricted=False, include_trashed=False):
        """Return a list of excerpt documents.

        If the agenda items has a proposal return the proposals excerpt
        documents. Otherwise return the excerpts stored in the meeting
        dossier.
        """
        if self.has_proposal:
            return self.submitted_proposal.get_excerpts(
                unrestricted=unrestricted, include_trashed=include_trashed)

        checkPermission = getSecurityManager().checkPermission
        documents = [excerpt.resolve_document() for excerpt in self.excerpts]
        documents = filter(None, documents)
        if not unrestricted:
            documents = filter(lambda obj: checkPermission('View', obj),
                               documents)
        if not include_trashed:
            documents = filter(lambda obj: not ITrashed.providedBy(obj),
                               documents)
        return documents
Example #25
0
    def is_revert_allowed(self):
        """Return wheter reverting a the document to a previous version is
        allowed.
        """
        # is it already checked out?
        if self.get_checked_out_by():
            return False

        # does a user hold a lock?
        if self.is_locked():
            return False

        # is it versionable?
        if not self.repository.isVersionable(self.context):
            return False

        if not self.check_permission('Modify portal content'):
            return False

        # is it not trashed
        if ITrashed.providedBy(self.context):
            return False

        return True
Example #26
0
 def trash_warning(self):
     if ITrashed.providedBy(self.context):
         return document_mf(
             u'warning_trashed',
             default=u'This document is trashed.',
         )
Example #27
0
 def trash_warning(self):
     if ITrashed.providedBy(self.context):
         return mail_mf(
             u'warning_trashed',
             default=u'This mail is trashed.',
         )
 def is_trashed(self):
     return ITrashed.providedBy(self._realobject)
Example #29
0
def trashed_indexer(obj):
    """Indexer for the `trashed` index, this index is used to filter trashed
    documents from catalog search results by default. For that we monkey patch
    the catalog tool's searchResults(), see the patch in opengever.base.monkey.
    """
    return ITrashed.providedBy(obj)
Example #30
0
 def verify_is_trashed(self):
     if not ITrashed.providedBy(self.document):
         self.error_msg.append(
             _(u'msg_is_not_trashed',
               default=u'The document is not trashed.'))
 def is_trashed(self):
     return ITrashed.providedBy(self._realobject)
Example #32
0
 def is_not_trashed(self):
     return bool(not ITrashed.providedBy(self.context))
Example #33
0
 def trash_warning(self):
     if ITrashed.providedBy(self.context):
         return document_mf(
             u'warning_trashed', default=u'This document is trashed.',)
Example #34
0
 def is_not_trashed(self):
     return bool(not ITrashed.providedBy(self.context))
Example #35
0
 def trash_item(self, item):
     self.portal.REQUEST['paths'] = ['/'.join(item.getPhysicalPath())]
     current_url = item.restrictedTraverse('trashed')()
     self.assertTrue(ITrashed.providedBy(item),
             "The item %s should be trashed" % item)
     return current_url
Example #36
0
 def trash_warning(self):
     if ITrashed.providedBy(self.context):
         return mail_mf(
             u'warning_trashed', default=u'This mail is trashed.',)
Example #37
0
 def is_trashed(self):
     return ITrashed.providedBy(self)
Example #38
0
 def test_trash_document(self, browser):
     self.login(self.administrator, browser)
     browser.open(self.document.absolute_url() + '/@trash',
                  method='POST', headers={'Accept': 'application/json'})
     self.assertEqual(204, browser.status_code)
     self.assertTrue(ITrashed.providedBy(self.document))