Allow cancelling of information notices #22006
This commit is contained in:
parent
7a7cdae5e6
commit
65959efc69
|
@ -0,0 +1,88 @@
|
|||
|
||||
import z3c.form
|
||||
from Products.CMFCore.utils import getToolByName
|
||||
from collective.task import _
|
||||
from pfwbged.policy.subscribers.document import email_notification_of_canceled_information
|
||||
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
|
||||
|
||||
PMF = MessageFactory('plone')
|
||||
|
||||
|
||||
def responsibles_vocabulary(context):
|
||||
acl_users = getToolByName(context, 'acl_users')
|
||||
terms = []
|
||||
informations = context.listFolderContents(contentFilter={"portal_type": "information"})
|
||||
|
||||
for information in informations:
|
||||
responsible_id = information.responsible[0]
|
||||
user = acl_users.getUserById(responsible_id)
|
||||
responsible_name = user.getProperty('fullname') or responsible_id
|
||||
terms.append(SimpleVocabulary.createTerm(responsible_id, str(responsible_id), responsible_name))
|
||||
|
||||
return SimpleVocabulary(terms)
|
||||
|
||||
|
||||
directlyProvides(responsibles_vocabulary, IContextSourceBinder)
|
||||
|
||||
|
||||
class IInformationRecipients(model.Schema):
|
||||
""""""
|
||||
responsible = schema.List(
|
||||
value_type=schema.Choice(
|
||||
source=responsibles_vocabulary,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
class CancelInformation(z3c.form.form.Form):
|
||||
"""Cancel (delete) one or more information
|
||||
"""
|
||||
|
||||
implements(z3c.form.interfaces.IFieldsForm)
|
||||
fields = Fields(IInformationRecipients)
|
||||
fields["responsible"].widgetFactory = CheckBoxFieldWidget
|
||||
|
||||
label = _(u'Cancel information(s)')
|
||||
description = _(u'Please select information notices to cancel. The responsibles will be notified by mail.')
|
||||
ignoreContext = True
|
||||
|
||||
@button.buttonAndHandler(_('Apply'), name='apply')
|
||||
def handleApply(self, action):
|
||||
data, errors = self.extractData()
|
||||
responsibles = data.get('responsible')
|
||||
if not responsibles:
|
||||
return
|
||||
|
||||
informations = self.context.listFolderContents(contentFilter={
|
||||
'portal_type': 'information',
|
||||
'Creator': api.user.get_current().id,
|
||||
})
|
||||
|
||||
for information in informations:
|
||||
responsible_id = information.responsible[0]
|
||||
if responsible_id in responsibles:
|
||||
local_roles = self.context.get_local_roles_for_userid(responsible_id)
|
||||
leftover_roles = set(local_roles).difference(['Editor'])
|
||||
if leftover_roles:
|
||||
# set leftover roles
|
||||
self.context.manage_setLocalRoles(responsible_id, leftover_roles)
|
||||
else:
|
||||
# delete local roles for user
|
||||
self.context.manage_delLocalRoles([responsible_id])
|
||||
|
||||
email_notification_of_canceled_information(information)
|
||||
|
||||
self.context.manage_delObjects(information.id)
|
||||
|
||||
self.request.response.redirect(self.context.absolute_url())
|
|
@ -27,6 +27,13 @@
|
|||
permission="zope2.View"
|
||||
/>
|
||||
|
||||
<browser:page
|
||||
name="cancel_information"
|
||||
for="*"
|
||||
class=".cancel_information.CancelInformation"
|
||||
permission="zope2.View"
|
||||
/>
|
||||
|
||||
<browser:page
|
||||
for="..interfaces.IBaseTask"
|
||||
name="view"
|
||||
|
|
|
@ -38,6 +38,10 @@ msgstr ""
|
|||
msgid "Cancel attribution(s)"
|
||||
msgstr ""
|
||||
|
||||
#: ../browser/cancel_information.py:56
|
||||
msgid "Cancel information(s)"
|
||||
msgstr ""
|
||||
|
||||
#: ../browser/tasks-portlet.pt:21
|
||||
#: ../interfaces.py:26
|
||||
msgid "Deadline"
|
||||
|
@ -67,6 +71,10 @@ msgstr ""
|
|||
msgid "Please select attributions to cancel. The responsibles will be notified by mail."
|
||||
msgstr ""
|
||||
|
||||
#: ../browser/cancel_information.py:57
|
||||
msgid "Please select information notices to cancel. The responsibles will be notified by mail."
|
||||
msgstr ""
|
||||
|
||||
#: ../behaviors.py:14
|
||||
msgid "Target"
|
||||
msgstr ""
|
||||
|
|
|
@ -70,6 +70,10 @@ msgstr "Demande d'avis"
|
|||
msgid "Please select attributions to cancel. The responsibles will be notified by mail."
|
||||
msgstr "Veuillez sélectionner les attributions à annuler. Les destinaires en seront informés par email."
|
||||
|
||||
#: ../browser/cancel_information.py:57
|
||||
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."
|
||||
|
||||
#: ../behaviors.py:14
|
||||
msgid "Target"
|
||||
msgstr "Cible"
|
||||
|
|
Reference in New Issue