Project owners can now enter multiple email addresses for each notification type.

Each email must be separated by a comma from the other. (Based on a patch from
Pierre Marechal, fixes issue 372).
This commit is contained in:
Thomas Keller 2010-12-06 00:11:59 +01:00
parent 784c9718eb
commit 51c42a65c5
8 changed files with 163 additions and 96 deletions

View File

@ -309,13 +309,16 @@ class IDF_Commit extends Pluf_Model
); );
$tmpl = new Pluf_Template('idf/source/commit-created-email.txt'); $tmpl = new Pluf_Template('idf/source/commit-created-email.txt');
$text_email = $tmpl->render($context); $text_email = $tmpl->render($context);
$addresses = explode(',', $conf->getVal('source_notification_email'));
foreach ($addresses as $address) {
$email = new Pluf_Mail(Pluf::f('from_email'), $email = new Pluf_Mail(Pluf::f('from_email'),
$conf->getVal('source_notification_email'), $address,
sprintf(__('New Commit %s - %s (%s)'), sprintf(__('New Commit %s - %s (%s)'),
$this->scm_id, $this->summary, $this->scm_id, $this->summary,
$this->get_project()->shortname)); $this->get_project()->shortname));
$email->addTextMessage($text_email); $email->addTextMessage($text_email);
$email->sendMail(); $email->sendMail();
}
Pluf_Translation::loadSetLocale($current_locale); Pluf_Translation::loadSetLocale($current_locale);
} }
} }

View File

@ -0,0 +1,51 @@
<?php
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
# ***** BEGIN LICENSE BLOCK *****
# This file is part of InDefero, an open source project management application.
# Copyright (C) 2010 Céondo Ltd and contributors.
#
# Plume Framework is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Plume Framework is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# ***** END LICENSE BLOCK ***** */
/**
* Similar to Pluf_Form_Field_Email, this form field validates one or more
* email addresses separated by a comma
*/
class IDF_Form_Field_EmailList extends Pluf_Form_Field
{
public $widget = 'Pluf_Form_Widget_TextInput';
public function clean($value)
{
parent::clean($value);
if (in_array($value, $this->empty_values)) {
$value = '';
}
if ($value == '') {
return $value;
}
$emails = preg_split('/\s*,\s*/', $value, -1, PREG_SPLIT_NO_EMPTY);
foreach ($emails as $email) {
if (!Pluf_Utils::isValidEmail($email)) {
throw new Pluf_Form_Invalid(__(
'Please enter one or more valid email addresses.'
));
}
}
return implode(',', $emails);
}
}

View File

@ -63,10 +63,11 @@ class IDF_Form_TabsConf extends Pluf_Form
'source_notification_email', 'source_notification_email',
'issues_notification_email',); 'issues_notification_email',);
foreach ($ak as $key) { foreach ($ak as $key) {
$this->fields[$key] = new Pluf_Form_Field_Email( $this->fields[$key] = new IDF_Form_Field_EmailList(
array('required' => false, array('required' => false,
'label' => $key, 'label' => $key,
'initial' => $this->conf->getVal($key, ''), 'initial' => $this->conf->getVal($key, ''),
'widget_attrs' => array('size' => 40),
)); ));
} }

View File

@ -242,8 +242,10 @@ class IDF_Issue extends Pluf_Model
$to_email = array(); $to_email = array();
if ('' != $conf->getVal('issues_notification_email', '')) { if ('' != $conf->getVal('issues_notification_email', '')) {
$langs = Pluf::f('languages', array('en')); $langs = Pluf::f('languages', array('en'));
$to_email[] = array($conf->getVal('issues_notification_email'), $addresses = explode(',', $conf->getVal('issues_notification_email'));
$langs[0]); foreach ($addresses as $address) {
$to_email[] = array($address, $langs[0]);
}
} }
$current_locale = Pluf_Translation::getLocale(); $current_locale = Pluf_Translation::getLocale();
$id = '<'.md5($this->id.md5(Pluf::f('secret_key'))).'@'.Pluf::f('mail_host', 'localhost').'>'; $id = '<'.md5($this->id.md5(Pluf::f('secret_key'))).'@'.Pluf::f('mail_host', 'localhost').'>';

View File

