added 'deactivated' parameter to EmailAccounts.update() so admins can disable individual email-accounts, will be overridden if customer is deactivatd and re-enabled; fixes #921
Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
@@ -100,7 +100,7 @@ class EmailAccounts extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Reso
|
||||
// alternative email address to send info to
|
||||
if (Settings::Get('panel.sendalternativemail') == 1) {
|
||||
$alternative_email = $idna_convert->encode(\Froxlor\Validate\Validate::validate($alternative_email, 'alternative_email', '', '', array(), true));
|
||||
if (!empty($alternative_email) && ! \Froxlor\Validate\Validate::validateEmail($alternative_email)) {
|
||||
if (! empty($alternative_email) && ! \Froxlor\Validate\Validate::validateEmail($alternative_email)) {
|
||||
\Froxlor\UI\Response::standard_error('alternativeemailiswrong', $alternative_email, true);
|
||||
}
|
||||
} else {
|
||||
@@ -236,7 +236,7 @@ class EmailAccounts extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Reso
|
||||
$this->mailer()->clearAddresses();
|
||||
|
||||
// customer wants to send the e-mail to an alternative email address too
|
||||
if (Settings::Get('panel.sendalternativemail') == 1 && !empty($alternative_email)) {
|
||||
if (Settings::Get('panel.sendalternativemail') == 1 && ! empty($alternative_email)) {
|
||||
// get template for mail subject
|
||||
$mail_subject = $this->getMailTemplate($customer, 'mails', 'pop_success_alternative_subject', $replace_arr, $this->lng['mails']['pop_success_alternative']['subject']);
|
||||
// get template for mail body
|
||||
@@ -302,6 +302,8 @@ class EmailAccounts extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Reso
|
||||
* optional, update quota
|
||||
* @param string $email_password
|
||||
* optional, update password
|
||||
* @param bool $deactivated
|
||||
* optional, admin-only
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws \Exception
|
||||
@@ -331,6 +333,7 @@ class EmailAccounts extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Reso
|
||||
|
||||
$password = $this->getParam('email_password', true, '');
|
||||
$quota = $this->getParam('email_quota', true, $result['quota']);
|
||||
$deactivated = $this->getBoolParam('deactivated', true, (strtolower($result['postfix']) == 'n' ? true : false));
|
||||
|
||||
// get needed customer info to reduce the email-account-counter by one
|
||||
$customer = $this->getCustomerData();
|
||||
@@ -372,6 +375,18 @@ class EmailAccounts extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Reso
|
||||
$quota = 0;
|
||||
}
|
||||
|
||||
if ($this->isAdmin()) {
|
||||
if (($deactivated == true && strtolower($result['postfix']) == 'y') || ($deactivated == false && strtolower($result['postfix']) == 'n')) {
|
||||
if (! empty($upd_query)) {
|
||||
$upd_query .= ", ";
|
||||
}
|
||||
$upd_query .= "`postfix` = :postfix, `imap` = :imap, `pop3` = :pop3";
|
||||
$upd_params['postfix'] = $deactivated ? 'N' : 'Y';
|
||||
$upd_params['imap'] = $deactivated ? '0' : '1';
|
||||
$upd_params['pop3'] = $deactivated ? '0' : '1';
|
||||
}
|
||||
}
|
||||
|
||||
// build update query
|
||||
if (! empty($upd_query)) {
|
||||
$upd_stmt = Database::prepare("
|
||||
|
||||
@@ -172,7 +172,7 @@ class Emails extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
||||
$customer_ids = $this->getAllowedCustomerIds('email');
|
||||
$params['idea'] = ($id <= 0 ? $emailaddr : $id);
|
||||
|
||||
$result_stmt = Database::prepare("SELECT v.`id`, v.`email`, v.`email_full`, v.`iscatchall`, v.`destination`, v.`customerid`, v.`popaccountid`, v.`domainid`, v.`description`, u.`quota`
|
||||
$result_stmt = Database::prepare("SELECT v.`id`, v.`email`, v.`email_full`, v.`iscatchall`, v.`destination`, v.`customerid`, v.`popaccountid`, v.`domainid`, v.`description`, u.`quota`, u.`imap`, u.`pop3`, u.`postfix`, u.`mboxsize`
|
||||
FROM `" . TABLE_MAIL_VIRTUAL . "` v
|
||||
LEFT JOIN `" . TABLE_MAIL_USERS . "` u ON v.`popaccountid` = u.`id`
|
||||
WHERE v.`customerid` IN (" . implode(", ", $customer_ids) . ")
|
||||
@@ -309,7 +309,7 @@ class Emails extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
||||
$result = array();
|
||||
$query_fields = array();
|
||||
$result_stmt = Database::prepare("
|
||||
SELECT m.`id`, m.`domainid`, m.`email`, m.`email_full`, m.`iscatchall`, u.`quota`, m.`destination`, m.`popaccountid`, d.`domain`, u.`mboxsize`
|
||||
SELECT m.`id`, m.`domainid`, m.`email`, m.`email_full`, m.`iscatchall`, m.`destination`, m.`popaccountid`, d.`domain`, u.`quota`, u.`imap`, u.`pop3`, u.`postfix`, u.`mboxsize`
|
||||
FROM `" . TABLE_MAIL_VIRTUAL . "` m
|
||||
LEFT JOIN `" . TABLE_PANEL_DOMAINS . "` d ON (m.`domainid` = d.`id`)
|
||||
LEFT JOIN `" . TABLE_MAIL_USERS . "` u ON (m.`popaccountid` = u.`id`)
|
||||
|
||||
@@ -448,6 +448,36 @@ class MailsTest extends TestCase
|
||||
$this->assertEquals(0, $result['quota']);
|
||||
}
|
||||
|
||||
public function testAdminEmailAccountsUpdateDeactivated()
|
||||
{
|
||||
global $admin_userdata;
|
||||
|
||||
// disable
|
||||
$data = [
|
||||
'emailaddr' => 'info@test2.local',
|
||||
'loginname' => 'test1',
|
||||
'deactivated' => 1
|
||||
];
|
||||
$json_result = EmailAccounts::getLocal($admin_userdata, $data)->update();
|
||||
$result = json_decode($json_result, true)['data'];
|
||||
// quota is disabled
|
||||
$this->assertEquals(0, $result['imap']);
|
||||
$this->assertEquals(0, $result['pop3']);
|
||||
$this->assertEquals('N', $result['postfix']);
|
||||
// re-enable
|
||||
$data = [
|
||||
'emailaddr' => 'info@test2.local',
|
||||
'loginname' => 'test1',
|
||||
'deactivated' => 0
|
||||
];
|
||||
$json_result = EmailAccounts::getLocal($admin_userdata, $data)->update();
|
||||
$result = json_decode($json_result, true)['data'];
|
||||
// quota is disabled
|
||||
$this->assertEquals(1, $result['imap']);
|
||||
$this->assertEquals(1, $result['pop3']);
|
||||
$this->assertEquals('Y', $result['postfix']);
|
||||
}
|
||||
|
||||
public function testAdminEmailAccountsUndefinedGet()
|
||||
{
|
||||
global $admin_userdata;
|
||||
|
||||
Reference in New Issue
Block a user