From 0d75e685da62b82020d860a01bafffe05df4b78c Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 8 Dec 2023 21:52:22 +0000 Subject: [PATCH] bug fixes --- Admin/Install/db.json | 38 +++++--- Controller/ApiController.php | 43 ++++----- ICAL.txt | 2 +- Models/AccountExternal.php | 44 +++++---- Models/AccountExternalMapper.php | 6 +- Models/Address.php | 94 ------------------ Models/AddressMapper.php | 12 ++- Models/ApiKey.php | 2 +- Models/NullAddress.php | 46 --------- tests/Models/AddressMapperTest.php | 8 +- tests/Models/AddressTest.php | 147 ----------------------------- tests/Models/NullAddressTest.php | 52 ---------- 12 files changed, 95 insertions(+), 399 deletions(-) delete mode 100755 Models/Address.php delete mode 100755 Models/NullAddress.php delete mode 100755 tests/Models/AddressTest.php delete mode 100755 tests/Models/NullAddressTest.php diff --git a/Admin/Install/db.json b/Admin/Install/db.json index 90bf209..ad9bbcf 100755 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -96,8 +96,8 @@ "type": "VARCHAR(255)", "null": false }, - "address_addition": { - "name": "address_addition", + "address_fao": { + "name": "address_fao", "type": "VARCHAR(255)", "null": false }, @@ -106,6 +106,11 @@ "type": "VARCHAR(255)", "null": false }, + "address_addition": { + "name": "address_addition", + "type": "VARCHAR(255)", + "null": false + }, "address_postal": { "name": "address_postal", "type": "VARCHAR(30)", @@ -1602,18 +1607,28 @@ "type": "INT", "null": false }, - "account_external_key": { - "name": "account_external_key", - "type": "VARCHAR(255)", - "null": false - }, "account_external_name": { "name": "account_external_name", "type": "VARCHAR(255)", "null": false }, - "account_external_auth": { - "name": "account_external_auth", + "account_external_uid": { + "name": "account_external_uid", + "type": "VARCHAR(255)", + "null": false + }, + "account_external_login": { + "name": "account_external_login", + "type": "VARCHAR(255)", + "null": false + }, + "account_external_password": { + "name": "account_external_password", + "type": "VARCHAR(255)", + "null": false + }, + "account_external_key": { + "name": "account_external_key", "type": "VARCHAR(255)", "null": false }, @@ -1875,11 +1890,6 @@ "primary": true, "autoincrement": true }, - "account_api_status": { - "name": "account_api_status", - "type": "TINYINT", - "null": false - }, "account_api_key": { "name": "account_api_key", "type": "VARCHAR(129)", diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 9bf250c..350dea5 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -298,12 +298,12 @@ final class ApiController extends Controller $mail->setFrom($emailSettings[SettingsEnum::MAIL_SERVER_ADDR]->content); $mail->addTo($account->email); - // @todo: load default l11n if no translation is available + // @todo load default l11n if no translation is available $mailL11n = $mail->getL11nByLanguage($response->header->l11n->language); $mail->subject = $mailL11n->subject; - // @todo: improve, the /tld link could be api.myurl.com which of course is not the url of the respective app. + // @todo improve, the /tld link could be api.myurl.com which of course is not the url of the respective app. // Maybe store the uri in the $app model? or store all urls in the config file $mail->body = \str_replace( [ @@ -440,12 +440,12 @@ final class ApiController extends Controller $mail->setFrom($emailSettings[SettingsEnum::MAIL_SERVER_ADDR]->content); $mail->addTo($account->email); - // @todo: load default l11n if no translation is available + // @todo load default l11n if no translation is available $mailL11n = $mail->getL11nByLanguage($response->header->l11n->language); $mail->subject = $mailL11n->subject; - // @todo: improve, the /tld link could be api.myurl.com which of course is not the url of the respective app. + // @todo improve, the /tld link could be api.myurl.com which of course is not the url of the respective app. // Maybe store the uri in the $app model? or store all urls in the config file $mail->body = \str_replace( [ @@ -1877,12 +1877,12 @@ final class ApiController extends Controller $mail->setFrom($emailSettings[SettingsEnum::MAIL_SERVER_ADDR]->content); $mail->addTo((string) $request->getData('email')); - // @todo: load default l11n if no translation is available + // @todo load default l11n if no translation is available $mailL11n = $mail->getL11nByLanguage($response->header->l11n->language); $mail->subject = $mailL11n->subject; - // @todo: improve, the /tld link could be api.myurl.com which of course is not the url of the respective app. + // @todo improve, the /tld link could be api.myurl.com which of course is not the url of the respective app. // Maybe store the uri in the $app model? or store all urls in the config file $mail->body = \str_replace( [ @@ -1984,7 +1984,7 @@ final class ApiController extends Controller * @return void * * @api - * @todo: maybe move to job/workflow??? This feels very much like a job/event especially if we make the 'type' an event-trigger + * @todo maybe move to job/workflow??? This feels very much like a job/event especially if we make the 'type' an event-trigger * * @since 1.0.0 */ @@ -3238,7 +3238,7 @@ final class ApiController extends Controller * * @return App * - * @todo: implement + * @todo Implement API update function * * @since 1.0.0 */ @@ -3320,7 +3320,7 @@ final class ApiController extends Controller * * @return array * - * @todo: implement + * @todo Implement API validation function * * @since 1.0.0 */ @@ -3341,7 +3341,7 @@ final class ApiController extends Controller * * @return array * - * @todo: implement + * @todo Implement API validation function * * @since 1.0.0 */ @@ -3363,7 +3363,7 @@ final class ApiController extends Controller * * @return AccountPermission * - * @todo: implement + * @todo Implement API update function * * @since 1.0.0 */ @@ -3379,7 +3379,7 @@ final class ApiController extends Controller * * @return array * - * @todo: implement + * @todo Implement API validation function * * @since 1.0.0 */ @@ -3400,7 +3400,7 @@ final class ApiController extends Controller * * @return array * - * @todo: implement + * @todo Implement API validation function * * @since 1.0.0 */ @@ -3452,12 +3452,15 @@ final class ApiController extends Controller * * @return Contact * - * @todo: implement - * * @since 1.0.0 */ public function updateContactFromRequest(RequestAbstract $request, Contact $new) : Contact { + $new->type = $request->getDataInt('type') ?? $new->type; + $new->subtype = $request->getDataInt('subtype') ?? $new->subtype; + $new->content = $request->getDataString('content') ?? $new->content; + $new->account = $request->getDataInt('account') ?? $new->account; + return $new; } @@ -3468,7 +3471,7 @@ final class ApiController extends Controller * * @return array * - * @todo: implement + * @todo Implement API validation function * * @since 1.0.0 */ @@ -3517,7 +3520,7 @@ final class ApiController extends Controller * * @return array * - * @todo: implement + * @todo Implement API validation function * * @since 1.0.0 */ @@ -3563,7 +3566,7 @@ final class ApiController extends Controller * * @return DataChange * - * @todo: implement + * @todo implement * * @since 1.0.0 */ @@ -3579,7 +3582,7 @@ final class ApiController extends Controller * * @return array * - * @todo: implement + * @todo Implement API validation function * * @since 1.0.0 */ @@ -3628,8 +3631,6 @@ final class ApiController extends Controller * * @return array * - * @todo: implement - * * @since 1.0.0 */ private function validateDataChangeDelete(RequestAbstract $request) : array diff --git a/ICAL.txt b/ICAL.txt index 019045f..f1b55ed 100755 --- a/ICAL.txt +++ b/ICAL.txt @@ -1,6 +1,6 @@ # Individual Contributor License Agreement ("CLA") 1.0 -Thank you for your interest in Karaka-Management (the "Company"). In order to clarify the intellectual property license granted with Contributions from any person or entity, the Company must provide a Contributor License Agreement ("CLA") on file that has been made available to each Contributor. This license is for your protection as a Contributor as well as the protection of the Company and its users; it does not change your rights to use your own Contributions for any other purpose. +Thank you for your interest in Jingga e. K. (the "Company"). In order to clarify the intellectual property license granted with Contributions from any person or entity, the Company must provide a Contributor License Agreement ("CLA") on file that has been made available to each Contributor. This license is for your protection as a Contributor as well as the protection of the Company and its users; it does not change your rights to use your own Contributions for any other purpose. By contributing to the Company You accept and agree to the following terms and conditions for Your present and future Contributions submitted to the Company. In return, the Company shall not use Your Contributions in a way that is contrary to the public benefit or inconsistent with its bylaws in effect at the time of the Contribution. Except for the license granted herein to the Company and recipients of software distributed by the Company, You reserve all right, title, and interest in and to Your Contributions. diff --git a/Models/AccountExternal.php b/Models/AccountExternal.php index ffef77a..b713375 100755 --- a/Models/AccountExternal.php +++ b/Models/AccountExternal.php @@ -57,19 +57,7 @@ class AccountExternal public int $status = AccountExternalStatus::ACTIVATE; /** - * External key - * - * (e.g. user id on the external platform). - * - * @var string - * @since 1.0.0 - */ - public string $key = ''; - - /** - * External name - * - * (e.g. user name on the external platform). + * Name of the external service * * @var string * @since 1.0.0 @@ -77,14 +65,36 @@ class AccountExternal public string $name = ''; /** - * External auth - * - * (e.g. user authentication on the external platform such as password or api key). + * External uid * * @var string * @since 1.0.0 */ - public string $auth = ''; + public string $uid = ''; + + /** + * External login + * + * @var string + * @since 1.0.0 + */ + public string $login = ''; + + /** + * External password + * + * @var string + * @since 1.0.0 + */ + public string $password = ''; + + /** + * External key + * + * @var string + * @since 1.0.0 + */ + public string $key = ''; /** * Belongs to. diff --git a/Models/AccountExternalMapper.php b/Models/AccountExternalMapper.php index 0897186..028d381 100755 --- a/Models/AccountExternalMapper.php +++ b/Models/AccountExternalMapper.php @@ -40,9 +40,11 @@ class AccountExternalMapper extends DataMapperFactory 'account_external_status' => ['name' => 'account_external_status', 'type' => 'int', 'internal' => 'status'], 'account_external_type' => ['name' => 'account_external_type', 'type' => 'int', 'internal' => 'type'], 'account_external_subtype' => ['name' => 'account_external_subtype', 'type' => 'int', 'internal' => 'subtype'], - 'account_external_key' => ['name' => 'account_external_key', 'type' => 'string', 'internal' => 'key'], 'account_external_name' => ['name' => 'account_external_name', 'type' => 'string', 'internal' => 'name'], - 'account_external_auth' => ['name' => 'account_external_auth', 'type' => 'string', 'internal' => 'auth', ], + 'account_external_uid' => ['name' => 'account_external_uid', 'type' => 'string', 'internal' => 'uid', ], + 'account_external_login' => ['name' => 'account_external_login', 'type' => 'string', 'internal' => 'login', ], + 'account_external_password' => ['name' => 'account_external_password', 'type' => 'string', 'internal' => 'password', ], + 'account_external_key' => ['name' => 'account_external_key', 'type' => 'string', 'internal' => 'key'], 'account_external_account' => ['name' => 'account_external_account', 'type' => 'int', 'internal' => 'account'], ]; diff --git a/Models/Address.php b/Models/Address.php deleted file mode 100755 index 2b6874f..0000000 --- a/Models/Address.php +++ /dev/null @@ -1,94 +0,0 @@ -name; - $data['addition'] = $this->addition; - - return $data; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return $this->toArray(); - } - - /** - * {@inheritdoc} - */ - public function serialize() : string - { - return (string) \json_encode($this->jsonSerialize()); - } - - /** - * {@inheritdoc} - */ - public function unserialize(mixed $serialized) : void - { - parent::unserialize($serialized); - - if (!\is_string($serialized)) { - return; - } - - /** @var array{name:string, addition:string} $data */ - $data = \json_decode($serialized, true); - if (!\is_array($data)) { - return; - } - - $this->name = $data['name']; - $this->addition = $data['addition']; - } -} diff --git a/Models/AddressMapper.php b/Models/AddressMapper.php index 07786d3..c720a46 100755 --- a/Models/AddressMapper.php +++ b/Models/AddressMapper.php @@ -16,6 +16,7 @@ namespace Modules\Admin\Models; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; use phpOMS\Localization\Defaults\CountryMapper; +use phpOMS\Stdlib\Base\Address; /** * Address mapper class. @@ -39,8 +40,9 @@ final class AddressMapper extends DataMapperFactory public const COLUMNS = [ 'address_id' => ['name' => 'address_id', 'type' => 'int', 'internal' => 'id'], 'address_name' => ['name' => 'address_name', 'type' => 'string', 'internal' => 'name'], - 'address_addition' => ['name' => 'address_addition', 'type' => 'string', 'internal' => 'addition'], + 'address_fao' => ['name' => 'address_fao', 'type' => 'string', 'internal' => 'fao'], 'address_address' => ['name' => 'address_address', 'type' => 'string', 'internal' => 'address'], + 'address_addition' => ['name' => 'address_addition', 'type' => 'string', 'internal' => 'addressAddition'], 'address_postal' => ['name' => 'address_postal', 'type' => 'string', 'internal' => 'postal'], 'address_state' => ['name' => 'address_state', 'type' => 'string', 'internal' => 'state'], 'address_city' => ['name' => 'address_city', 'type' => 'string', 'internal' => 'city'], @@ -81,4 +83,12 @@ final class AddressMapper extends DataMapperFactory * @since 1.0.0 */ public const PRIMARYFIELD = 'address_id'; + + /** + * Model to use by the mapper. + * + * @var class-string + * @since 1.0.0 + */ + public const MODEL = Address::class; } diff --git a/Models/ApiKey.php b/Models/ApiKey.php index cf07ecd..c40d0c4 100755 --- a/Models/ApiKey.php +++ b/Models/ApiKey.php @@ -35,7 +35,7 @@ class ApiKey public int $id = 0; /** - * Names. + * Key. * * @var string * @since 1.0.0 diff --git a/Models/NullAddress.php b/Models/NullAddress.php deleted file mode 100755 index acb83da..0000000 --- a/Models/NullAddress.php +++ /dev/null @@ -1,46 +0,0 @@ -id = $id; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return ['id' => $this->id]; - } -} diff --git a/tests/Models/AddressMapperTest.php b/tests/Models/AddressMapperTest.php index 1317eb6..9005a43 100755 --- a/tests/Models/AddressMapperTest.php +++ b/tests/Models/AddressMapperTest.php @@ -14,8 +14,8 @@ declare(strict_types=1); namespace Modules\Admin\tests\Models; -use Modules\Admin\Models\Address; use Modules\Admin\Models\AddressMapper; +use phpOMS\Stdlib\Base\Address; use phpOMS\Stdlib\Base\AddressType; /** @@ -34,7 +34,8 @@ final class AddressMapperTest extends \PHPUnit\Framework\TestCase $address = new Address(); $address->name = 'name'; - $address->addition = 'addition'; + $address->fao = 'fao'; + $address->addressAddition = 'addition'; $address->postal = '0123456789'; $address->setType(AddressType::BUSINESS); $address->city = 'city'; @@ -50,7 +51,8 @@ final class AddressMapperTest extends \PHPUnit\Framework\TestCase $addressR = AddressMapper::get()->where('id', $address->id)->execute(); self::assertEquals($address->name, $addressR->name); - self::assertEquals($address->addition, $addressR->addition); + self::assertEquals($address->fao, $addressR->fao); + self::assertEquals($address->addressAddition, $addressR->addressAddition); self::assertEquals($address->getType(), $addressR->getType()); self::assertEquals($address->postal, $addressR->postal); self::assertEquals($address->address, $addressR->address); diff --git a/tests/Models/AddressTest.php b/tests/Models/AddressTest.php deleted file mode 100755 index e2120dc..0000000 --- a/tests/Models/AddressTest.php +++ /dev/null @@ -1,147 +0,0 @@ -address = new Address(); - } - - /** - * @covers Modules\Admin\Models\Address - * @group module - */ - public function testDefault() : void - { - $expected = [ - 'postal' => '', - 'city' => '', - 'country' => 'XX', - 'address' => '', - 'state' => '', - 'lat' => 0.0, - 'lon' => 0.0, - 'name' => '', - 'addition' => '', - ]; - - self::assertEquals('', $this->address->name); - self::assertEquals('', $this->address->addition); - self::assertEquals($expected, $this->address->toArray()); - self::assertEquals($expected, $this->address->jsonSerialize()); - } - - public function testToArray() : void - { - $expected = [ - 'postal' => '0123456789', - 'city' => 'city', - 'country' => 'Country', - 'address' => 'Some address here', - 'state' => 'This is a state 123', - 'lat' => 12.1, - 'lon' => 11.2, - 'name' => 'name', - 'addition' => 'addition', - ]; - - $this->address->name = 'name'; - $this->address->addition = 'addition'; - $this->address->postal = '0123456789'; - $this->address->setType(AddressType::BUSINESS); - $this->address->city = 'city'; - $this->address->address = 'Some address here'; - $this->address->state = 'This is a state 123'; - $this->address->setCountry('Country'); - $this->address->lat = 12.1; - $this->address->lon = 11.2; - - self::assertEquals($expected, $this->address->toArray()); - } - - public function testJsonSerialize() : void - { - $expected = [ - 'postal' => '0123456789', - 'city' => 'city', - 'country' => 'Country', - 'address' => 'Some address here', - 'state' => 'This is a state 123', - 'lat' => 12.1, - 'lon' => 11.2, - 'name' => 'name', - 'addition' => 'addition', - ]; - - $this->address->name = 'name'; - $this->address->addition = 'addition'; - $this->address->postal = '0123456789'; - $this->address->setType(AddressType::BUSINESS); - $this->address->city = 'city'; - $this->address->address = 'Some address here'; - $this->address->state = 'This is a state 123'; - $this->address->setCountry('Country'); - $this->address->lat = 12.1; - $this->address->lon = 11.2; - - self::assertEquals($expected, $this->address->jsonSerialize()); - self::assertEquals(\json_encode($this->address->jsonSerialize()), $this->address->serialize()); - } - - public function testUnserialize() : void - { - $expected = [ - 'postal' => '0123456789', - 'city' => 'city', - 'country' => 'Country', - 'address' => 'Some address here', - 'state' => 'This is a state 123', - 'lat' => 12.1, - 'lon' => 11.2, - 'name' => 'name', - 'addition' => 'addition', - ]; - - $this->address->unserialize(\json_encode($expected)); - self::assertEquals(\json_encode($expected), $this->address->serialize()); - } - - public function testUnserializeInvalidType() : void - { - $this->address->unserialize(true); - self::assertTrue(true); - } - - public function testUnserializeInvalidJson() : void - { - $this->address->unserialize('{{}'); - self::assertTrue(true); - } -} diff --git a/tests/Models/NullAddressTest.php b/tests/Models/NullAddressTest.php deleted file mode 100755 index f06d744..0000000 --- a/tests/Models/NullAddressTest.php +++ /dev/null @@ -1,52 +0,0 @@ -id); - } - - /** - * @covers Modules\Admin\Models\NullAddress - * @group module - */ - public function testJsonSerialize() : void - { - $null = new NullAddress(2); - self::assertEquals(['id' => 2], $null->jsonSerialize()); - } -}