@ -197,14 +197,17 @@ class IDF_Review_Patch extends Pluf_Model
); );
$tmpl = new Pluf_Template('idf/review/review-created-email.txt'); $tmpl = new Pluf_Template('idf/review/review-created-email.txt');
$text_email = $tmpl->render($context); $text_email = $tmpl->render($context);
$addresses = explode(';',$conf->getVal('review_notification_email'));
foreach ($addresses as $address) {
$email = new Pluf_Mail(Pluf::f('from_email'), $email = new Pluf_Mail(Pluf::f('from_email'),
$conf->getVal('review_notification_email'), $address,
sprintf(__('New Code Review %s - %s (%s)'), sprintf(__('New Code Review %s - %s (%s)'),
$this->get_review()->id, $this->get_review()->id,
$this->get_review()->summary, $this->get_review()->summary,
$this->get_review()->get_project()->shortname)); $this->get_review()->get_project()->shortname));
$email->addTextMessage($text_email); $email->addTextMessage($text_email);
$email->sendMail(); $email->sendMail();
}
Pluf_Translation::loadSetLocale($current_locale); Pluf_Translation::loadSetLocale($current_locale);
} }
} }

View File

@ -237,14 +237,16 @@ class IDF_Upload extends Pluf_Model
)); ));
$tmpl = new Pluf_Template('idf/downloads/download-created-email.txt'); $tmpl = new Pluf_Template('idf/downloads/download-created-email.txt');
$text_email = $tmpl->render($context); $text_email = $tmpl->render($context);
$addresses = explode(',', $conf->getVal('downloads_notification_email'));
foreach ($addresses as $address) {
$email = new Pluf_Mail(Pluf::f('from_email'), $email = new Pluf_Mail(Pluf::f('from_email'),
$conf->getVal('downloads_notification_email'), $address,
sprintf(__('New download - %s (%s)'), sprintf(__('New download - %s (%s)'),
$this->summary, $this->summary,
$this->get_project()->shortname)); $this->get_project()->shortname));
$email->addTextMessage($text_email); $email->addTextMessage($text_email);
$email->sendMail(); $email->sendMail();
}
Pluf_Translation::loadSetLocale($current_locale); Pluf_Translation::loadSetLocale($current_locale);
} }
} }

View File

@ -272,11 +272,16 @@ class IDF_WikiRevision extends Pluf_Model
} }
$tmpl = new Pluf_Template($template); $tmpl = new Pluf_Template($template);
$text_email = $tmpl->render($context); $text_email = $tmpl->render($context);
$addresses = explode(',', $conf->getVal('wiki_notification_email'));
foreach ($addresses as $address) {
$email = new Pluf_Mail(Pluf::f('from_email'), $email = new Pluf_Mail(Pluf::f('from_email'),
$conf->getVal('wiki_notification_email'), $address,
$title); $title);
$email->addTextMessage($text_email); $email->addTextMessage($text_email);
$email->sendMail(); $email->sendMail();
}
Pluf_Translation::loadSetLocale($current_locale); Pluf_Translation::loadSetLocale($current_locale);
} }
} }

View File

@ -96,7 +96,7 @@ password or SSH key.{/blocktrans}
<div class="issue-submit-info"> <div class="issue-submit-info">
<p><strong>{trans 'Instructions:'}</strong></p> <p><strong>{trans 'Instructions:'}</strong></p>
<p>{blocktrans}You can configure here the project tabs access rights and notification emails.{/blocktrans}</p> <p>{blocktrans}You can configure here the project tabs access rights and notification emails.{/blocktrans}</p>
<p>{blocktrans}Notification emails will be sent from the <strong>{$from_email}</strong> address, if you send the email to a mailing list, you may need to register this email address. If you do not want to send emails for a given type of changes, simply leave the corresponding field empty.{/blocktrans}</p> <p>{blocktrans}Notification emails will be sent from the <strong>{$from_email}</strong> address, if you send the email to a mailing list, you may need to register this email address. Multiple email addresses must be separated through commas (','). If you do not want to send emails for a given type of changes, simply leave the corresponding field empty.{/blocktrans}</p>
<p>{blocktrans}If you mark a project as private, only the project members and administrators, together with the extra authorized users you provide will have access to the project. You will still be able to define further access rights for the different tabs but the "Open to all" and "Signed in users" will default to authorized users only.{/blocktrans}</p> <p>{blocktrans}If you mark a project as private, only the project members and administrators, together with the extra authorized users you provide will have access to the project. You will still be able to define further access rights for the different tabs but the "Open to all" and "Signed in users" will default to authorized users only.{/blocktrans}</p>
<p>{blocktrans}Specify each person by its login. Each person must have already registered with the given login. Separate the logins with commas and/or new lines.{/blocktrans}</p> <p>{blocktrans}Specify each person by its login. Each person must have already registered with the given login. Separate the logins with commas and/or new lines.{/blocktrans}</p>
</div> </div>