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:
@@ -302,6 +302,8 @@ class EmailAccounts extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Reso
|
|||||||
* optional, update quota
|
* optional, update quota
|
||||||
* @param string $email_password
|
* @param string $email_password
|
||||||
* optional, update password
|
* optional, update password
|
||||||
|
* @param bool $deactivated
|
||||||
|
* optional, admin-only
|
||||||
*
|
*
|
||||||
* @access admin, customer
|
* @access admin, customer
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
@@ -331,6 +333,7 @@ class EmailAccounts extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Reso
|
|||||||
|
|
||||||
$password = $this->getParam('email_password', true, '');
|
$password = $this->getParam('email_password', true, '');
|
||||||
$quota = $this->getParam('email_quota', true, $result['quota']);
|
$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
|
// get needed customer info to reduce the email-account-counter by one
|
||||||
$customer = $this->getCustomerData();
|
$customer = $this->getCustomerData();
|
||||||
@@ -372,6 +375,18 @@ class EmailAccounts extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Reso
|
|||||||
$quota = 0;
|
$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
|
// build update query
|
||||||
if (! empty($upd_query)) {
|
if (! empty($upd_query)) {
|
||||||
$upd_stmt = Database::prepare("
|
$upd_stmt = Database::prepare("
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ class Emails extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
|||||||
$customer_ids = $this->getAllowedCustomerIds('email');
|
$customer_ids = $this->getAllowedCustomerIds('email');
|
||||||
$params['idea'] = ($id <= 0 ? $emailaddr : $id);
|
$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
|
FROM `" . TABLE_MAIL_VIRTUAL . "` v
|
||||||
LEFT JOIN `" . TABLE_MAIL_USERS . "` u ON v.`popaccountid` = u.`id`
|
LEFT JOIN `" . TABLE_MAIL_USERS . "` u ON v.`popaccountid` = u.`id`
|
||||||
WHERE v.`customerid` IN (" . implode(", ", $customer_ids) . ")
|
WHERE v.`customerid` IN (" . implode(", ", $customer_ids) . ")
|
||||||
@@ -309,7 +309,7 @@ class Emails extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
|||||||
$result = array();
|
$result = array();
|
||||||
$query_fields = array();
|
$query_fields = array();
|
||||||
$result_stmt = Database::prepare("
|
$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
|
FROM `" . TABLE_MAIL_VIRTUAL . "` m
|
||||||
LEFT JOIN `" . TABLE_PANEL_DOMAINS . "` d ON (m.`domainid` = d.`id`)
|
LEFT JOIN `" . TABLE_PANEL_DOMAINS . "` d ON (m.`domainid` = d.`id`)
|
||||||
LEFT JOIN `" . TABLE_MAIL_USERS . "` u ON (m.`popaccountid` = u.`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']);
|
$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()
|
public function testAdminEmailAccountsUndefinedGet()
|
||||||
{
|
{
|
||||||
global $admin_userdata;
|
global $admin_userdata;
|
||||||
|
|||||||
Reference in New Issue
Block a user