* 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 3c5bea23ef
commit 2775569936
5 changed files with 66 additions and 27 deletions

View File

@ -215,28 +215,25 @@ class notifications {
* it's an int with the account id or the e-mail address of a non-eGW user * it's an int with the account id or the e-mail address of a non-eGW user
*/ */
public function set_sender($_sender) { public function set_sender($_sender) {
// Check configured sender first - that overrides all if(is_object($_sender))
$config = Api\Config::read('notifications');
if($config && ($config['async_account' || $config['async_email']]))
{ {
$send_user = $config['async_account'];
$email = $config['async_email'] ?: $GLOBALS['egw']->accounts->id2name($send_user,'account_email');
}
if(is_object($_sender)) {
$this->sender = $_sender; $this->sender = $_sender;
return true; return true;
} else { }
else
{
// no object atm, we have to handle this and make a pseudo-object // no object atm, we have to handle this and make a pseudo-object
if(is_numeric($_sender)) { if(is_numeric($_sender))
$this->sender = (object) $GLOBALS['egw']->accounts->read($_sender); {
$this->sender = (object)$GLOBALS['egw']->accounts->read($_sender);
return true; return true;
} }
if(is_string($_sender) && strpos($_sender,'@')) { if(is_string($_sender) && strpos($_sender, '@'))
$this->sender = (object) array ( {
'account_email' => $this->get_addresspart($_sender,'email'), $this->sender = (object)array(
'account_fullname' => $this->get_addresspart($_sender,'fullname'), 'account_email' => $this->get_addresspart($_sender, 'email'),
); 'account_fullname' => $this->get_addresspart($_sender, 'fullname'),
);
return true; return true;
} }
} }
@ -829,12 +826,45 @@ class notifications {
* @param array $_data * @param array $_data
* @return boolean * @return boolean
*/ */
public function set_popupdata($_appname, $_data) { public function set_popupdata($_appname, $_data)
{
$this->popup_data = array( $this->popup_data = array(
'appname' => $_appname, 'appname' => $_appname,
'data' => $_data 'data' => $_data
); );
return true; 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

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

View File

@ -55,6 +55,7 @@ last month notifications en Last month
linked entries: common en Linked entries: linked entries: common en Linked entries:
login aborted, application exit? notifications en Login aborted, application exit? login aborted, application exit? notifications en Login aborted, application exit?
login in egroupware: notifications en login in EGroupware: 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 mail backend admin en Mail backend
mark all as read notifications en mark all as read mark all as read notifications en mark all as read
mark as read notifications en mark 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'][] = 'settings';
$setup_info[NOTIFICATION_APP]['hooks'][] = 'admin'; $setup_info[NOTIFICATION_APP]['hooks'][] = 'admin';
$setup_info[NOTIFICATION_APP]['hooks']['deleteaccount'] = 'notifications.notifications.deleteaccount'; $setup_info[NOTIFICATION_APP]['hooks']['deleteaccount'] = 'notifications.notifications.deleteaccount';
$setup_info[NOTIFICATION_APP]['hooks']['config'] = 'notifications.notifications.config';
/* Dependencies for this app to work */ /* Dependencies for this app to work */
$setup_info[NOTIFICATION_APP]['depends'][] = array( $setup_info[NOTIFICATION_APP]['depends'][] = array(

View File

@ -35,11 +35,11 @@
<description value="Account" span="all" class="subHeader"/> <description value="Account" span="all" class="subHeader"/>
</row> </row>
<row> <row>
<description value="User to use for async notifications"/> <description value="Mail account to use for notifications"/>
<select-account id="newsettings[async_account]"/> <select id="newsettings[async_identity]"/>
</row> </row>
<row> <row>
<description value="Email address to use for async notifications"/> <description value="Email address to use for notifications"/>
<url-email id="newsettings[async_email]"/> <url-email id="newsettings[async_email]"/>
</row> </row>
<row> <row>