Skip to content

Commit

Permalink
unify customerid/loginname api-parameter-descriptions; fixes froxlor#883
Browse files Browse the repository at this point in the history


Signed-off-by: Michael Kaufmann <[email protected]>
  • Loading branch information
d00p committed Oct 5, 2020
1 parent 244d282 commit a5dc7b9
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 50 deletions.
4 changes: 3 additions & 1 deletion lib/Froxlor/Api/Commands/CustomerBackups.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ private function validateAccess()
* @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
Expand Down
8 changes: 4 additions & 4 deletions lib/Froxlor/Api/Commands/DirOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -198,9 +198,9 @@ public function get()
* @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
Expand Down
8 changes: 4 additions & 4 deletions lib/Froxlor/Api/Commands/DirProtections.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -187,9 +187,9 @@ public function get()
* @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
Expand Down
31 changes: 18 additions & 13 deletions lib/Froxlor/Api/Commands/Domains.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ private function getIpsForDomain($domain_id = 0, $ssl_only = false)
* @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
Expand Down Expand Up @@ -297,7 +300,6 @@ public function add()

// parameters
$p_domain = $this->getParam('domain');
$customerid = intval($this->getParam('customerid'));

// optional parameters
$p_ipandports = $this->getParam('ipandport', true, explode(',', Settings::Get('system.defaultip')));
Expand Down Expand Up @@ -377,9 +379,8 @@ public function add()
), '', 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("
Expand Down Expand Up @@ -844,7 +845,9 @@ public function add()
* @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
Expand Down Expand Up @@ -952,9 +955,18 @@ public function update()

// 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']);
Expand Down Expand Up @@ -1085,13 +1097,6 @@ public function update()
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)
Expand Down
12 changes: 6 additions & 6 deletions lib/Froxlor/Api/Commands/EmailAccounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -295,9 +295,9 @@ public function get()
* @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
Expand Down Expand Up @@ -418,9 +418,9 @@ public function listingCount()
* @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
*
Expand Down
8 changes: 4 additions & 4 deletions lib/Froxlor/Api/Commands/EmailForwarders.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -221,9 +221,9 @@ public function listingCount()
* @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
*
Expand Down
12 changes: 6 additions & 6 deletions lib/Froxlor/Api/Commands/Emails.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -190,9 +190,9 @@ public function get()
* @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
*
Expand Down Expand Up @@ -352,9 +352,9 @@ public function listingCount()
* @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)
*
Expand Down
8 changes: 6 additions & 2 deletions lib/Froxlor/Api/Commands/Ftps.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -351,7 +353,9 @@ public function get()
* @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
Expand Down
12 changes: 6 additions & 6 deletions lib/Froxlor/Api/Commands/Mysqls.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -278,9 +278,9 @@ public function get()
* @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
Expand Down Expand Up @@ -462,9 +462,9 @@ public function listingCount()
* @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
Expand Down
12 changes: 9 additions & 3 deletions lib/Froxlor/Api/Commands/SubDomains.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -470,7 +472,9 @@ public function get()
* @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
Expand Down Expand Up @@ -876,7 +880,9 @@ public function listingCount()
* @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
Expand Down
2 changes: 1 addition & 1 deletion tests/Domains/DomainsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public function testAdminDomainsMoveButUnknownCustomer()
'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();
}

Expand Down

0 comments on commit a5dc7b9

Please sign in to comment.