def reply(self): # Disable CSRF protection alsoProvides(self.request, plone.protect.interfaces.IDisableCSRFProtection) trasher = ITrashable(self.context) try: trasher.trash() except TrashError as exc: if exc.message == 'Already trashed': self.request.response.setStatus(400) return { 'error': { 'type': 'Bad Request', 'message': 'Already trashed', } } elif exc.message == 'Document checked out': self.request.response.setStatus(400) return { 'error': { 'type': 'Bad Request', 'message': 'Can not trash a checked-out document', } } self.request.response.setStatus(204) return super(Trash, self).reply()
def after_create(self, obj): if self._trashed: trasher = ITrashable(obj) trasher.trash() obj.update_filename() super(MailBuilder, self).after_create(obj)
def reply(self): # Disable CSRF protection alsoProvides(self.request, plone.protect.interfaces.IDisableCSRFProtection) trasher = ITrashable(self.context) try: trasher.trash() except TrashError as exc: if exc.message == 'Already trashed': self.request.response.setStatus(400) return {'error': { 'type': 'Bad Request', 'message': 'Already trashed', }} elif exc.message == 'Document checked out': self.request.response.setStatus(400) return {'error': { 'type': 'Bad Request', 'message': 'Can not trash a checked-out document', }} self.request.response.setStatus(204) return super(Trash, self).reply()
def test_untrashing_available_for_trashed_document(self, browser): self.login(self.regular_user, browser) trasher = ITrashable(self.document) trasher.trash() expected_file_actions = [ { u'id': u'download_copy', u'title': u'Download copy', u'icon': u'' }, { u'id': u'attach_to_email', u'title': u'Attach to email', u'icon': u'' }, { u'id': u'open_as_pdf', u'title': u'Open as PDF', u'icon': u'' }, { u'id': u'untrash_document', u'title': u'Untrash document', u'icon': u'' }, ] self.assertEqual(expected_file_actions, self.get_file_actions(browser, self.document))
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 after_create(self, obj): if self.checked_out: IAnnotations(obj)[CHECKIN_CHECKOUT_ANNOTATIONS_KEY] = self.checked_out if self._trashed: trasher = ITrashable(obj) trasher.trash() super(DocumentBuilder, self).after_create(obj)
def after_create(self, obj): if self.checked_out: IAnnotations( obj)[CHECKIN_CHECKOUT_ANNOTATIONS_KEY] = self.checked_out if self._trashed: trasher = ITrashable(obj) trasher.trash() super(DocumentBuilder, self).after_create(obj)
def remove(self): assert self.meeting.is_editable() # the agenda_item is ad hoc if it has a document but no proposal if self.has_document and not self.has_proposal: document = self.resolve_document() trasher = ITrashable(document) trasher.trash() session = create_session() if self.proposal: self.proposal.remove_scheduled(self.meeting) session.delete(self) self.meeting.reorder_agenda_items()
def after_create(self, obj): if self._checked_out: IAnnotations(obj)[CHECKIN_CHECKOUT_ANNOTATIONS_KEY] = self._checked_out obj.reindexObject(idxs=['checked_out']) if self._trashed: trasher = ITrashable(obj) trasher.trash() if self._is_shadow: obj.as_shadow_document() obj.reindexObject(idxs=["review_state"]) super(DocumentBuilder, self).after_create(obj)
def after_create(self, obj): if self._checked_out: IAnnotations( obj)[CHECKIN_CHECKOUT_ANNOTATIONS_KEY] = self._checked_out obj.reindexObject(idxs=['checked_out']) if self._trashed: trasher = ITrashable(obj) trasher.trash() if self._is_shadow: obj.as_shadow_document() super(DocumentBuilder, self).after_create(obj)
def __call__(self): paths = self.request.get('paths') if paths: for item in paths: obj = self.context.restrictedTraverse(item) trasher = ITrashable(obj) try: trasher.trash() except TrashError as exc: if exc.message == 'Already trashed': msg = _( u'could not trash the object ${obj}, ' 'it is already trashed', mapping={'obj': obj.Title().decode('utf-8')}) elif exc.message == 'Document checked out': msg = _( u'could not trash the object ${obj}, it is checked' ' out.', mapping={'obj': obj.Title().decode('utf-8')}) elif exc.message == 'The document has been returned as excerpt': msg = _( u'could not trash the object ${obj}, it is an excerpt' ' that has been returned to the proposal.', mapping={'obj': obj.Title().decode('utf-8')}) IStatusMessage(self.request).addStatusMessage( msg, type='error') except Unauthorized: msg = _(u'Trashing ${title} is forbidden', mapping={'title': obj.Title().decode('utf-8')}) IStatusMessage(self.request).addStatusMessage( msg, type='error') else: msg = _(u'the object ${obj} trashed', mapping={'obj': obj.Title().decode('utf-8')}) IStatusMessage(self.request).addStatusMessage( msg, type='info') else: msg = _(u'You have not selected any items.') IStatusMessage(self.request).addStatusMessage( msg, type='error') return self.request.RESPONSE.redirect( '{}#documents'.format(self.context.absolute_url()))
def __call__(self): paths = self.request.get('paths') catalog = getToolByName(self.context, 'portal_catalog') if paths: for item in paths: obj = self.context.restrictedTraverse(item) brains = catalog(path=item) # check that the object isn't already trashed if not brains: msg = _( u'could not trash the object ${obj}, ' 'it is already trashed', mapping={'obj': obj.Title().decode('utf-8')}) IStatusMessage(self.request).addStatusMessage(msg, type='error') continue # check that the document isn't checked_out if brains[0].checked_out: msg = _( u'could not trash the object ${obj}, it is checked out.', mapping={'obj': obj.Title().decode('utf-8')}) IStatusMessage(self.request).addStatusMessage(msg, type='error') continue if not api.user.has_permission( 'opengever.trash: Trash content', obj=obj): msg = _(u'Trashing ${title} is forbidden', mapping={'title': obj.Title().decode('utf-8')}) IStatusMessage(self.request).addStatusMessage(msg, type='error') continue trasher = ITrashable(obj) trasher.trash() msg = _(u'the object ${obj} trashed', mapping={'obj': obj.Title().decode('utf-8')}) IStatusMessage(self.request).addStatusMessage(msg, type='info') else: msg = _(u'You have not selected any items.') IStatusMessage(self.request).addStatusMessage(msg, type='error') return self.request.RESPONSE.redirect('{}#documents'.format( self.context.absolute_url()))
def __call__(self): paths = self.request.get('paths') if paths: for item in paths: obj = self.context.restrictedTraverse(item) trasher = ITrashable(obj) try: trasher.trash() except TrashError as exc: if exc.message == 'Already trashed': msg = _( u'could not trash the object ${obj}, ' 'it is already trashed', mapping={'obj': obj.Title().decode('utf-8')}) elif exc.message == 'Document checked out': msg = _( u'could not trash the object ${obj}, it is checked' ' out.', mapping={'obj': obj.Title().decode('utf-8')}) elif exc.message == 'The document has been returned as excerpt': msg = _( u'could not trash the object ${obj}, it is an excerpt' ' that has been returned to the proposal.', mapping={'obj': obj.Title().decode('utf-8')}) IStatusMessage(self.request).addStatusMessage(msg, type='error') except Unauthorized: msg = _(u'Trashing ${title} is forbidden', mapping={'title': obj.Title().decode('utf-8')}) IStatusMessage(self.request).addStatusMessage(msg, type='error') else: msg = _(u'the object ${obj} trashed', mapping={'obj': obj.Title().decode('utf-8')}) IStatusMessage(self.request).addStatusMessage(msg, type='info') else: msg = _(u'You have not selected any items.') IStatusMessage(self.request).addStatusMessage(msg, type='error') return self.request.RESPONSE.redirect('{}#documents'.format( self.context.absolute_url()))
def delete(self): """Unschedule the current agenda_item. If the agenda_item has no proposal, the agenda_item gets deleted. If there is a proposal related, the proposal is unscheduled. """ if not self.context.model.is_editable(): raise Unauthorized("Editing is not allowed") # the agenda_item is ad hoc if it has a document but no proposal if self.agenda_item.has_document and not self.agenda_item.has_proposal: document = self.agenda_item.resolve_document() trasher = ITrashable(document) trasher.trash() self.agenda_item.remove() return JSONResponse(self.request).info( _(u'agenda_item_deleted', default=u'Agenda Item Successfully deleted')).dump()