* Notifications: Admins now configure the mail account to use for email notifications instead of the user account

This commit is contained in:
nathan 2022-02-09 13:48:16 -07:00
parent 5665fe537a
commit 4cbb9f7d6e
5 changed files with 84 additions and 12 deletions

View File

@ -215,19 +215,24 @@ class notifications {
* it's an int with the account id or the e-mail address of a non-eGW user
*/
public function set_sender($_sender) {
if(is_object($_sender)) {
if(is_object($_sender))
{
$this->sender = $_sender;
return true;
} else {
}
else
{
// no object atm, we have to handle this and make a pseudo-object
if(is_numeric($_sender)) {
$this->sender = (object) $GLOBALS['egw']->accounts->read($_sender);
if(is_numeric($_sender))
{
$this->sender = (object)$GLOBALS['egw']->accounts->read($_sender);
return true;
}
if(is_string($_sender) && strpos($_sender,'@')) {
$this->sender = (object) array (
'account_email' => $this->get_addresspart($_sender,'email'),
'account_fullname' => $this->get_addresspart($_sender,'fullname'),
if(is_string($_sender) && strpos($_sender, '@'))
{
$this->sender = (object)array(
'account_email' => $this->get_addresspart($_sender, 'email'),
'account_fullname' => $this->get_addresspart($_sender, 'fullname'),
);
return true;
}
@ -821,7 +826,8 @@ class notifications {
* @param array $_data
* @return boolean
*/
public function set_popupdata($_appname, $_data) {
public function set_popupdata($_appname, $_data)
{
$this->popup_data = array(
'appname' => $_appname,
'data' => $_data
@ -829,4 +835,36 @@ class notifications {
return true;
}
/**
* Hook for site configuration
* Gets the appropriate mail accounts to offer to use for notifications
*
* @param $data
* @return void
*/
public function config($data)
{
$result = ['sel_options' => ['async_identity' => []]];
$identities = iterator_to_array(EGroupware\Api\Mail\Account::search(false, 'params', 'ABS(egw_ea_valid.account_id) ASC, '));
// We only want identities for all users, and prefer SMTP only
$smtp_only = [];
$others = [];
foreach($identities as $id => $identity)
{
// Identities should be sorted so all users are first. Stop when we get to the others.
if(!in_array('0', $identity['account_id']))
{
break;
}
$destination = $identity['acc_imap_host'] ? 'others' : 'smtp_only';
$$destination[$id] = $identity['acc_name'];
}
// Put SMTP only identities first
$result['sel_options']['async_identity'] = $smtp_only + $others;
return $result;
}
}

View File

@ -76,7 +76,28 @@ class notifications_email implements notifications_iface {
{
unset($this->mail);
}
$this->mail = new Api\Mailer();
// Use configured mail ac
$ident = null;
if($this->config->async_identity)
{
$ident = Api\Mail\Account::read($this->config->async_identity);
}
else
{
if($this->config->async_account)
{
$mail_identities = Api\Mail\Account::identities([], true, 'params', $this->config->async_account);
foreach($mail_identities as $mi)
{
if($mi['ident_email'] == $this->config->async_email || !$this->config->async_email)
{
$ident = Api\Mail\Account::read($mi['acc_id']);
}
}
}
}
$this->mail = new Api\Mailer($ident);
}
/**

View File

@ -55,6 +55,7 @@ last month notifications en Last month
linked entries: common en Linked entries:
login aborted, application exit? notifications en Login aborted, application exit?
login in egroupware: notifications en login in EGroupware:
mail account to use for notifications admin en Mail account to use for notifications
mail backend admin en Mail backend
mark all as read notifications en mark all as read
mark as read notifications en mark as read

View File

@ -33,6 +33,7 @@ $setup_info[NOTIFICATION_APP]['hooks'][] = 'after_navbar';
$setup_info[NOTIFICATION_APP]['hooks'][] = 'settings';
$setup_info[NOTIFICATION_APP]['hooks'][] = 'admin';
$setup_info[NOTIFICATION_APP]['hooks']['deleteaccount'] = 'notifications.notifications.deleteaccount';
$setup_info[NOTIFICATION_APP]['hooks']['config'] = 'notifications.notifications.config';
/* Dependencies for this app to work */
$setup_info[NOTIFICATION_APP]['depends'][] = array(

View File

@ -31,6 +31,17 @@
<option value="True">Yes</option>
</select>
</row>
<row>
<description value="Account" span="all" class="subHeader"/>
</row>
<row>
<description value="Mail account to use for notifications"/>
<select id="newsettings[async_identity]"/>
</row>
<row>
<description value="Email address to use for notifications"/>
<url-email id="newsettings[async_email]"/>
</row>
<row>
<description value="Signature" span="all" class="subHeader"/>
</row>