diff --git a/lib/Froxlor/Api/Commands/Customers.php b/lib/Froxlor/Api/Commands/Customers.php index 11e0b014..34f386bf 100644 --- a/lib/Froxlor/Api/Commands/Customers.php +++ b/lib/Froxlor/Api/Commands/Customers.php @@ -197,11 +197,13 @@ class Customers extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resource * @param bool $perlenabled * optional, whether to allow usage of Perl/CGI, default 0 (false) * @param bool $dnsenabled - * optional, ether to allow usage of the DNS editor (requires activated nameserver in settings), default 0 (false) + * optional, wether to allow usage of the DNS editor (requires activated nameserver in settings), default 0 (false) * @param bool $logviewenabled - * optional, ether to allow acccess to webserver access/error-logs, default 0 (false) + * optional, wether to allow acccess to webserver access/error-logs, default 0 (false) * @param bool $store_defaultindex * optional, whether to store the default index file to customers homedir + * @param int $hosting_plan_id + * optional, specify a hosting-plan to set certain resource-values from the plan instead of specifying them * * @access admin * @throws \Exception @@ -230,29 +232,57 @@ class Customers extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resource $gender = (int) $this->getParam('gender', true, 0); $custom_notes = $this->getParam('custom_notes', true, ''); $custom_notes_show = $this->getBoolParam('custom_notes_show', true, 0); - - $diskspace = $this->getUlParam('diskspace', 'diskspace_ul', true, 0); - $traffic = $this->getUlParam('traffic', 'traffic_ul', true, 0); - $subdomains = $this->getUlParam('subdomains', 'subdomains_ul', true, 0); - $emails = $this->getUlParam('emails', 'emails_ul', true, 0); - $email_accounts = $this->getUlParam('email_accounts', 'email_accounts_ul', true, 0); - $email_forwarders = $this->getUlParam('email_forwarders', 'email_forwarders_ul', true, 0); - $email_quota = $this->getUlParam('email_quota', 'email_quota_ul', true, Settings::Get('system.mail_quota')); - $email_imap = $this->getBoolParam('email_imap', true, 0); - $email_pop3 = $this->getBoolParam('email_pop3', true, 0); - $ftps = $this->getUlParam('ftps', 'ftps_ul', true, 0); - $mysqls = $this->getUlParam('mysqls', 'mysqls_ul', true, 0); $createstdsubdomain = $this->getBoolParam('createstdsubdomain', true, 0); $password = $this->getParam('new_customer_password', true, ''); $sendpassword = $this->getBoolParam('sendpassword', true, 0); - $phpenabled = $this->getBoolParam('phpenabled', true, 0); - $p_allowed_phpconfigs = $this->getParam('allowed_phpconfigs', true, array()); - $perlenabled = $this->getBoolParam('perlenabled', true, 0); - $dnsenabled = $this->getBoolParam('dnsenabled', true, 0); - $logviewenabled = $this->getBoolParam('logviewenabled', true, 0); $store_defaultindex = $this->getBoolParam('store_defaultindex', true, 0); $loginname = $this->getParam('new_loginname', true, ''); + // hosting-plan values + $hosting_plan_id = $this->getParam('hosting_plan_id', true, 0); + if ($hosting_plan_id > 0) { + $hp_result = $this->apiCall('HostingPlans.get', array( + 'id' => $hosting_plan_id + )); + $hp_result['value'] = json_decode($hp_result['value'], true); + foreach ($hp_result['value'] as $index => $value) { + $hp_result[$index] = $value; + } + $diskspace = $hp_result['diskspace'] ?? 0; + $traffic = $hp_result['traffic'] ?? 0; + $subdomains = $hp_result['subdomains'] ?? 0; + $emails = $hp_result['emails'] ?? 0; + $email_accounts = $hp_result['email_accounts'] ?? 0; + $email_forwarders = $hp_result['email_forwarders'] ?? 0; + $email_quota = $hp_result['email_quota'] ?? Settings::Get('system.mail_quota'); + $email_imap = $hp_result['email_imap'] ?? 0; + $email_pop3 = $hp_result['email_pop3'] ?? 0; + $ftps = $hp_result['ftps'] ?? 0; + $mysqls = $hp_result['mysqls'] ?? 0; + $phpenabled = $hp_result['phpenabled'] ?? 0; + $p_allowed_phpconfigs = $hp_result['allowed_phpconfigs'] ?? 0; + $perlenabled = $hp_result['perlenabled'] ?? 0; + $dnsenabled = $hp_result['dnsenabled'] ?? 0; + $logviewenabled = $hp_result['logviewenabled'] ?? 0; + } else { + $diskspace = $this->getUlParam('diskspace', 'diskspace_ul', true, 0); + $traffic = $this->getUlParam('traffic', 'traffic_ul', true, 0); + $subdomains = $this->getUlParam('subdomains', 'subdomains_ul', true, 0); + $emails = $this->getUlParam('emails', 'emails_ul', true, 0); + $email_accounts = $this->getUlParam('email_accounts', 'email_accounts_ul', true, 0); + $email_forwarders = $this->getUlParam('email_forwarders', 'email_forwarders_ul', true, 0); + $email_quota = $this->getUlParam('email_quota', 'email_quota_ul', true, Settings::Get('system.mail_quota')); + $email_imap = $this->getBoolParam('email_imap', true, 0); + $email_pop3 = $this->getBoolParam('email_pop3', true, 0); + $ftps = $this->getUlParam('ftps', 'ftps_ul', true, 0); + $mysqls = $this->getUlParam('mysqls', 'mysqls_ul', true, 0); + $phpenabled = $this->getBoolParam('phpenabled', true, 0); + $p_allowed_phpconfigs = $this->getParam('allowed_phpconfigs', true, array()); + $perlenabled = $this->getBoolParam('perlenabled', true, 0); + $dnsenabled = $this->getBoolParam('dnsenabled', true, 0); + $logviewenabled = $this->getBoolParam('logviewenabled', true, 0); + } + // validation $name = \Froxlor\Validate\Validate::validate($name, 'name', '', '', array(), true); $firstname = \Froxlor\Validate\Validate::validate($firstname, 'first name', '', '', array(), true); diff --git a/tests/Customers/HostingPlansTest.php b/tests/Customers/HostingPlansTest.php index 41cafd80..463fa64b 100644 --- a/tests/Customers/HostingPlansTest.php +++ b/tests/Customers/HostingPlansTest.php @@ -12,6 +12,7 @@ use Froxlor\Api\Commands\HostingPlans; * @covers \Froxlor\Api\ApiCommand * @covers \Froxlor\Api\ApiParameter * @covers \Froxlor\Api\Commands\HostingPlans + * @covers \Froxlor\Api\Commands\Customers */ class HostingPlansTest extends TestCase { @@ -65,7 +66,7 @@ class HostingPlansTest extends TestCase $this->expectExceptionMessage('Requested parameter "name" could not be found for "HostingPlans:add"'); HostingPlans::getLocal($admin_userdata, $data)->add(); - + $data['name'] = null; $this->expectExceptionMessage('Requested parameter "name" is empty where it should not be for "HostingPlans:add"'); HostingPlans::getLocal($admin_userdata, $data)->add(); @@ -120,7 +121,7 @@ class HostingPlansTest extends TestCase $json_result = HostingPlans::getLocal($customer_userdata)->listing(); } - + public function testCustomerPlanAdd() { global $admin_userdata; @@ -129,10 +130,10 @@ class HostingPlansTest extends TestCase 'id' => 1 ))->get(); $customer_userdata = json_decode($json_result, true)['data']; - + $this->expectExceptionCode(403); $this->expectExceptionMessage("Not allowed to execute given command."); - + $json_result = HostingPlans::getLocal($customer_userdata)->add(); } @@ -144,13 +145,13 @@ class HostingPlansTest extends TestCase 'id' => 1 ))->get(); $customer_userdata = json_decode($json_result, true)['data']; - + $this->expectExceptionCode(403); $this->expectExceptionMessage("Not allowed to execute given command."); - + $json_result = HostingPlans::getLocal($customer_userdata)->get(); } - + public function testCustomerPlanUpdate() { global $admin_userdata; @@ -159,10 +160,10 @@ class HostingPlansTest extends TestCase 'id' => 1 ))->get(); $customer_userdata = json_decode($json_result, true)['data']; - + $this->expectExceptionCode(403); $this->expectExceptionMessage("Not allowed to execute given command."); - + $json_result = HostingPlans::getLocal($customer_userdata)->update(); } @@ -174,10 +175,10 @@ class HostingPlansTest extends TestCase 'id' => 1 ))->get(); $customer_userdata = json_decode($json_result, true)['data']; - + $this->expectExceptionCode(403); $this->expectExceptionMessage("Not allowed to execute given command."); - + $json_result = HostingPlans::getLocal($customer_userdata)->delete(); } @@ -255,4 +256,48 @@ class HostingPlansTest extends TestCase $result = json_decode($json_result, true)['data']; $this->assertEquals('test2', $result['name']); } + + /** + * + * @depends testAdminPlanAdd + */ + public function testAdminCustomersAddWithHostingPlan() + { + global $admin_userdata; + + $json_result = HostingPlans::getLocal($admin_userdata, array( + 'planname' => 'test' + ))->get(); + $result = json_decode($json_result, true)['data']; + + $data = [ + 'new_loginname' => 'test1hp', + 'email' => 'team@froxlor.org', + 'firstname' => 'Test', + 'name' => 'Testman', + 'customernumber' => 1337, + 'createstdsubdomain' => 0, + 'new_customer_password' => 'h0lYmo1y', + 'sendpassword' => TRAVIS_CI == 1 ? 0 : 1, + 'store_defaultindex' => 1, + 'custom_notes' => 'secret', + 'custom_notes_show' => 0, + 'gender' => 5, + 'hosting_plan_id' => $result['id'] + ]; + + $json_result = Customers::getLocal($admin_userdata, $data)->add(); + $result = json_decode($json_result, true)['data']; + $this->assertEquals(- 1024, $result['diskspace']); + $this->assertEquals(15, $result['subdomains']); + $this->assertEquals(1, $result['phpenabled']); + $this->assertJsonStringEqualsJsonString(json_encode([ + 1 + ]), $result['allowed_phpconfigs']); + + // remove customer + Customers::getLocal($admin_userdata, array( + 'loginname' => 'test1hp' + ))->delete(); + } }