Allow cancelling of validation requests #22008
This commit is contained in:
parent
a5d4dbfa8c
commit
c496d7f4d1
|
@ -0,0 +1,107 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import z3c.form
|
||||
from Products.CMFCore.utils import getToolByName
|
||||
from collective.task import _
|
||||
from plone import api
|
||||
from plone.supermodel import model
|
||||
from z3c.form import button
|
||||
from z3c.form.browser.checkbox import CheckBoxFieldWidget
|
||||
from z3c.form.field import Fields
|
||||
from z3c.form.interfaces import HIDDEN_MODE
|
||||
from zope import schema
|
||||
from zope.i18nmessageid import MessageFactory
|
||||
from zope.interface import directlyProvides
|
||||
from zope.interface import implements
|
||||
from zope.schema.interfaces import IContextSourceBinder
|
||||
from zope.schema.vocabulary import SimpleVocabulary
|
||||
|
||||
from zope.component import getUtility
|
||||
from zope.intid.interfaces import IIntIds
|
||||
from zc.relation.interfaces import ICatalog
|
||||
from collective.task.content.validation import IValidation
|
||||
|
||||
PMF = MessageFactory('plone')
|
||||
|
||||
|
||||
def validations_vocabulary(context):
|
||||
acl_users = getToolByName(context, 'acl_users')
|
||||
terms = []
|
||||
catalog = api.portal.get_tool('portal_catalog')
|
||||
container_path = '/'.join(context.getPhysicalPath())
|
||||
validations = catalog.searchResults({
|
||||
'path': container_path,
|
||||
'portal_type': 'validation',
|
||||
'review_state': 'todo',
|
||||
'Creator': api.user.get_current().id,
|
||||
})
|
||||
|
||||
for brain in validations:
|
||||
validation = brain.getObject()
|
||||
terms.append(SimpleVocabulary.createTerm(validation.id, str(validation.id), validation.title))
|
||||
|
||||
return SimpleVocabulary(terms)
|
||||
|
||||
|
||||
directlyProvides(validations_vocabulary, IContextSourceBinder)
|
||||
|
||||
|
||||
class IValidations(model.Schema):
|
||||
""""""
|
||||
validations = schema.List(
|
||||
value_type=schema.Choice(
|
||||
source=validations_vocabulary,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
class CancelValidationRequest(z3c.form.form.Form):
|
||||
"""Cancel (delete) one or more validation requests
|
||||
"""
|
||||
|
||||
implements(z3c.form.interfaces.IFieldsForm)
|
||||
fields = Fields(IValidations)
|
||||
fields["validations"].widgetFactory = CheckBoxFieldWidget
|
||||
|
||||
label = _(u'Cancel validations request(s)')
|
||||
description = _(u'Please select validation requests to cancel. The responsibles will be notified by mail.')
|
||||
ignoreContext = True
|
||||
|
||||
@button.buttonAndHandler(_('Apply'), name='apply')
|
||||
def handleApply(self, action):
|
||||
data, errors = self.extractData()
|
||||
validations = data.get('validations')
|
||||
if not validations:
|
||||
return
|
||||
|
||||
refs_catalog = getUtility(ICatalog)
|
||||
intids = getUtility(IIntIds)
|
||||
workflow = api.portal.get_tool('portal_workflow')
|
||||
|
||||
for validation_id in validations:
|
||||
validation = self.context.get(validation_id)
|
||||
if not validation:
|
||||
continue
|
||||
|
||||
# find version linked to the validation
|
||||
validation_intid = intids.getId(validation)
|
||||
relations = list(refs_catalog.findRelations({
|
||||
'from_id': validation_intid,
|
||||
'from_interfaces_flattened': IValidation,
|
||||
}))
|
||||
if not relations:
|
||||
continue
|
||||
version = relations[0].to_object
|
||||
|
||||
self.context.manage_delObjects(validation.id)
|
||||
|
||||
# return the version to its previous state, if possible
|
||||
with api.env.adopt_user('admin'):
|
||||
review_history = workflow.getInfoFor(version, 'review_history')
|
||||
if len(review_history) >= 2 and review_history[-1]['review_state'] == 'pending':
|
||||
return_state = review_history[-2]['review_state']
|
||||
api.content.transition(obj=version,
|
||||
transition='back_to_{}'.format(return_state))
|
||||
version.reindexObject(idxs=['review_state'])
|
||||
|
||||
self.request.response.redirect(self.context.absolute_url())
|
|
@ -34,6 +34,13 @@
|
|||
permission="zope2.View"
|
||||
/>
|
||||
|
||||
<browser:page
|
||||
name="cancel_validation"
|
||||
for="*"
|
||||
class=".cancel_validation.CancelValidationRequest"
|
||||
permission="zope2.View"
|
||||
/>
|
||||
|
||||
<browser:page
|
||||
for="..interfaces.IBaseTask"
|
||||
name="view"
|
||||
|
|
|
@ -42,6 +42,10 @@ msgstr ""
|
|||
msgid "Cancel information(s)"
|
||||
msgstr ""
|
||||
|
||||
#: ../browser/cancel_validation.py:67
|
||||
msgid "Cancel validations request(s)"
|
||||
msgstr ""
|
||||
|
||||
#: ../browser/tasks-portlet.pt:21
|
||||
#: ../interfaces.py:26
|
||||
msgid "Deadline"
|
||||
|
@ -75,6 +79,10 @@ msgstr ""
|
|||
msgid "Please select information notices to cancel. The responsibles will be notified by mail."
|
||||
msgstr ""
|
||||
|
||||
#: ../browser/cancel_validation.py:68
|
||||
msgid "Please select validation requests to cancel. The responsibles will be notified by mail."
|
||||
msgstr ""
|
||||
|
||||
#: ../behaviors.py:14
|
||||
msgid "Target"
|
||||
msgstr ""
|
||||
|
|
|
@ -39,6 +39,10 @@ msgstr "Appliquer"
|
|||
msgid "Cancel attribution(s)"
|
||||
msgstr "Annuler les attributions"
|
||||
|
||||
#: ../browser/cancel_validation.py:67
|
||||
msgid "Cancel validations request(s)"
|
||||
msgstr "Annuler des demandes de validation"
|
||||
|
||||
#: ../browser/tasks-portlet.pt:21
|
||||
#: ../interfaces.py:74
|
||||
msgid "Deadline"
|
||||
|
@ -74,6 +78,10 @@ msgstr "Veuillez sélectionner les attributions à annuler. Les destinaires en s
|
|||
msgid "Please select information notices to cancel. The responsibles will be notified by mail."
|
||||
msgstr "Veuillez sélectionner les notes pour information à supprimer. Les personnes concernées en seront notifiées par mail."
|
||||
|
||||
#: ../browser/cancel_validation.py:68
|
||||
msgid "Please select validation requests to cancel. The responsibles will be notified by mail."
|
||||
msgstr "Veuillez sélectionner les demandes de validation à annuler. Les personnes concernées en seront notifiées par mail."
|
||||
|
||||
#: ../behaviors.py:14
|
||||
msgid "Target"
|
||||
msgstr "Cible"
|
||||
|
|
Reference in New Issue