From a5dc7b93a2cfe9405fb3048e07e8414b5bda7e2b Mon Sep 17 00:00:00 2001 From: Michael Kaufmann Date: Mon, 5 Oct 2020 19:59:02 +0200 Subject: [PATCH] unify customerid/loginname api-parameter-descriptions; fixes #883 Signed-off-by: Michael Kaufmann --- lib/Froxlor/Api/Commands/CustomerBackups.php | 4 ++- lib/Froxlor/Api/Commands/DirOptions.php | 8 ++--- lib/Froxlor/Api/Commands/DirProtections.php | 8 ++--- lib/Froxlor/Api/Commands/Domains.php | 31 ++++++++++++-------- lib/Froxlor/Api/Commands/EmailAccounts.php | 12 ++++---- lib/Froxlor/Api/Commands/EmailForwarders.php | 8 ++--- lib/Froxlor/Api/Commands/Emails.php | 12 ++++---- lib/Froxlor/Api/Commands/Ftps.php | 8 +++-- lib/Froxlor/Api/Commands/Mysqls.php | 12 ++++---- lib/Froxlor/Api/Commands/SubDomains.php | 12 ++++++-- tests/Domains/DomainsTest.php | 2 +- 11 files changed, 67 insertions(+), 50 deletions(-) diff --git a/lib/Froxlor/Api/Commands/CustomerBackups.php b/lib/Froxlor/Api/Commands/CustomerBackups.php index b5ebf5cf..bd74dac3 100644 --- a/lib/Froxlor/Api/Commands/CustomerBackups.php +++ b/lib/Froxlor/Api/Commands/CustomerBackups.php @@ -52,7 +52,9 @@ class CustomerBackups extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Re * @param bool $backup_web * optional whether to backup web-data, default is 0 (false) * @param int $customerid - * required when called as admin, not needed when called as customer + * optional, required when called as admin (if $loginname is not specified) + * @param string $loginname + * optional, required when called as admin (if $customerid is not specified) * * @access admin, customer * @throws \Exception diff --git a/lib/Froxlor/Api/Commands/DirOptions.php b/lib/Froxlor/Api/Commands/DirOptions.php index b7ddeb90..981fd02f 100644 --- a/lib/Froxlor/Api/Commands/DirOptions.php +++ b/lib/Froxlor/Api/Commands/DirOptions.php @@ -26,9 +26,9 @@ class DirOptions extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resourc * add options for a given directory * * @param int $customerid - * optional, admin-only, the customer-id + * optional, required when called as admin (if $loginname is not specified) * @param string $loginname - * optional, admin-only, the loginname + * optional, required when called as admin (if $customerid is not specified) * @param string $path * path relative to the customer's home-Directory * @param bool $options_indexes @@ -198,9 +198,9 @@ class DirOptions extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resourc * @param int $id * id of dir-protection entry * @param int $customerid - * optional, admin-only, the customer-id + * optional, required when called as admin (if $loginname is not specified) * @param string $loginname - * optional, admin-only, the loginname + * optional, required when called as admin (if $customerid is not specified) * @param bool $options_indexes * optional, activate directory-listing for this path, default 0 (false) * @param bool $options_cgi diff --git a/lib/Froxlor/Api/Commands/DirProtections.php b/lib/Froxlor/Api/Commands/DirProtections.php index 93959d59..8c4ea904 100644 --- a/lib/Froxlor/Api/Commands/DirProtections.php +++ b/lib/Froxlor/Api/Commands/DirProtections.php @@ -26,9 +26,9 @@ class DirProtections extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Res * add htaccess protection to a given directory * * @param int $customerid - * optional, admin-only, the customer-id + * optional, required when called as admin (if $loginname is not specified) * @param string $loginname - * optional, admin-only, the loginname + * optional, required when called as admin (if $customerid is not specified) * @param string $path * @param string $username * @param string $directory_password @@ -187,9 +187,9 @@ class DirProtections extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Res * @param string $username * optional, the username * @param int $customerid - * optional, admin-only, the customer-id + * optional, required when called as admin (if $loginname is not specified) * @param string $loginname - * optional, admin-only, the loginname + * optional, required when called as admin (if $customerid is not specified) * @param string $directory_password * optional, leave empty for no change * @param string $directory_authname diff --git a/lib/Froxlor/Api/Commands/Domains.php b/lib/Froxlor/Api/Commands/Domains.php index 6ef2ef2d..c0f9c0dd 100644 --- a/lib/Froxlor/Api/Commands/Domains.php +++ b/lib/Froxlor/Api/Commands/Domains.php @@ -199,6 +199,9 @@ class Domains extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEn * @param string $domain * domain-name * @param int $customerid + * optional, required when called as admin (if $loginname is not specified) + * @param string $loginname + * optional, required when called as admin (if $customerid is not specified) * @param int $adminid * optional, default is the calling admin's ID * @param array $ipandport @@ -297,7 +300,6 @@ class Domains extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEn // parameters $p_domain = $this->getParam('domain'); - $customerid = intval($this->getParam('customerid')); // optional parameters $p_ipandports = $this->getParam('ipandport', true, explode(',', Settings::Get('system.defaultip'))); @@ -377,9 +379,8 @@ class Domains extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEn ), '', true); } - $customer = $this->apiCall('Customers.get', array( - 'id' => $customerid - )); + $customer = $this->getCustomerData(); + $customerid = $customer['customerid']; if ($this->getUserDetail('customers_see_all') == '1' && $adminid != $this->getUserDetail('adminid')) { $admin_stmt = Database::prepare(" @@ -844,7 +845,9 @@ class Domains extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEn * @param string $domainname * optional, the domainname * @param int $customerid - * optional customer-id + * required (if $loginname is not specified) + * @param string $loginname + * required (if $customerid is not specified) * @param int $adminid * optional, default is the calling admin's ID * @param array $ipandport @@ -952,9 +955,18 @@ class Domains extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEn // optional parameters $p_ipandports = $this->getParam('ipandport', true, array()); - $customerid = intval($this->getParam('customerid', true, $result['customerid'])); $adminid = intval($this->getParam('adminid', true, $result['adminid'])); + if ($this->getParam('customerid', true, 0) == 0 && $this->getParam('loginname', true, '') == '') { + $customerid = $result['customerid']; + $customer = $this->apiCall('Customers.get', array( + 'id' => $customerid + )); + } else { + $customer = $this->getCustomerData(); + $customerid = $customer['customerid']; + } + $subcanemaildomain = $this->getParam('subcanemaildomain', true, $result['subcanemaildomain']); $isemaildomain = $this->getBoolParam('isemaildomain', true, $result['isemaildomain']); $email_only = $this->getBoolParam('email_only', true, $result['email_only']); @@ -1085,13 +1097,6 @@ class Domains extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEn if (empty($customer) || $customer['customerid'] != $customerid) { \Froxlor\UI\Response::standard_error('customerdoesntexist', '', true); } - } else { - $customerid = $result['customerid']; - - // get customer - $customer = $this->apiCall('Customers.get', array( - 'id' => $customerid - )); } // handle change of admin (move domain from admin to admin) diff --git a/lib/Froxlor/Api/Commands/EmailAccounts.php b/lib/Froxlor/Api/Commands/EmailAccounts.php index 4a7b75b4..017359dd 100644 --- a/lib/Froxlor/Api/Commands/EmailAccounts.php +++ b/lib/Froxlor/Api/Commands/EmailAccounts.php @@ -30,9 +30,9 @@ class EmailAccounts extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Reso * @param string $emailaddr * optional email-address to add the account for * @param int $customerid - * optional, admin-only, the customer-id + * optional, required when called as admin (if $loginname is not specified) * @param string $loginname - * optional, admin-only, the loginname + * optional, required when called as admin (if $customerid is not specified) * @param string $email_password * password for the account * @param string $alternative_email @@ -295,9 +295,9 @@ class EmailAccounts extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Reso * @param string $emailaddr * optional, the email-address to update * @param int $customerid - * optional, admin-only, the customer-id + * optional, required when called as admin (if $loginname is not specified) * @param string $loginname - * optional, admin-only, the loginname + * optional, required when called as admin (if $customerid is not specified) * @param int $email_quota * optional, update quota * @param string $email_password @@ -418,9 +418,9 @@ class EmailAccounts extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Reso * @param string $emailaddr * optional, the email-address to delete the account for * @param int $customerid - * optional, admin-only, the customer-id + * optional, required when called as admin (if $loginname is not specified) * @param string $loginname - * optional, admin-only, the loginname + * optional, required when called as admin (if $customerid is not specified) * @param bool $delete_userfiles * optional, default false * diff --git a/lib/Froxlor/Api/Commands/EmailForwarders.php b/lib/Froxlor/Api/Commands/EmailForwarders.php index d01094d8..847bf9f6 100644 --- a/lib/Froxlor/Api/Commands/EmailForwarders.php +++ b/lib/Froxlor/Api/Commands/EmailForwarders.php @@ -30,9 +30,9 @@ class EmailForwarders extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Re * @param string $emailaddr * optional, the email-address to add the forwarder for * @param int $customerid - * optional, admin-only, the customer-id + * optional, required when called as admin (if $loginname is not specified) * @param string $loginname - * optional, admin-only, the loginname + * optional, required when called as admin (if $customerid is not specified) * @param string $destination * email-address to add as forwarder * @@ -221,9 +221,9 @@ class EmailForwarders extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Re * @param string $emailaddr * optional, the email-address to delete the forwarder from * @param int $customerid - * optional, admin-only, the customer-id + * optional, required when called as admin (if $loginname is not specified) * @param string $loginname - * optional, admin-only, the loginname + * optional, required when called as admin (if $customerid is not specified) * @param int $forwarderid * id of the forwarder to delete * diff --git a/lib/Froxlor/Api/Commands/Emails.php b/lib/Froxlor/Api/Commands/Emails.php index c3120fe7..f6c2abba 100644 --- a/lib/Froxlor/Api/Commands/Emails.php +++ b/lib/Froxlor/Api/Commands/Emails.php @@ -32,9 +32,9 @@ class Emails extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt * @param boolean $iscatchall * optional, make this address a catchall address, default: no * @param int $customerid - * optional, admin-only, the customer-id + * optional, required when called as admin (if $loginname is not specified) * @param string $loginname - * optional, admin-only, the loginname + * optional, required when called as admin (if $customerid is not specified) * * @access admin, customer * @throws \Exception @@ -190,9 +190,9 @@ class Emails extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt * @param string $emailaddr * optional, the email-address * @param int $customerid - * optional, admin-only, the customer-id + * optional, required when called as admin (if $loginname is not specified) * @param string $loginname - * optional, admin-only, the loginname + * optional, required when called as admin (if $customerid is not specified) * @param boolean $iscatchall * optional * @@ -352,9 +352,9 @@ class Emails extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt * @param string $emailaddr * optional, the email-address * @param int $customerid - * optional, admin-only, the customer-id + * optional, required when called as admin (if $loginname is not specified) * @param string $loginname - * optional, admin-only, the loginname + * optional, required when called as admin (if $customerid is not specified) * @param boolean $delete_userfiles * optional, delete email data from filesystem, default: 0 (false) * diff --git a/lib/Froxlor/Api/Commands/Ftps.php b/lib/Froxlor/Api/Commands/Ftps.php index 056c43bf..b20c0286 100644 --- a/lib/Froxlor/Api/Commands/Ftps.php +++ b/lib/Froxlor/Api/Commands/Ftps.php @@ -40,7 +40,9 @@ class Ftps extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntit * @param string $ftp_domain * optional if customer.ftpatdomain is allowed, specify a domain (customer must be owner) * @param int $customerid - * required when called as admin, not needed when called as customer + * optional, required when called as admin (if $loginname is not specified) + * @param string $loginname + * optional, required when called as admin (if $customerid is not specified) * @param array $additional_members * optional whether to add additional usernames to the group * @param bool $is_defaultuser @@ -351,7 +353,9 @@ class Ftps extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntit * @param string $shell * optional, default /bin/false (not changeable when deactivated) * @param int $customerid - * required when called as admin, not needed when called as customer + * optional, required when called as admin (if $loginname is not specified) + * @param string $loginname + * optional, required when called as admin (if $customerid is not specified) * * @access admin, customer * @throws \Exception diff --git a/lib/Froxlor/Api/Commands/Mysqls.php b/lib/Froxlor/Api/Commands/Mysqls.php index 6ad4e1f8..4a0afa00 100644 --- a/lib/Froxlor/Api/Commands/Mysqls.php +++ b/lib/Froxlor/Api/Commands/Mysqls.php @@ -34,9 +34,9 @@ class Mysqls extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt * @param bool $sendinfomail * optional, send created resource-information to customer, default: false * @param int $customerid - * optional, admin-only, the customer-id + * optional, required when called as admin (if $loginname is not specified) * @param string $loginname - * optional, admin-only, the loginname + * optional, required when called as admin (if $customerid is not specified) * * @access admin, customer * @throws \Exception @@ -278,9 +278,9 @@ class Mysqls extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt * @param string $description * optional, description for database * @param int $customerid - * optional, admin-only, the customer-id + * optional, required when called as admin (if $loginname is not specified) * @param string $loginname - * optional, admin-only, the loginname + * optional, required when called as admin (if $customerid is not specified) * * @access admin, customer * @throws \Exception @@ -462,9 +462,9 @@ class Mysqls extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt * @param int $mysql_server * optional, specify database-server, default is none * @param int $customerid - * optional, admin-only, the customer-id + * optional, required when called as admin (if $loginname is not specified) * @param string $loginname - * optional, admin-only, the loginname + * optional, required when called as admin (if $customerid is not specified) * * @access admin, customer * @throws \Exception diff --git a/lib/Froxlor/Api/Commands/SubDomains.php b/lib/Froxlor/Api/Commands/SubDomains.php index 699c70c9..3c09c6f8 100644 --- a/lib/Froxlor/Api/Commands/SubDomains.php +++ b/lib/Froxlor/Api/Commands/SubDomains.php @@ -56,7 +56,9 @@ class SubDomains extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resourc * @param bool $hsts_preload * optional whether or not to preload HSTS header value, default 0 * @param int $customerid - * required when called as admin, not needed when called as customer + * optional, required when called as admin (if $loginname is not specified) + * @param string $loginname + * optional, required when called as admin (if $customerid is not specified) * * @access admin, customer * @throws \Exception @@ -470,7 +472,9 @@ class SubDomains extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resourc * @param bool $hsts_preload * optional whether or not to preload HSTS header value * @param int $customerid - * required when called as admin, not needed when called as customer + * optional, required when called as admin (if $loginname is not specified) + * @param string $loginname + * optional, required when called as admin (if $customerid is not specified) * * @access admin, customer * @throws \Exception @@ -876,7 +880,9 @@ class SubDomains extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resourc * @param string $domainname * optional, the domainname * @param int $customerid - * required when called as admin, not needed when called as customer + * optional, required when called as admin (if $loginname is not specified) + * @param string $loginname + * optional, required when called as admin (if $customerid is not specified) * * @access admin, customer * @throws \Exception diff --git a/tests/Domains/DomainsTest.php b/tests/Domains/DomainsTest.php index 85e0855b..36018ef5 100644 --- a/tests/Domains/DomainsTest.php +++ b/tests/Domains/DomainsTest.php @@ -282,7 +282,7 @@ class DomainsTest extends TestCase 'customerid' => $customer_userdata['customerid'] + 1 ]; Settings::Set('panel.allow_domain_change_customer', 1); - $this->expectExceptionMessage("The customer you have chosen doesn't exist."); + $this->expectExceptionMessage("Customer with id #2 could not be found"); Domains::getLocal($admin_userdata, $data)->update(); }