[gen] Removed the obsolete mail notification system.
This commit is contained in:
parent
cc776dc2f0
commit
50544aaecf
|
@ -18,7 +18,6 @@ import types, string
|
|||
from group import Group
|
||||
from appy.px import Px
|
||||
from appy.gen.utils import User
|
||||
from appy.gen.mail import sendNotification
|
||||
|
||||
# Default Appy permissions -----------------------------------------------------
|
||||
r, w, d = ('read', 'write', 'delete')
|
||||
|
@ -192,8 +191,8 @@ class State:
|
|||
# ------------------------------------------------------------------------------
|
||||
class Transition:
|
||||
'''Represents a workflow transition.'''
|
||||
def __init__(self, states, condition=True, action=None, notify=None,
|
||||
show=True, confirm=False, group=None, icon=None):
|
||||
def __init__(self, states, condition=True, action=None, show=True,
|
||||
confirm=False, group=None, icon=None):
|
||||
# In its simpler form, "states" is a list of 2 states:
|
||||
# (fromState, toState). But it can also be a list of several
|
||||
# (fromState, toState) sub-lists. This way, you may define only 1
|
||||
|
@ -205,8 +204,6 @@ class Transition:
|
|||
# The condition specifies the name of a role.
|
||||
self.condition = Role(condition)
|
||||
self.action = action
|
||||
self.notify = notify # If not None, it is a method telling who must be
|
||||
# notified by email after the transition has been executed.
|
||||
self.show = show # If False, the end user will not be able to trigger
|
||||
# the transition. It will only be possible by code.
|
||||
self.confirm = confirm # If True, a confirm popup will show up.
|
||||
|
@ -367,13 +364,11 @@ class Transition:
|
|||
wf = wf.__instance__ # We need the prototypical instance here.
|
||||
wf.onTrigger(obj, name)
|
||||
|
||||
def trigger(self, name, obj, wf, comment, doAction=True, doNotify=True,
|
||||
doHistory=True, doSay=True, reindex=True, noSecurity=False):
|
||||
def trigger(self, name, obj, wf, comment, doAction=True, doHistory=True,
|
||||
doSay=True, reindex=True, noSecurity=False):
|
||||
'''This method triggers this transition (named p_name) on p_obj. If
|
||||
p_doAction is False, the action that must normally be executed after
|
||||
the transition has been triggered will not be executed. If p_doNotify
|
||||
is False, the email notifications that must normally be launched
|
||||
after the transition has been triggered will not be launched. If
|
||||
the transition has been triggered will not be executed. If
|
||||
p_doHistory is False, there will be no trace from this transition
|
||||
triggering in the workflow history. If p_doSay is False, we consider
|
||||
the transition is triggered programmatically, and no message is
|
||||
|
@ -418,10 +413,6 @@ class Transition:
|
|||
# Reindex the object if required. Not only security-related indexes
|
||||
# (Allowed, State) need to be updated here.
|
||||
if reindex and not obj.isTemporary(): obj.reindex()
|
||||
# Send notifications if needed
|
||||
mail = obj.getTool().getProductConfig(True).mail
|
||||
if doNotify and self.notify and mail and mail.enabled:
|
||||
sendNotification(obj.appy(), self, name, wf)
|
||||
# Return a message to the user if needed
|
||||
if not doSay or (name == '_init_'): return
|
||||
if not msg: msg = obj.translate('object_saved')
|
||||
|
|
|
@ -788,12 +788,4 @@ class ZopeGenerator(Generator):
|
|||
# We need to generate a label for the message that will be shown
|
||||
# in the confirm popup.
|
||||
self.i18n('%s_%s_confirm'%(wfName, name),po.CONFIRM, nice=False)
|
||||
if transition.notify:
|
||||
# Appy will send a mail when this transition is triggered.
|
||||
# So we need 2 i18n labels: one for the mail subject and one for
|
||||
# the mail body.
|
||||
self.i18n('%s_%s_mail_subject' % (wfName, name),
|
||||
po.EMAIL_SUBJECT, nice=False)
|
||||
self.i18n('%s_%s_mail_body' % (wfName, name),
|
||||
po.EMAIL_BODY, nice=False)
|
||||
# ------------------------------------------------------------------------------
|
||||
|
|
44
gen/mail.py
44
gen/mail.py
|
@ -116,48 +116,4 @@ def sendMail(config, to, subject, body, attachments=None, log=None):
|
|||
if log: log('mail sending failed: %s' % str(e), type='error')
|
||||
except socket.error, se:
|
||||
if log: log('mail sending failed: %s' % str(se), type='error')
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
def sendNotification(obj, transition, transitionName, workflow):
|
||||
'''Sends mail about p_transition named p_transitionName, that has been
|
||||
triggered on p_obj that is controlled by p_workflow.'''
|
||||
from appy.gen.descriptors import WorkflowDescriptor
|
||||
wfName = WorkflowDescriptor.getWorkflowName(workflow.__class__)
|
||||
zopeObj = obj.o
|
||||
tool = zopeObj.getTool()
|
||||
mailInfo = transition.notify(workflow, obj)
|
||||
if not mailInfo[0]: return # Send a mail to nobody.
|
||||
# mailInfo may be one of the following:
|
||||
# (to,)
|
||||
# (to, cc)
|
||||
# (to, mailSubject, mailBody)
|
||||
# (to, cc, mailSubject, mailBody)
|
||||
# "to" and "cc" maybe simple strings (one simple string = one email
|
||||
# address or one role) or sequences of strings.
|
||||
# Determine mail subject and body.
|
||||
if len(mailInfo) <= 2:
|
||||
# The user didn't mention mail body and subject. We will use those
|
||||
# defined from i18n labels.
|
||||
wfHistory = zopeObj.getHistory()
|
||||
labelPrefix = '%s_%s' % (wfName, transitionName)
|
||||
tName = obj.translate(labelPrefix)
|
||||
keys = {'siteUrl': tool.getPath('/').absolute_url(),
|
||||
'siteTitle': tool.getAppName(),
|
||||
'objectUrl': zopeObj.absolute_url(),
|
||||
'objectTitle': zopeObj.Title(),
|
||||
'transitionName': tName,
|
||||
'transitionComment': wfHistory[0]['comments']}
|
||||
mailSubject = obj.translate(labelPrefix + '_mail_subject', keys)
|
||||
mailBody = obj.translate(labelPrefix + '_mail_body', keys)
|
||||
else:
|
||||
mailSubject = mailInfo[-1]
|
||||
mailBody = mailInfo[-2]
|
||||
# Determine "to" and "cc".
|
||||
to = mailInfo[0]
|
||||
cc = []
|
||||
if (len(mailInfo) in (2,4)) and mailInfo[1]: cc = mailInfo[1]
|
||||
if type(to) not in sequenceTypes: to = [to]
|
||||
if type(cc) not in sequenceTypes: cc = [cc]
|
||||
# Send the mail
|
||||
sendMail(tool.appy(), to, mailSubject, mailBody)
|
||||
# ------------------------------------------------------------------------------
|
||||
|
|
|
@ -23,9 +23,6 @@ fallbacks = {'en': 'en-us en-ca',
|
|||
|
||||
# Default values for i18n labels whose ids are not fixed.
|
||||
CONFIG = "Configuration panel for product '%s'"
|
||||
EMAIL_SUBJECT = '${siteTitle} - Action \\"${transitionName}\\" has been ' \
|
||||
'performed on element entitled \\"${objectTitle}\\".'
|
||||
EMAIL_BODY = 'You can consult this element at ${objectUrl}.'
|
||||
CONFIRM = 'Are you sure ?'
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
|
|
@ -939,7 +939,7 @@ class AbstractWrapper(object):
|
|||
return self.o.translate(label, mapping, domain, language=language,
|
||||
format=format)
|
||||
|
||||
def do(self, name, comment='', doAction=True, doNotify=True, doHistory=True,
|
||||
def do(self, name, comment='', doAction=True, doHistory=True,
|
||||
noSecurity=False):
|
||||
'''Triggers on p_self a transition named p_name programmatically.'''
|
||||
o = self.o
|
||||
|
@ -948,7 +948,7 @@ class AbstractWrapper(object):
|
|||
if not tr or (tr.__class__.__name__ != 'Transition'):
|
||||
raise Exception('Transition "%s" not found.' % name)
|
||||
return tr.trigger(name, o, wf, comment, doAction=doAction,
|
||||
doNotify=doNotify, doHistory=doHistory, doSay=False,
|
||||
doHistory=doHistory, doSay=False,
|
||||
noSecurity=noSecurity)
|
||||
|
||||
def log(self, message, type='info'): return self.o.log(message, type)
|
||||
|
|
Loading…
Reference in a new issue