bug fixes

This commit is contained in:
Dennis Eichhorn 2023-12-08 21:52:22 +00:00
parent ab8ddb8d8e
commit 0d75e685da
12 changed files with 95 additions and 399 deletions

View File

@ -96,8 +96,8 @@
"type": "VARCHAR(255)", "type": "VARCHAR(255)",
"null": false "null": false
}, },
"address_addition": { "address_fao": {
"name": "address_addition", "name": "address_fao",
"type": "VARCHAR(255)", "type": "VARCHAR(255)",
"null": false "null": false
}, },
@ -106,6 +106,11 @@
"type": "VARCHAR(255)", "type": "VARCHAR(255)",
"null": false "null": false
}, },
"address_addition": {
"name": "address_addition",
"type": "VARCHAR(255)",
"null": false
},
"address_postal": { "address_postal": {
"name": "address_postal", "name": "address_postal",
"type": "VARCHAR(30)", "type": "VARCHAR(30)",
@ -1602,18 +1607,28 @@
"type": "INT", "type": "INT",
"null": false "null": false
}, },
"account_external_key": {
"name": "account_external_key",
"type": "VARCHAR(255)",
"null": false
},
"account_external_name": { "account_external_name": {
"name": "account_external_name", "name": "account_external_name",
"type": "VARCHAR(255)", "type": "VARCHAR(255)",
"null": false "null": false
}, },
"account_external_auth": { "account_external_uid": {
"name": "account_external_auth", "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)", "type": "VARCHAR(255)",
"null": false "null": false
}, },
@ -1875,11 +1890,6 @@
"primary": true, "primary": true,
"autoincrement": true "autoincrement": true
}, },
"account_api_status": {
"name": "account_api_status",
"type": "TINYINT",
"null": false
},
"account_api_key": { "account_api_key": {
"name": "account_api_key", "name": "account_api_key",
"type": "VARCHAR(129)", "type": "VARCHAR(129)",

View File

@ -298,12 +298,12 @@ final class ApiController extends Controller
$mail->setFrom($emailSettings[SettingsEnum::MAIL_SERVER_ADDR]->content); $mail->setFrom($emailSettings[SettingsEnum::MAIL_SERVER_ADDR]->content);
$mail->addTo($account->email); $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); $mailL11n = $mail->getL11nByLanguage($response->header->l11n->language);
$mail->subject = $mailL11n->subject; $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 // Maybe store the uri in the $app model? or store all urls in the config file
$mail->body = \str_replace( $mail->body = \str_replace(
[ [
@ -440,12 +440,12 @@ final class ApiController extends Controller
$mail->setFrom($emailSettings[SettingsEnum::MAIL_SERVER_ADDR]->content); $mail->setFrom($emailSettings[SettingsEnum::MAIL_SERVER_ADDR]->content);
$mail->addTo($account->email); $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); $mailL11n = $mail->getL11nByLanguage($response->header->l11n->language);
$mail->subject = $mailL11n->subject; $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 // Maybe store the uri in the $app model? or store all urls in the config file
$mail->body = \str_replace( $mail->body = \str_replace(
[ [
@ -1877,12 +1877,12 @@ final class ApiController extends Controller
$mail->setFrom($emailSettings[SettingsEnum::MAIL_SERVER_ADDR]->content); $mail->setFrom($emailSettings[SettingsEnum::MAIL_SERVER_ADDR]->content);
$mail->addTo((string) $request->getData('email')); $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); $mailL11n = $mail->getL11nByLanguage($response->header->l11n->language);
$mail->subject = $mailL11n->subject; $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 // Maybe store the uri in the $app model? or store all urls in the config file
$mail->body = \str_replace( $mail->body = \str_replace(
[ [
@ -1984,7 +1984,7 @@ final class ApiController extends Controller
* @return void * @return void
* *
* @api * @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 * @since 1.0.0
*/ */
@ -3238,7 +3238,7 @@ final class ApiController extends Controller
* *
* @return App * @return App
* *
* @todo: implement * @todo Implement API update function
* *
* @since 1.0.0 * @since 1.0.0
*/ */
@ -3320,7 +3320,7 @@ final class ApiController extends Controller
* *
* @return array<string, bool> * @return array<string, bool>
* *
* @todo: implement * @todo Implement API validation function
* *
* @since 1.0.0 * @since 1.0.0
*/ */
@ -3341,7 +3341,7 @@ final class ApiController extends Controller
* *
* @return array<string, bool> * @return array<string, bool>
* *
* @todo: implement * @todo Implement API validation function
* *
* @since 1.0.0 * @since 1.0.0
*/ */
@ -3363,7 +3363,7 @@ final class ApiController extends Controller
* *
* @return AccountPermission * @return AccountPermission
* *
* @todo: implement * @todo Implement API update function
* *
* @since 1.0.0 * @since 1.0.0
*/ */
@ -3379,7 +3379,7 @@ final class ApiController extends Controller
* *
* @return array<string, bool> * @return array<string, bool>
* *
* @todo: implement * @todo Implement API validation function
* *
* @since 1.0.0 * @since 1.0.0
*/ */
@ -3400,7 +3400,7 @@ final class ApiController extends Controller
* *
* @return array<string, bool> * @return array<string, bool>
* *
* @todo: implement * @todo Implement API validation function
* *
* @since 1.0.0 * @since 1.0.0
*/ */
@ -3452,12 +3452,15 @@ final class ApiController extends Controller
* *
* @return Contact * @return Contact
* *
* @todo: implement
*
* @since 1.0.0 * @since 1.0.0
*/ */
public function updateContactFromRequest(RequestAbstract $request, Contact $new) : Contact 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; return $new;
} }
@ -3468,7 +3471,7 @@ final class ApiController extends Controller
* *
* @return array<string, bool> * @return array<string, bool>
* *
* @todo: implement * @todo Implement API validation function
* *
* @since 1.0.0 * @since 1.0.0
*/ */
@ -3517,7 +3520,7 @@ final class ApiController extends Controller
* *
* @return array<string, bool> * @return array<string, bool>
* *
* @todo: implement * @todo Implement API validation function
* *
* @since 1.0.0 * @since 1.0.0
*/ */
@ -3563,7 +3566,7 @@ final class ApiController extends Controller
* *
* @return DataChange * @return DataChange
* *
* @todo: implement * @todo implement
* *
* @since 1.0.0 * @since 1.0.0
*/ */
@ -3579,7 +3582,7 @@ final class ApiController extends Controller
* *
* @return array<string, bool> * @return array<string, bool>
* *
* @todo: implement * @todo Implement API validation function
* *
* @since 1.0.0 * @since 1.0.0
*/ */
@ -3628,8 +3631,6 @@ final class ApiController extends Controller
* *
* @return array<string, bool> * @return array<string, bool>
* *
* @todo: implement
*
* @since 1.0.0 * @since 1.0.0
*/ */
private function validateDataChangeDelete(RequestAbstract $request) : array private function validateDataChangeDelete(RequestAbstract $request) : array

View File

@ -1,6 +1,6 @@
# Individual Contributor License Agreement ("CLA") 1.0 # 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. 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.

View File

@ -57,19 +57,7 @@ class AccountExternal
public int $status = AccountExternalStatus::ACTIVATE; public int $status = AccountExternalStatus::ACTIVATE;
/** /**
* External key * Name of the external service
*
* (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).
* *
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
@ -77,14 +65,36 @@ class AccountExternal
public string $name = ''; public string $name = '';
/** /**
* External auth * External uid
*
* (e.g. user authentication on the external platform such as password or api key).
* *
* @var string * @var string
* @since 1.0.0 * @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. * Belongs to.

View File

@ -40,9 +40,11 @@ class AccountExternalMapper extends DataMapperFactory
'account_external_status' => ['name' => 'account_external_status', 'type' => 'int', 'internal' => 'status'], 'account_external_status' => ['name' => 'account_external_status', 'type' => 'int', 'internal' => 'status'],
'account_external_type' => ['name' => 'account_external_type', 'type' => 'int', 'internal' => 'type'], 'account_external_type' => ['name' => 'account_external_type', 'type' => 'int', 'internal' => 'type'],
'account_external_subtype' => ['name' => 'account_external_subtype', 'type' => 'int', 'internal' => 'subtype'], '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_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'], 'account_external_account' => ['name' => 'account_external_account', 'type' => 'int', 'internal' => 'account'],
]; ];

View File

@ -1,94 +0,0 @@
<?php
/**
* Jingga
*
* PHP Version 8.1
*
* @package Modules\Admin\Models
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\Admin\Models;
use phpOMS\Stdlib\Base\Location;
/**
* Address model
*
* @package Modules\Admin\Models
* @license OMS License 2.0
* @link https://jingga.app
* @since 1.0.0
*/
class Address extends Location
{
/**
* Name.
*
* @var string
* @since 1.0.0
*/
public string $name = '';
/**
* Addition.
*
* @var string
* @since 1.0.0
*/
public string $addition = '';
/**
* {@inheritdoc}
*/
public function toArray() : array
{
$data = parent::toArray();
$data['name'] = $this->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'];
}
}

View File

@ -16,6 +16,7 @@ namespace Modules\Admin\Models;
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
use phpOMS\Localization\Defaults\CountryMapper; use phpOMS\Localization\Defaults\CountryMapper;
use phpOMS\Stdlib\Base\Address;
/** /**
* Address mapper class. * Address mapper class.
@ -39,8 +40,9 @@ final class AddressMapper extends DataMapperFactory
public const COLUMNS = [ public const COLUMNS = [
'address_id' => ['name' => 'address_id', 'type' => 'int', 'internal' => 'id'], 'address_id' => ['name' => 'address_id', 'type' => 'int', 'internal' => 'id'],
'address_name' => ['name' => 'address_name', 'type' => 'string', 'internal' => 'name'], '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_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_postal' => ['name' => 'address_postal', 'type' => 'string', 'internal' => 'postal'],
'address_state' => ['name' => 'address_state', 'type' => 'string', 'internal' => 'state'], 'address_state' => ['name' => 'address_state', 'type' => 'string', 'internal' => 'state'],
'address_city' => ['name' => 'address_city', 'type' => 'string', 'internal' => 'city'], 'address_city' => ['name' => 'address_city', 'type' => 'string', 'internal' => 'city'],
@ -81,4 +83,12 @@ final class AddressMapper extends DataMapperFactory
* @since 1.0.0 * @since 1.0.0
*/ */
public const PRIMARYFIELD = 'address_id'; public const PRIMARYFIELD = 'address_id';
/**
* Model to use by the mapper.
*
* @var class-string<T>
* @since 1.0.0
*/
public const MODEL = Address::class;
} }

View File

@ -35,7 +35,7 @@ class ApiKey
public int $id = 0; public int $id = 0;
/** /**
* Names. * Key.
* *
* @var string * @var string
* @since 1.0.0 * @since 1.0.0

View File

@ -1,46 +0,0 @@
<?php
/**
* Jingga
*
* PHP Version 8.1
*
* @package Modules\Admin\Models
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\Admin\Models;
/**
* Null model
*
* @package Modules\Admin\Models
* @license OMS License 2.0
* @link https://jingga.app
* @since 1.0.0
*/
final class NullAddress extends Address
{
/**
* Constructor
*
* @param int $id Model id
*
* @since 1.0.0
*/
public function __construct(int $id = 0)
{
$this->id = $id;
}
/**
* {@inheritdoc}
*/
public function jsonSerialize() : mixed
{
return ['id' => $this->id];
}
}

View File

@ -14,8 +14,8 @@ declare(strict_types=1);
namespace Modules\Admin\tests\Models; namespace Modules\Admin\tests\Models;
use Modules\Admin\Models\Address;
use Modules\Admin\Models\AddressMapper; use Modules\Admin\Models\AddressMapper;
use phpOMS\Stdlib\Base\Address;
use phpOMS\Stdlib\Base\AddressType; use phpOMS\Stdlib\Base\AddressType;
/** /**
@ -34,7 +34,8 @@ final class AddressMapperTest extends \PHPUnit\Framework\TestCase
$address = new Address(); $address = new Address();
$address->name = 'name'; $address->name = 'name';
$address->addition = 'addition'; $address->fao = 'fao';
$address->addressAddition = 'addition';
$address->postal = '0123456789'; $address->postal = '0123456789';
$address->setType(AddressType::BUSINESS); $address->setType(AddressType::BUSINESS);
$address->city = 'city'; $address->city = 'city';
@ -50,7 +51,8 @@ final class AddressMapperTest extends \PHPUnit\Framework\TestCase
$addressR = AddressMapper::get()->where('id', $address->id)->execute(); $addressR = AddressMapper::get()->where('id', $address->id)->execute();
self::assertEquals($address->name, $addressR->name); 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->getType(), $addressR->getType());
self::assertEquals($address->postal, $addressR->postal); self::assertEquals($address->postal, $addressR->postal);
self::assertEquals($address->address, $addressR->address); self::assertEquals($address->address, $addressR->address);

View File

@ -1,147 +0,0 @@
<?php
/**
* Jingga
*
* PHP Version 8.1
*
* @package tests
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\Admin\tests\Models;
use Modules\Admin\Models\Address;
use phpOMS\Stdlib\Base\AddressType;
/**
* @testdox Modules\Admin\tests\Models\AddressTest: Address model
*
* @internal
*/
final class AddressTest extends \PHPUnit\Framework\TestCase
{
protected Address $address;
/**
* {@inheritdoc}
*/
protected function setUp() : void
{
$this->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);
}
}

View File

@ -1,52 +0,0 @@
<?php
/**
* Jingga
*
* PHP Version 8.1
*
* @package tests
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\Admin\tests\Models;
use Modules\Admin\Models\NullAddress;
/**
* @internal
*/
final class NullAddressTest extends \PHPUnit\Framework\TestCase
{
/**
* @covers Modules\Admin\Models\NullAddress
* @group module
*/
public function testNull() : void
{
self::assertInstanceOf('\Modules\Admin\Models\Address', new NullAddress());
}
/**
* @covers Modules\Admin\Models\NullAddress
* @group module
*/
public function testId() : void
{
$null = new NullAddress(2);
self::assertEquals(2, $null->id);
}
/**
* @covers Modules\Admin\Models\NullAddress
* @group module
*/
public function testJsonSerialize() : void
{
$null = new NullAddress(2);
self::assertEquals(['id' => 2], $null->jsonSerialize());
}
}