def handleCancelCheckout(event): lockable = ILockable(event.object) if lockable.locked(): # unlock working copy if it was auto-locked, or this will fail lockable.clear_locks() lock.unlockContext(event.baseline) event.baseline.reindexObject(idxs=['review_state'])
def handleCancelCheckout(event): lockable = ILockable(event.object) if lockable.locked(): # unlock working copy if it was auto-locked, or this will fail lockable.clear_locks() lock.unlockContext(event.baseline) event.baseline.reindexObject(idxs=['review_state'])
def test_clear_locks_remove_all_locks_on_the_object(self): lockable = ILockable(self.wrapper) lockable.lock() self.assertTrue(lockable.locked()) lockable.clear_locks() self.assertFalse(lockable.locked())
def handle_delete(self, action): title = safe_unicode(self.context.Title()) parent = aq_parent(aq_inner(self.context)) # has the context object been acquired from a place it should not have # been? if self.context.aq_chain == self.context.aq_inner.aq_chain: if self.items_to_delete > 120: tasks.delete_items.delay([IUUID(self.context)]) IStatusMessage(self.request).add( """ You have selected to delete %i items which is a large amount. This action can take a long time to accomplish. We will email you when the content is done being deleted.""" % self.items_to_delete, 'error') else: if self.is_locked: # force unlock before delete... lockable = ILockable(self.context) lockable.clear_locks() parent.manage_delObjects(self.context.getId(), self.request) IStatusMessage(self.request).add( _(u'${title} has been deleted.', mapping={u'title': title})) else: IStatusMessage(self.request).add( _(u'"${title}" has already been deleted', mapping={u'title': title})) self.request.response.redirect(parent.absolute_url())
def action(self, obj): parent = obj.aq_inner.aq_parent lockable = ILockable(obj, None) if lockable and lockable.locked(): lockable.clear_locks() try: parent.manage_delObjects(obj.getId(), self.request) except Unauthorized: self.errors.append( _(u'You are not authorized to delete ${title}.', mapping={u'title': self.objectTitle(self.dest)}))
def do_action(self): if is_locked(self): # force unlock before delete... lockable = ILockable(self.context) lockable.clear_locks() try: self.parent.manage_cutObjects(self.context.getId(), self.request) except CopyError: return self.do_redirect( self.view_url, _(u'${title} is not moveable.', mapping={'title': self.title})) return self.do_redirect( self.view_url, _(u'${title} cut.', mapping={'title': self.title}), 'info')
def delete(self): obj = self.get_by_uid(self.request.get('uid')) lockable = ILockable(obj, None) if lockable and lockable.locked(): lockable.clear_locks() try: api.content.delete(obj) api.portal.show_message( 'Successfully deleted "%s" located at: %s' % (unidecode(obj.Title()), self.get_path(obj)), self.request, type='warning') except LinkIntegrityNotificationException: api.portal.show_message( 'Can not delete "%s" located at: %s because it is still linked.' % (unidecode(obj.Title()), self.get_path(obj)), self.request, type='warning')
def empty(self): for item in [ i for i in self.catalog(trashed=True, object_provides=ITrashed.__identifier__) ]: obj = item.getObject() lockable = ILockable(obj, None) if lockable and lockable.locked(): lockable.clear_locks() try: api.content.delete(obj, check_linkintegrity=False) except LinkIntegrityNotificationException: # could be a folder that has been deleted api.portal.show_message( 'Some content could not be removed because it is still linked ' 'to other content on the site.', self.request, type='warning') api.portal.show_message('Trash emptied', self.request, type='warning')
def empty(site): setSite(site) catalog = api.portal.get_tool('portal_catalog') end = DateTime() - 30 query = dict(modified={ 'query': (DateTime('1999/09/09'), end), 'range': 'min:max' }, trashed=True) count = 0 for brain in catalog(**query): count += 1 ob = brain.getObject() lockable = ILockable(ob, None) if lockable and lockable.locked(): lockable.clear_locks() try: api.content.delete(ob) except LinkIntegrityNotificationException: # quietly ignore for now pass if count % 20 == 0: transaction.commit() transaction.commit()
def lockContext(context): lockable = ILockable(context) # Be quite forceful - we assume that we won't have gotten here unless # we had rights to do this. lockable.clear_locks() lockable.lock(ITERATE_LOCK, children=True)
def __call__(self): self.errors = [] self.protect() context = aq_inner(self.context) catalog = getToolByName(context, 'portal_catalog') mtool = getToolByName(context, 'portal_membership') missing = [] for key in self.request.form.keys(): if not key.startswith('UID_'): continue index = key.split('_')[-1] uid = self.request.form[key] brains = catalog(UID=uid) if len(brains) == 0: missing.append(uid) continue obj = brains[0].getObject() title = self.objectTitle(obj) if not mtool.checkPermission('Copy or Move', obj): self.errors( _(u'Permission denied to rename ${title}.', mapping={u'title': title})) continue sp = transaction.savepoint(optimistic=True) newid = self.request.form['newid_' + index].encode('utf8') newtitle = self.request.form['newtitle_' + index] lockable = ILockable(obj, None) if lockable: lockable.clear_locks() try: obid = obj.getId() title = obj.Title() change_title = newtitle and title != newtitle if change_title: getSecurityManager().validate(obj, obj, 'setTitle', obj.setTitle) obj.setTitle(newtitle) notify(ObjectModifiedEvent(obj)) if newid and obid != newid: parent = aq_parent(aq_inner(obj)) # Make sure newid is safe newid = INameChooser(parent).chooseName(newid, obj) # Update the default_page on the parent. context_state = getMultiAdapter((obj, self.request), name='plone_context_state') if context_state.is_default_page(): parent.setDefaultPage(newid) parent.manage_renameObjects((obid, ), (newid, )) elif change_title: # the rename will have already triggered a reindex obj.reindexObject() except ConflictError: raise except Exception as e: sp.rollback() logger.error(u'Error renaming "{title}": "{exception}"'.format( title=title.decode('utf8'), exception=e)) self.errors.append( _(u'Error renaming ${title}', mapping={'title': title.decode('utf8')})) return self.message(missing)
def handleCheckin(event): lockable = ILockable(event.object) if lockable.locked(): # unlock working copy if it was auto-locked, or this will fail lockable.clear_locks()
def unlock_before_transition(ob, event): # Force unlock to always allow workflow transitions lockable = ILockable(ob, None) if lockable is not None: lockable.clear_locks()
def lockContext(context): lockable = ILockable(context) # Be quite forceful - we assume that we won't have gotten here unless # we had rights to do this. lockable.clear_locks() lockable.lock(ITERATE_LOCK, children=True)
def handleCheckin(event): lockable = ILockable(event.object) if lockable.locked(): # unlock working copy if it was auto-locked, or this will fail lockable.clear_locks()
def handle_rename(self, action): lockable = ILockable(self.context) if lockable: lockable.clear_locks() return super(RenameForm, self).handle_rename(self, action)