From 35f5c851b7ab7fc6d60e097672a0a5358af2f17d Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 26 Jan 2024 22:53:58 +0000 Subject: [PATCH] auto fixes + some impl. --- Admin/Install/Messages.php | 3 +- Admin/Install/db.json | 102 ++++-- Admin/Installer.php | 5 +- Admin/Routes/Cli.php | 4 +- Admin/Routes/Web/Api.php | 80 ++++- Admin/Routes/Web/Backend.php | 26 +- Admin/Settings/Theme/Backend/settings.tpl.php | 10 +- CONTRIBUTING.md | 164 +++++++-- Controller/ApiController.php | 326 +++++++++++++++--- Controller/BackendController.php | 20 +- Docs/Help/de/groups.md | 2 +- Docs/Help/en/groups.md | 2 +- LICENSE.txt | 2 +- Models/Account.php | 22 +- Models/AccountExternalMapper.php | 20 +- Models/AccountMapper.php | 38 +- Models/AccountPermission.php | 14 +- Models/AccountPermissionMapper.php | 32 +- Models/App.php | 8 +- Models/AppMapper.php | 12 +- Models/Contact.php | 78 +---- Models/ContactMapper.php | 16 +- Models/DataChange.php | 4 +- Models/GroupPermission.php | 14 +- Models/GroupPermissionMapper.php | 32 +- Models/LocalizationMapper.php | 30 +- Models/Module.php | 57 +-- Models/NullContact.php | 46 +++ Models/PermissionCategory.php | 6 +- .../AccountPermissionSelector/BaseView.php | 2 +- .../Components/AddressEditor/AddressView.php | 35 +- .../AddressEditor/addresses.tpl.php | 234 +++++++------ .../Components/ContactEditor/ContactView.php | 102 ++++++ .../Components/ContactEditor/contacts.tpl.php | 140 ++++++++ .../GroupTagSelectorPopupView.php | 28 +- .../GroupTagSelector/GroupTagSelectorView.php | 14 +- Theme/Backend/Lang/en.lang.php | 25 +- Theme/Backend/accounts-list.tpl.php | 10 +- ...s-single.tpl.php => accounts-view.tpl.php} | 22 +- Theme/Backend/groups-list.tpl.php | 10 +- ...ups-single.tpl.php => groups-view.tpl.php} | 6 +- Theme/Backend/modules-list.tpl.php | 2 +- Theme/Backend/modules-log.tpl.php | 2 +- Theme/Backend/modules-settings.tpl.php | 2 +- Theme/Backend/page-list.tpl.php | 16 +- Theme/Backend/settings-general.tpl.php | 10 +- tests/Autoloader.php | 4 +- tests/Bootstrap.php | 71 ++-- .../Api/ApiControllerAccountTrait.php | 25 +- .../Api/ApiControllerApplicationTrait.php | 3 +- .../Api/ApiControllerGroupTrait.php | 19 +- .../Api/ApiControllerModuleTrait.php | 11 +- .../Api/ApiControllerPermissionTrait.php | 27 +- .../Api/ApiControllerSettingsTrait.php | 13 +- tests/Controller/ApiControllerTest.php | 14 +- tests/Helper.php | 4 +- tests/Models/AccountMapperTest.php | 14 +- tests/Models/AddressMapperTest.php | 16 +- tests/Models/ModuleTest.php | 18 +- 59 files changed, 1369 insertions(+), 705 deletions(-) create mode 100644 Models/NullContact.php create mode 100644 Theme/Backend/Components/ContactEditor/ContactView.php create mode 100644 Theme/Backend/Components/ContactEditor/contacts.tpl.php rename Theme/Backend/{accounts-single.tpl.php => accounts-view.tpl.php} (98%) mode change 100755 => 100644 rename Theme/Backend/{groups-single.tpl.php => groups-view.tpl.php} (99%) mode change 100755 => 100644 diff --git a/Admin/Install/Messages.php b/Admin/Install/Messages.php index ab699a6..91403b5 100755 --- a/Admin/Install/Messages.php +++ b/Admin/Install/Messages.php @@ -18,7 +18,6 @@ use Modules\Admin\Models\SettingsEnum; use phpOMS\Application\ApplicationAbstract; use phpOMS\Message\Http\HttpRequest; use phpOMS\Message\Http\HttpResponse; -use phpOMS\Uri\HttpUri; /** * Media class. @@ -75,7 +74,7 @@ class Messages ]; $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('settings', \json_encode($settings)); diff --git a/Admin/Install/db.json b/Admin/Install/db.json index f974112..d1fc48f 100755 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -188,6 +188,11 @@ "type": "TINYINT(1)", "null": false }, + "address_attr_type_internal": { + "name": "address_attr_type_internal", + "type": "TINYINT(1)", + "null": false + }, "address_attr_type_required": { "description": "Every address must have this attribute type if set to true.", "name": "address_attr_type_required", @@ -871,6 +876,11 @@ "type": "TINYINT(1)", "null": false }, + "unit_attr_type_internal": { + "name": "unit_attr_type_internal", + "type": "TINYINT(1)", + "null": false + }, "unit_attr_type_required": { "description": "Every unit must have this attribute type if set to true.", "name": "unit_attr_type_required", @@ -1399,6 +1409,11 @@ "type": "TINYINT(1)", "null": false }, + "account_attr_type_internal": { + "name": "account_attr_type_internal", + "type": "TINYINT(1)", + "null": false + }, "account_attr_type_required": { "description": "Every account must have this attribute type if set to true.", "name": "account_attr_type_required", @@ -1656,50 +1671,35 @@ } } }, - "account_contact": { - "name": "account_contact", + "contact": { + "name": "contact", "fields": { - "account_contact_id": { - "name": "account_contact_id", + "contact_id": { + "name": "contact_id", "type": "INT", "null": false, "primary": true, "autoincrement": true }, - "account_contact_type": { - "name": "account_contact_type", - "type": "TINYINT", - "null": false - }, - "account_contact_subtype": { - "name": "account_contact_subtype", - "type": "TINYINT", - "null": false - }, - "account_contact_order": { - "name": "account_contact_order", - "type": "INT", - "null": false - }, - "account_contact_content": { - "name": "account_contact_content", + "contact_title": { + "name": "contact_title", "type": "VARCHAR(255)", "null": false }, - "account_contact_module": { - "name": "account_contact_module", - "type": "VARCHAR(190)", - "null": true, - "default": null, - "foreignTable": "module", - "foreignKey": "module_id" + "contact_type": { + "name": "contact_type", + "type": "TINYINT", + "null": false }, - "account_contact_account": { - "name": "account_contact_account", - "type": "INT", - "null": false, - "foreignTable": "account", - "foreignKey": "account_id" + "contact_subtype": { + "name": "contact_subtype", + "type": "TINYINT", + "null": false + }, + "contact_content": { + "name": "contact_content", + "type": "VARCHAR(255)", + "null": false } } }, @@ -1737,6 +1737,40 @@ } } }, + "account_contact_rel": { + "name": "account_contact_rel", + "fields": { + "account_contact_rel_id": { + "name": "account_contact_rel_id", + "type": "INT", + "null": false, + "primary": true, + "autoincrement": true + }, + "account_contact_rel_account": { + "name": "account_contact_rel_account", + "type": "INT", + "null": false, + "foreignTable": "account", + "foreignKey": "account_id" + }, + "account_contact_rel_module": { + "name": "account_contact_rel_module", + "type": "VARCHAR(190)", + "null": true, + "default": null, + "foreignTable": "module", + "foreignKey": "module_id" + }, + "account_contact_rel_contact": { + "name": "account_contact_rel_contact", + "type": "INT", + "null": false, + "foreignTable": "contact", + "foreignKey": "contact_id" + } + } + }, "account_account_rel": { "description": "Accounts can belong to other accounts. E.g. a user can belong to a company account", "name": "account_account_rel", diff --git a/Admin/Installer.php b/Admin/Installer.php index 24100d7..dc98bf1 100755 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -31,7 +31,6 @@ use phpOMS\Module\ModuleInfo; use phpOMS\System\File\PathException; use phpOMS\System\OperatingSystem; use phpOMS\System\SystemType; -use phpOMS\Uri\HttpUri; /** * Installer class. @@ -287,13 +286,13 @@ final class Installer extends InstallerAbstract * * @since 1.0.0 */ - private static function createSettings(ApplicationAbstract $app, array $data) : array + public static function createSettings(ApplicationAbstract $app, array $data) : array { /** @var \Modules\Admin\Controller\ApiController $module */ $module = $app->moduleManager->get('Admin'); $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('id', $data['id'] ?? 0); diff --git a/Admin/Routes/Cli.php b/Admin/Routes/Cli.php index d13a6a9..eeaaece 100755 --- a/Admin/Routes/Cli.php +++ b/Admin/Routes/Cli.php @@ -10,13 +10,13 @@ return [ 'verb' => RouteVerb::ANY, ], ], - '^/admin/event.*$' => [ + '^/admin/event(\?.*$|$)' => [ [ 'dest' => '\Modules\Admin\Controller\CliController:cliRunEvent', 'verb' => RouteVerb::ANY, ], ], - '^/admin/encryption/change.*$' => [ + '^/admin/encryption/change(\?.*$|$)' => [ [ 'dest' => '\Modules\Admin\Controller\CliController:cliEncryptionChange', 'verb' => RouteVerb::ANY, diff --git a/Admin/Routes/Web/Api.php b/Admin/Routes/Web/Api.php index 9530d96..6761ca9 100755 --- a/Admin/Routes/Web/Api.php +++ b/Admin/Routes/Web/Api.php @@ -153,7 +153,7 @@ return [ ], ], ], - '^.*/admin/find/group.*$' => [ + '^.*/admin/find/group(\?.*$|$)' => [ [ 'dest' => '\Modules\Admin\Controller\ApiController:apiGroupFind', 'verb' => RouteVerb::GET, @@ -164,7 +164,7 @@ return [ ], ], ], - '^.*/admin/find/accgrp.*$' => [ + '^.*/admin/find/accgrp(\?.*$|$)' => [ [ 'dest' => '\Modules\Admin\Controller\ApiController:apiAccountGroupFind', 'verb' => RouteVerb::GET, @@ -226,7 +226,7 @@ return [ ], ], - '^.*/admin/module/status.*$' => [ + '^.*/admin/module/status(\?.*$|$)' => [ [ 'dest' => '\Modules\Admin\Controller\ApiController:apiModuleStatusUpdate', 'verb' => RouteVerb::SET, @@ -238,7 +238,7 @@ return [ ], ], - '^.*/admin/group/account.*$' => [ + '^.*/admin/group/account(\?.*$|$)' => [ [ 'dest' => '\Modules\Admin\Controller\ApiController:apiAddAccountToGroup', 'verb' => RouteVerb::PUT, @@ -249,7 +249,7 @@ return [ ], ], ], - '^.*/admin/account/group.*$' => [ + '^.*/admin/account/group(\?.*$|$)' => [ [ 'dest' => '\Modules\Admin\Controller\ApiController:apiAddGroupToAccount', 'verb' => RouteVerb::PUT, @@ -261,7 +261,7 @@ return [ ], ], - '^.*/admin/group/permission.*$' => [ + '^.*/admin/group/permission(\?.*$|$)' => [ [ 'dest' => '\Modules\Admin\Controller\ApiController:apiGroupPermissionGet', 'verb' => RouteVerb::PUT, @@ -299,7 +299,7 @@ return [ ], ], ], - '^.*/admin/account/permission.*$' => [ + '^.*/admin/account/permission(\?.*$|$)' => [ [ 'dest' => '\Modules\Admin\Controller\ApiController:apiAccountPermissionGet', 'verb' => RouteVerb::GET, @@ -337,7 +337,7 @@ return [ ], ], ], - '^.*/admin/module/reinit.*$' => [ + '^.*/admin/module/reinit(\?.*$|$)' => [ [ 'dest' => '\Modules\Admin\Controller\ApiController:apiReInit', 'verb' => RouteVerb::GET, @@ -349,7 +349,7 @@ return [ ], ], - '^.*/admin/update/url.*$' => [ + '^.*/admin/update/url(\?.*$|$)' => [ [ 'dest' => '\Modules\Admin\Controller\ApiController:apiUpdateFile', 'verb' => RouteVerb::GET, @@ -360,7 +360,7 @@ return [ ], ], ], - '^.*/admin/update/check.*$' => [ + '^.*/admin/update/check(\?.*$|$)' => [ [ 'dest' => '\Modules\Admin\Controller\ApiController:apiCheckForUpdates', 'verb' => RouteVerb::PUT, @@ -371,7 +371,7 @@ return [ ], ], ], - '^.*/admin/update/component.*$' => [ + '^.*/admin/update/component(\?.*$|$)' => [ [ 'dest' => '\Modules\Admin\Controller\ApiController:apiCheckForUpdates', 'verb' => RouteVerb::PUT, @@ -382,4 +382,62 @@ return [ ], ], ], + '^.*/account/address$' => [ + [ + 'dest' => '\Modules\Admin\Controller\ApiAttributeController:apiAddressCreate', + 'verb' => RouteVerb::PUT, + 'permission' => [ + 'module' => ApiController::NAME, + 'type' => PermissionType::CREATE, + 'state' => PermissionCategory::ADDRESS, + ], + ], + [ + 'dest' => '\Modules\Admin\Controller\ApiAttributeController:apiAddressUpdate', + 'verb' => RouteVerb::SET, + 'permission' => [ + 'module' => ApiController::NAME, + 'type' => PermissionType::MODIFY, + 'state' => PermissionCategory::ADDRESS, + ], + ], + [ + 'dest' => '\Modules\Admin\Controller\ApiAttributeController:apiAddressDelete', + 'verb' => RouteVerb::DELETE, + 'permission' => [ + 'module' => ApiController::NAME, + 'type' => PermissionType::DELETE, + 'state' => PermissionCategory::ADDRESS, + ], + ], + ], + '^.*/account/contact$' => [ + [ + 'dest' => '\Modules\Admin\Controller\ApiAttributeController:apiContactCreate', + 'verb' => RouteVerb::PUT, + 'permission' => [ + 'module' => ApiController::NAME, + 'type' => PermissionType::CREATE, + 'state' => PermissionCategory::ADDRESS, + ], + ], + [ + 'dest' => '\Modules\Admin\Controller\ApiAttributeController:apiContactUpdate', + 'verb' => RouteVerb::SET, + 'permission' => [ + 'module' => ApiController::NAME, + 'type' => PermissionType::MODIFY, + 'state' => PermissionCategory::ADDRESS, + ], + ], + [ + 'dest' => '\Modules\Admin\Controller\ApiAttributeController:apiContactDelete', + 'verb' => RouteVerb::DELETE, + 'permission' => [ + 'module' => ApiController::NAME, + 'type' => PermissionType::DELETE, + 'state' => PermissionCategory::ADDRESS, + ], + ], + ], ]; diff --git a/Admin/Routes/Web/Backend.php b/Admin/Routes/Web/Backend.php index 993df12..061a62a 100755 --- a/Admin/Routes/Web/Backend.php +++ b/Admin/Routes/Web/Backend.php @@ -18,7 +18,7 @@ use phpOMS\Account\PermissionType; use phpOMS\Router\RouteVerb; return [ - '^.*/forgot.*$' => [ + '^.*/forgot(\?.*$|$)' => [ [ 'dest' => '\Modules\Admin\Controller\BackendController:viewForgot', 'verb' => RouteVerb::GET, @@ -27,7 +27,7 @@ return [ ], ], - '^.*/admin/module/settings.*$' => [ + '^.*/admin/module/settings(\?.*$|$)' => [ [ 'dest' => '\Modules\Admin\Controller\BackendController:viewModuleSettings', 'verb' => RouteVerb::GET, @@ -39,7 +39,7 @@ return [ ], ], - '^.*/admin/account/list.*$' => [ + '^.*/admin/account/list(\?.*$|$)' => [ [ 'dest' => '\Modules\Admin\Controller\BackendController:viewAccountList', 'verb' => RouteVerb::GET, @@ -50,7 +50,7 @@ return [ ], ], ], - '^.*/admin/account/settings.*$' => [ + '^.*/admin/account/settings(\?.*$|$)' => [ [ 'dest' => '\Modules\Admin\Controller\BackendController:viewAccountSettings', 'verb' => RouteVerb::GET, @@ -61,7 +61,7 @@ return [ ], ], ], - '^.*/admin/account/create.*$' => [ + '^.*/admin/account/create(\?.*$|$)' => [ [ 'dest' => '\Modules\Admin\Controller\BackendController:viewAccountCreate', 'verb' => RouteVerb::GET, @@ -72,7 +72,7 @@ return [ ], ], ], - '^.*/admin/group/list.*$' => [ + '^.*/admin/group/list(\?.*$|$)' => [ [ 'dest' => '\Modules\Admin\Controller\BackendController:viewGroupList', 'verb' => RouteVerb::GET, @@ -83,7 +83,7 @@ return [ ], ], ], - '^.*/admin/group/settings.*$' => [ + '^.*/admin/group/settings(\?.*$|$)' => [ [ 'dest' => '\Modules\Admin\Controller\BackendController:viewGroupSettings', 'verb' => RouteVerb::GET, @@ -94,7 +94,7 @@ return [ ], ], ], - '^.*/admin/group/create.*$' => [ + '^.*/admin/group/create(\?.*$|$)' => [ [ 'dest' => '\Modules\Admin\Controller\BackendController:viewGroupCreate', 'verb' => RouteVerb::GET, @@ -105,7 +105,7 @@ return [ ], ], ], - '^.*/admin/module/list.*$' => [ + '^.*/admin/module/list(\?.*$|$)' => [ [ 'dest' => '\Modules\Admin\Controller\BackendController:viewModuleList', 'verb' => RouteVerb::GET, @@ -116,7 +116,7 @@ return [ ], ], ], - '^.*/admin/module/info\?.*$' => [ + '^.*/admin/module/info(\?.*$|$)' => [ [ 'dest' => '\Modules\Admin\Controller\BackendController:viewModuleInfo', 'verb' => RouteVerb::GET, @@ -127,7 +127,7 @@ return [ ], ], ], - '^.*/admin/module/log\?.*$' => [ + '^.*/admin/module/log(\?.*$|$)' => [ [ 'dest' => '\Modules\Admin\Controller\BackendController:viewModuleLog', 'verb' => RouteVerb::GET, @@ -138,7 +138,7 @@ return [ ], ], ], - '^.*/admin/module/route/list\?.*$' => [ + '^.*/admin/module/route/list(\?.*$|$)' => [ [ 'dest' => '\Modules\Admin\Controller\BackendController:viewModuleRouteList', 'verb' => RouteVerb::GET, @@ -149,7 +149,7 @@ return [ ], ], ], - '^.*/admin/module/hook/list\?.*$' => [ + '^.*/admin/module/hook/list(\?.*$|$)' => [ [ 'dest' => '\Modules\Admin\Controller\BackendController:viewModuleHookList', 'verb' => RouteVerb::GET, diff --git a/Admin/Settings/Theme/Backend/settings.tpl.php b/Admin/Settings/Theme/Backend/settings.tpl.php index 7b8e1a2..9811e4a 100755 --- a/Admin/Settings/Theme/Backend/settings.tpl.php +++ b/Admin/Settings/Theme/Backend/settings.tpl.php @@ -37,7 +37,7 @@ $temperatures = \phpOMS\Utils\Converter\TemperatureType::getConstants(); $serverModes = ApplicationStatus::getConstants(); -$l11n = $this->getData('default_localization') ?? new NullLocalization(); +$l11n = $this->data['default_localization'] ?? new NullLocalization(); echo $this->data['nav']->render(); ?> @@ -288,7 +288,7 @@ echo $this->data['nav']->render(); @@ -296,8 +296,8 @@ echo $this->data['nav']->render();
@@ -806,7 +806,7 @@ echo $this->data['nav']->render(); $name = $this->getData('settings_class')::getName($setting->name); if (!\is_string($name)) { - $name= $setting->name; + $name = $setting->name; } } ?> diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4f4653b..88c5d9c 100755 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,12 +1,16 @@ -# Development - ## Development environment - The setup and configuration of the development environment is in the hands of every developer themselves. However, it is recommended to follow the setup instructions in the [Developer-Guide](https://github.com/Karaka-Management/Developer-Guide/blob/develop/general/setup.md). +The setup and configuration of the development environment is in the hands of every developer themselves. However, it is recommended to follow the setup instructions in the [Developer-Guide](https://github.com/Karaka-Management/Developer-Guide/blob/develop/general/setup.md). ## Code of conduct -Every organization member and contributor to the organization must follow the [code of conduct](../Policies & Guidelines/Code of conduct.md). +Every organization member and contributor to the organization must follow the [Code of Conduct](../Policies%20&%20Guidelines/Code%20of%20Conduct.md). + +## Becoming a contributor + +For public repositories you can immediately start by creating forks and pull requests. For private repositories which are necessary to setup the complete developer environment, feel free to request access. Please not that we may not immediately give you access to private repositories and instead will give you smaller tasks regarding public repositories. Please contact info@jingga.app for more details. (**R1**) + +For all contributions our [Contributor License Agreement "CLA"](https://github.com/Karaka-Management/Organization-Guide/blob/master/Processes/HR/Hiring/Individual%20Contributor%20License%20Agreement.md) comes into effect. (**R2**) ## Code changes @@ -14,58 +18,106 @@ Every organization member and contributor to the organization must follow the [c Generally, the development philosophy is result orientated. This means that anyone can propose tasks, pick up existing tasks or right away implement their code changes. However, implementing code changes without consulting with a senior developer in advance has a much higher risk of code changes not getting admitted. The easiest way to discuss a code change idea in advance are the github [issues](https://github.com/Karaka-Management/Karaka/issues) or [discussions](https://github.com/Karaka-Management/Karaka/discussions). -Developers are encouraged to pick open tasks with high priorities according to their own skill level. Senior developers may directly assign tasks to developers based on their importance. New developers may find it easier to start with a task that has a low priority as they often also have a lower difficulty. +Developers are encouraged to pick open tasks with high priorities according to their own skill level. Senior developers may directly assign tasks to developers based on their importance. New developers may find it easier to start with a task that has a low priority as they often also have a lower difficulty. -Open tasks can be found in the project overview: [PROJECT.md](https://github.com/orgs/Karaka-Management/projects/10) +Open tasks can be found in the project overview: [Todos](https://github.com/orgs/Karaka-Management/projects/10) -Tasks currently in development are prefixed in the priority column with an asterisk `*` and a name tag in the task description of the developer who is working on the task. +Tasks currently in development are prefixed in the priority column with an asterisk `*` and a name tag in the task description of the developer who is working on the task. -The open tasks are reviewed once a month by a senior developer. The senior developer updates the project overview if necessary and requests feedback regarding development status of important tasks under development. During this process important tasks may also get directly assigned to developers. This review is performed on a judgmental bases of the senior basis. +The open tasks are reviewed once a month by a senior developer. The senior developer updates the project overview if necessary and requests feedback regarding development status of important tasks under development. During this process important tasks may also get directly assigned to developers. This review is performed on a judgmental bases of the senior basis. -### Code style +### Quality -Code changes must follow the [style guidelines](https://github.com/Karaka-Management/Developer-Guide/tree/develop/standards). Additionally, the automatic code style inspection tools must return no errors, failures or warnings. Developers should test their changes with inspection tools and configurations mentioned in the [inspection documentation](https://github.com/Karaka-Management/Developer-Guide/blob/develop/quality/inspections.md) in advance before submitting them for review. +#### Code style -In rare cases errors, failures or warnings during the automatic inspection are acceptable. Reasons can be changes in the programming language, special cases which cannot, are difficult or must be individually configured in the inspection settings. If this is the case for a code change and if inspection configuration changes are necessary are decided by the senior developer performing the code review. +Code changes must follow the [style guidelines](https://github.com/Karaka-Management/Developer-Guide/tree/develop/standards) (**R3**). Additionally, the automatic code style inspection tools must return no errors, failures or warnings. Developers should test their changes with inspection tools and configurations mentioned in the [inspection documentation](https://github.com/Karaka-Management/Developer-Guide/blob/develop/quality/inspections.md) in advance before submitting them for review. (**R4**) -Automated checks which are run during the review process: +In rare cases errors, failures or warnings during the automatic inspection are acceptable. Reasons can be for example special cases which are difficult automatize or must be individually configured in the inspection settings. If this is the case for a code change and if inspection configuration changes are necessary are decided by the senior developer performing the code review. (**R5**) + +Automated checks which are run during the review process (**R4**): ```sh -php ./vendor/bin/phpcs --severity=1 ./ --standard="Build/Config/phpcs.xml" +php ./vendor/bin/phpcs ./ --standard="Build/Config/phpcs.xml" +php ./vendor/bin/php-cs-fixer fix ./ --config=Build/Config/.php-cs-fixer.php --allow-risky=yes +php ./vendor/bin/phpcbf --standard=Build/Config/phpcs.xml ./ +php ./vendor/bin/rector process --dry-run --config Build/Config/rector.php ./ npx eslint ./ -c ./Build/Config/.eslintrc.json ``` -### Tests +#### Tests -Code changes must follow the inspection guidelines (i.e. code coverage) mentioned in the [inspection documentation](https://github.com/Karaka-Management/Developer-Guide/blob/develop/quality/inspections.md). Developers should check if the code changes comply with the inspection guidelines before submitting them. +Code changes must follow the inspection guidelines (i.e. code coverage) mentioned in the [inspection documentation](https://github.com/Karaka-Management/Developer-Guide/blob/develop/quality/inspections.md) (**R6**). Developers should test their changes with inspection tools and configurations mentioned in the [inspection documentation](https://github.com/Karaka-Management/Developer-Guide/blob/develop/quality/inspections.md) in advance before submitting them for review. (**R7**) -In rare cases it might be not possible to follow the inspection guidelines. In such cases the senior developer performing the code review may decide if the code change still gets accepted. +In rare cases it might be not possible to follow the inspection guidelines. In such cases the senior developer performing the code review may decide if the code change still gets accepted. (**R8**) -Automated tests which are run during the review process: +Automated tests which are run during the review process (**R7**): ```sh php ./vendor/bin/phpunit -c tests/PHPUnit/phpunit_default.xml -php ./vendor/bin/phpstan analyse --autoload-file=phpOMS/Autoloader.php -l 9 -c Build/Config/phpstan.neon ./ +php ./vendor/bin/phpstan analyse --no-progress -l 9 -c Build/Config/phpstan.neon ./ npx jasmine-node ./ ./cOMS/tests/test.sh ``` -Additional inspections which are run but might be ignored during the review depending on the use case are mentioned in the [inspection documentation](https://github.com/Karaka-Management/Developer-Guide/blob/develop/quality/inspections.md) as other checks. +Additional inspections which are run but might be ignored during the review depending on the use case are mentioned in the [inspection documentation](https://github.com/Karaka-Management/Developer-Guide/blob/develop/quality/inspections.md) as other checks. (**R7**) -### Demo +#### Performance -Some code changes may also require changes or extensions in the demo setup scripts. The demo setup script try to simulate a real world use case by generating and modifying mostly random data. This is also a good way to setup and “manually” test the code changes in a larger picture. The demo setup script can be found in the [demoSetup](https://github.com/Karaka-Management/demoSetup) repository. The demo setup script takes a long time due to the large amount of user input simulated data which is generated. Therefore it is recommended to run this only sporadically. +Developers should occasionaly check performance statistics. At this point no target metrics are defined. -### Code review +Since the primary application is a web based application a similar tool as the Google lighthouse tool can be used to inspect the application for best practicies which can significantly improve the application performance. The sitespeed.io tool shows potential performance improvements and slow pages. With the php trace and profiler enabled in the `php.ini` file the VM automatically generates profiling and trace reports for every web request. These can be found in the webgrind logs directory and inspected in webgrind and dropped into the trace visualizer for a flame chart visualization. With mysqldumpslow you can inspect slow sql queries which may need optimization. + +1. Automatic trace and benchmark generation with every web request in `/var/www/html/webgrind/Logs` +2. Webgrind view `http://vm_ip:82` +3. Trace visualization `http://vm_ip:81` + 1. Download the latest trace from `http://vm_ip:82/Logs` + 2. Drag and drop that downloaded `*.xt` file in the trace visualizer +4. `sitespeed.io ./Build/Helper/Scripts/sitespeedDemoUrls.txt -b chrome --outputFolder /var/www/html/sitespeed` +5. Slow query inspection. + +```sh +mysqldumpslow -t 10 /var/log/mysql/mysql-slow.log +mysqldumpslow -t 10 -s l /var/log/mysql/mysql-slow.log +``` + +#### Code review In addition to the automatic code review performed by the various inspection tools such as (phpcs, phpstan, phpunit, eslint and custom scripts) a senior developer must check the proposed code change before it is merged with the respective `develop` branch. Only upon the approval by the reviewer a code change requests gets merged as no other developers have permission in the software to make such code merges. In case a code change request is not approved the reviewer states the reason for the decision, this may include some tips and requests which will allow the contributor to make improvements so that the code change may get approved. -If the code reviewer only finds minor issues with the proposed code change the reviewer may make small changes to the proposed code change and inform the contributor to speed up the implementation process. Code reviewers are encouraged to do this with new contributors to avoid long iteration processes and to not discourage new developers. However, communication is key and severe issues with code change requests or if the contributor already made multiple code change requests in the past the reviewer should not implement the improvements by himself and rather decline the code change requests with his reasoning. +If the code reviewer only finds minor issues with the proposed code change the reviewer may make small changes to the proposed code change and inform the contributor to speed up the implementation process. Code reviewers are encouraged to do this with new contributors to avoid long iteration processes and to not discourage new developers. However, communication is key and severe issues with code change requests or if the contributor already made multiple code change requests in the past the reviewer should not implement the improvements by himself and rather decline the code change requests with his reasoning. (**R5**+**R8**) + +#### Demo + +Some code changes may also require changes or extensions in the demo setup scripts. The demo setup script try to simulate a real world use case by generating and modifying mostly random data. This is also a good way to setup and “manually” test the code changes in a larger picture. The demo setup script can be found in the [demoSetup](https://github.com/Karaka-Management/demoSetup) repository. The demo setup script takes a long time due to the large amount of user input simulated data which is generated. Therefore it is recommended to run this only sporadically. (**R9**) + +```sh +sudo -u www-data php -dxdebug.remote_enable=1 -dxdebug.start_with_request=yes -dxdebug.mode=coverage,develop,debug demoSetup/setup.php +``` + +#### Documentation + +Occasionally new code or code changes also require new documentation or documentation changes. Developers should make sure that the new code is also reflected in the existing documentation ([Developer-Guide](), [User-Guide]() and/or module documentation) or if additional documentation is necessary. + +#### Improvements, features, bugs + +If a developer (or employee in general) has an idea for an improvement, feature or finds a potential bug it should be reported at https://github.com/Karaka-Management/Karaka/issues. A senior developer has to check these issues and decide how to proceed with them. The decision how to proceed with the issue must be explained by the senior developer as a response in the issue. Possible steps are: + +* Accept the issue and put the task into the [Todos](https://github.com/orgs/Karaka-Management/projects/10) +* Dismiss the issue with an explanation ### Release flow +In case SCSS/CSS or JS files got changed they must get re-built locally before comitting the code change: + +```sh +npx esbuild Web/Backend/js/backend.js --bundle --outfile=Install/Application/Backend/js/backend.min.js --minify +scss cssOMS/styles.scss > cssOMS/styles.css +``` + +For JS you may also use the shorthand command `npm run build`. + Code changes must be performed in a new branch. A new branch can be created with: ```sh @@ -75,8 +127,70 @@ git checkout -b new-branch-name The name of the branch can be chosen freely however it is recommended to follow the following branch naming conventions: * `feature-*` for feature implementations +* `hotfix-*` for security related fixes/improvements * `bug-*` for bug fixes * `security-*` for security related fixes/improvements -* `general-*` for general improvements (i.e. code documentation improvements, code style improvements) +* `general-*` for general improvements (i.e. documentation, code style & performance improvements) -The senior developer who performs the code review merges the change request into the `develop` branch upon approval. \ No newline at end of file +```mermaid +%%{init: { 'gitGraph': {'mainBranchName': 'master'}} }%% + gitGraph + commit + branch hotfix-xxx + commit + checkout master + branch develop + checkout master + merge hotfix-xxx + checkout develop + branch bug-xxx + commit + commit + checkout hotfix-xxx + commit + checkout master + merge hotfix-xxx + checkout develop + merge bug-xxx + commit + checkout develop + branch feature-xxx + commit + commit + commit + checkout develop + merge feature-xxx + checkout master + merge develop + checkout develop + branch general-xxx + commit + checkout develop + merge general-xxx + branch security-xxx + commit + commit + checkout develop + merge security-xxx + checkout master + merge develop + +``` + +The senior developer who performs the code review merges the change request into the `develop` branch after their successful code review. Unsuccessful reviews lead to change requests by the original developer, other developers who can make the requested changes, changes by the senior developer who performed the review, or dismissal of the changed code. (**R10**) + +## Approved dependencies + +### Customer dependencies + +Developers may only rely on the dependencies defined in [Approved Customer Software]() when developing a solution. If new software should be added to this list or a different version is required developers should make a request with their team leader/head of department who forwards this requests if appropriate to the CTO and explain the reasoning for the different dependency needs. The CTO can decide if the dependency will be accepted. (**R11**) + +### Developer dependencies + +Developers may only rely on the dependencies defined in [IT Equipment & Software](). If new software should be added to this list or a different version is required developers should make a request with their team leader/head of department who forwards this requests if appropriate to the CTO and explain the reasoning for the different dependency needs. The CTO can decide if the dependency will be accepted. Changing the package managers such as `composer.json` or `package.json` is not allowed by anyone else than the CTO. (**R12**) + +## Other related documents + +* [Confidentiality Policy](../Policies%20&%20Guidelines/Confidentiality%20Policy.md) +* [Organization Activity Policy](../Policies%20&%20Guidelines/Organization%20Activity%20Policy.md) +* [Tutorials](./Development/Tutorials) \ No newline at end of file diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 64dc741..1ee4873 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -21,10 +21,12 @@ use Modules\Admin\Models\AccountCredentialMapper; use Modules\Admin\Models\AccountMapper; use Modules\Admin\Models\AccountPermission; use Modules\Admin\Models\AccountPermissionMapper; +use Modules\Admin\Models\AddressMapper; use Modules\Admin\Models\App; use Modules\Admin\Models\AppMapper; use Modules\Admin\Models\Contact; use Modules\Admin\Models\ContactMapper; +use Modules\Admin\Models\ContactType; use Modules\Admin\Models\DataChange; use Modules\Admin\Models\DataChangeMapper; use Modules\Admin\Models\Group; @@ -48,11 +50,13 @@ use phpOMS\Account\GroupStatus; use phpOMS\Account\PermissionAbstract; use phpOMS\Account\PermissionOwner; use phpOMS\Account\PermissionType; +use phpOMS\Api\Geocoding\Nominatim; use phpOMS\Application\ApplicationInfo; use phpOMS\Application\ApplicationManager; use phpOMS\Application\ApplicationType; use phpOMS\Auth\LoginReturnType; use phpOMS\DataStorage\Database\Query\Builder; +use phpOMS\Localization\ISO3166TwoEnum; use phpOMS\Localization\Localization; use phpOMS\Message\Http\HttpRequest; use phpOMS\Message\Http\HttpResponse; @@ -70,6 +74,8 @@ use phpOMS\Model\Message\Reload; use phpOMS\Module\ModuleInfo; use phpOMS\Module\ModuleStatus; use phpOMS\Security\EncryptionHelper; +use phpOMS\Stdlib\Base\Address; +use phpOMS\Stdlib\Base\AddressType; use phpOMS\System\File\Local\File; use phpOMS\System\MimeType; use phpOMS\Uri\HttpUri; @@ -627,11 +633,11 @@ final class ApiController extends Controller $new->content = $new->isEncrypted && !empty($content) && !empty($_SERVER['OMS_PRIVATE_KEY_I'] ?? '') ? EncryptionHelper::encryptShared($content, $_SERVER['OMS_PRIVATE_KEY_I']) : $content ?? $new->content; - $new->unit = $unit ?? $new->unit; - $new->app = $app ?? $new->app; - $new->module = $module ?? $new->module; - $new->group = $group ?? $new->group; - $new->account = $account ?? $new->account; + $new->unit = $unit ?? $new->unit; + $new->app = $app ?? $new->app; + $new->module = $module ?? $new->module; + $new->group = $group ?? $new->group; + $new->account = $account ?? $new->account; $this->app->appSettings->set([$new], false); @@ -864,7 +870,7 @@ final class ApiController extends Controller $dataSettings = $request->getLike('settings_(.*)'); $account->l11n->setCountry($dataSettings['settings_country']); - $account->l11n->setLanguage($dataSettings['settings_language']); + $account->l11n->language = $dataSettings['settings_language']; $account->l11n->setTemperature($dataSettings['settings_temperature']); $account->l11n->setTimezone($dataSettings['settings_timezone']); @@ -878,7 +884,7 @@ final class ApiController extends Controller ] ); - $account->l11n->setCurrency($dataSettings['settings_currency']); + $account->l11n->currency = $dataSettings['settings_currency']; $account->l11n->setCurrencyFormat($dataSettings['settings_currencyformat']); $account->l11n->setDecimal($dataSettings['settings_decimal']); @@ -1074,7 +1080,7 @@ final class ApiController extends Controller { $app = new App(); $app->name = $request->getDataString('name') ?? ''; - $app->type = $request->getDataInt('type') ?? ApplicationType::WEB; + $app->type = ApplicationType::tryFromValue($request->getDataInt('type')) ?? ApplicationType::WEB; $app->defaultUnit = $request->getDataInt('default_unit'); return $app; @@ -1200,8 +1206,8 @@ final class ApiController extends Controller */ private function updateGroupFromRequest(RequestAbstract $request, Group $group) : Group { - $group->name = $request->getDataString('name') ?? $group->name; - $group->setStatus($request->getDataInt('status') ?? $group->getStatus()); + $group->name = $request->getDataString('name') ?? $group->name; + $group->status = GroupStatus::tryFromValue($request->getDataInt('status')) ?? $group->status; $group->description = Markdown::parse($request->getDataString('description') ?? $group->descriptionRaw); $group->descriptionRaw = $request->getDataString('description') ?? $group->descriptionRaw; @@ -1267,10 +1273,10 @@ final class ApiController extends Controller */ private function createGroupFromRequest(RequestAbstract $request) : Group { - $group = new Group(); - $group->createdBy = new NullAccount($request->header->account); - $group->name = $request->getDataString('name') ?? ''; - $group->setStatus($request->getDataInt('status') ?? GroupStatus::INACTIVE); + $group = new Group(); + $group->createdBy = new NullAccount($request->header->account); + $group->name = $request->getDataString('name') ?? ''; + $group->status = GroupStatus::tryFromValue($request->getDataInt('status')) ?? GroupStatus::INACTIVE; $group->description = Markdown::parse($request->getDataString('description') ?? ''); $group->descriptionRaw = $request->getDataString('description') ?? ''; @@ -1394,7 +1400,7 @@ final class ApiController extends Controller public function apiAccountFind(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void { /** @var \Modules\Admin\Models\Account[] $accounts */ - $accounts = AccountMapper::getAll() + $accounts = AccountMapper::getAll() ->where('login', '%' . ($request->getDataString('search') ?? '') . '%', 'LIKE') ->where('email', '%' . ($request->getDataString('search') ?? '') . '%', 'LIKE', 'OR') ->where('name1', '%' . ($request->getDataString('search') ?? '') . '%', 'LIKE', 'OR') @@ -1791,7 +1797,7 @@ final class ApiController extends Controller } if (empty($defaultGroupIds) - && $account->getStatus() === AccountStatus::INACTIVE + && $account->status === AccountStatus::INACTIVE ) { $response->header->status = RequestStatusCode::R_400; @@ -2016,7 +2022,7 @@ final class ApiController extends Controller break; } - $new->setStatus((int) ($data['status'] ?? -1)); + $new->status = AccountStatus::tryFromValue((int) ($data['status'] ?? AccountStatus::INACTIVE)) ?? AccountStatus::INACTIVE; $this->updateModel($dataChange->createdBy, $old, $new, AccountMapper::class, 'datachange', $request->getOrigin()); $this->deleteModel($dataChange->createdBy, $dataChange, DataChangeMapper::class, 'datachange', $request->getOrigin()); @@ -2098,13 +2104,13 @@ final class ApiController extends Controller */ private function createAccountFromRequest(RequestAbstract $request) : Account { - $account = new Account(); - $account->login = $request->getDataString('user') ?? ''; - $account->name1 = $request->getDataString('name1') ?? ''; - $account->name2 = $request->getDataString('name2') ?? ''; - $account->name3 = $request->getDataString('name3') ?? ''; - $account->setStatus($request->getDataInt('status') ?? AccountStatus::INACTIVE); - $account->setType($request->getDataInt('type') ?? AccountType::USER); + $account = new Account(); + $account->login = $request->getDataString('user') ?? ''; + $account->name1 = $request->getDataString('name1') ?? ''; + $account->name2 = $request->getDataString('name2') ?? ''; + $account->name3 = $request->getDataString('name3') ?? ''; + $account->status = AccountStatus::tryFromValue($request->getDataInt('status')) ?? AccountStatus::INACTIVE; + $account->type = AccountType::tryFromValue($request->getDataInt('type')) ?? AccountType::USER; $account->setEmail($request->getDataString('email') ?? ''); $account->generatePassword($request->getDataString('password') ?? ''); @@ -2191,8 +2197,8 @@ final class ApiController extends Controller $account->name2 = $request->getDataString('name2') ?? $account->name2; $account->name3 = $request->getDataString('name3') ?? $account->name3; $account->setEmail($request->getDataString('email') ?? $account->getEmail()); - $account->setStatus($request->getDataInt('status') ?? $account->getStatus()); - $account->setType($request->getDataInt('type') ?? $account->getType()); + $account->status = AccountStatus::tryFromValue($request->getDataInt('status')) ?? $account->status; + $account->type = AccountType::tryFromValue($request->getDataInt('type')) ?? $account->type; if ($allowPassword && $request->hasData('password')) { $account->generatePassword((string) $request->getData('password')); @@ -2250,8 +2256,8 @@ final class ApiController extends Controller ? $this->app->l11nManager->getText($response->header->l11n->language, 'Admin', 'Api', 'ModuleActivatedSuccessful') : $this->app->l11nManager->getText($response->header->l11n->language, 'Admin', 'Api', 'ModuleActivatedFailure'); - $new = clone $old; - $new->setStatus(ModuleStatusUpdateType::ACTIVATE); + $new = clone $old; + $new->status = ModuleStatusUpdateType::ACTIVATE; ModuleMapper::update()->execute($new); break; @@ -2261,8 +2267,8 @@ final class ApiController extends Controller ? $this->app->l11nManager->getText($response->header->l11n->language, 'Admin', 'Api', 'ModuleDeactivatedSuccessful') : $this->app->l11nManager->getText($response->header->l11n->language, 'Admin', 'Api', 'ModuleDeactivatedFailure'); - $new = clone $old; - $new->setStatus(ModuleStatusUpdateType::DEACTIVATE); + $new = clone $old; + $new->status = ModuleStatusUpdateType::DEACTIVATE; ModuleMapper::update()->execute($new); break; @@ -2289,7 +2295,7 @@ final class ApiController extends Controller $dependencies = $moduleInfo->getDependencies(); foreach ($dependencies as $key => $_) { $iResponse = new HttpResponse(); - $iRequest = new HttpRequest(new HttpUri('')); + $iRequest = new HttpRequest(); $iRequest->header->account = 1; $iRequest->setData('status', ModuleStatusUpdateType::INSTALL); $iRequest->setData('module', $key); @@ -2305,7 +2311,7 @@ final class ApiController extends Controller $moduleObj->version = $moduleInfo->getVersion(); $moduleObj->name = $moduleInfo->getExternalName(); - $moduleObj->setStatus(ModuleStatus::AVAILABLE); + $moduleObj->status = ModuleStatus::AVAILABLE; $this->createModel($request->header->account, $moduleObj, ModuleMapper::class, 'module', $request->getOrigin()); @@ -2314,8 +2320,8 @@ final class ApiController extends Controller ? $this->app->l11nManager->getText($response->header->l11n->language, 'Admin', 'Api', 'ModuleInstalledSuccessful') : $this->app->l11nManager->getText($response->header->l11n->language, 'Admin', 'Api', 'ModuleInstalledFailure'); - $old = clone $moduleObj; - $moduleObj->setStatus(ModuleStatus::ACTIVE); + $old = clone $moduleObj; + $moduleObj->status = ModuleStatus::ACTIVE; $this->updateModel($request->header->account, $old, $moduleObj, ModuleMapper::class, 'module', $request->getOrigin()); @@ -2356,8 +2362,8 @@ final class ApiController extends Controller ? $this->app->l11nManager->getText($response->header->l11n->language, 'Admin', 'Api', 'ModuleUninstalledSuccessful') : $this->app->l11nManager->getText($response->header->l11n->language, 'Admin', 'Api', 'ModuleUninstalledFailure'); - $new = clone $old; - $new->setStatus(ModuleStatusUpdateType::DELETE); + $new = clone $old; + $new->status = ModuleStatusUpdateType::DELETE; ModuleMapper::delete()->execute($new); break; @@ -3098,7 +3104,6 @@ final class ApiController extends Controller } $contact = $this->createContactFromRequest($request); - $this->createModel($request->header->account, $contact, ContactMapper::class, 'account_contact', $request->getOrigin()); $this->createModelRelation( @@ -3145,11 +3150,10 @@ final class ApiController extends Controller public function createContactFromRequest(RequestAbstract $request) : Contact { /** @var Contact $element */ - $element = new Contact(); - $element->setType($request->getDataInt('type') ?? 0); - $element->setSubtype($request->getDataInt('subtype') ?? 0); + $element = new Contact(); + $element->type = ContactType::tryFromValue($request->getDataInt('type')) ?? ContactType::EMAIL; + $element->subtype = $request->getDataInt('subtype') ?? 0; $element->content = $request->getDataString('content') ?? ''; - $element->account = $request->getDataInt('account') ?? 0; return $element; } @@ -3456,10 +3460,9 @@ final class ApiController extends Controller */ public function updateContactFromRequest(RequestAbstract $request, Contact $new) : Contact { - $new->type = $request->getDataInt('type') ?? $new->type; + $new->type = ContactType::tryFromValue($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; } @@ -3509,7 +3512,9 @@ final class ApiController extends Controller /** @var \Modules\Admin\Models\Contact $contact */ $contact = ContactMapper::get()->where('id', (int) $request->getData('id'))->execute(); + $this->deleteModelRelation($request->header->account, (int) $request->getData('account'), [$contact->id], AccountMapper::class, 'contacts', 'account-contact', $request->getOrigin()); $this->deleteModel($request->header->account, $contact, ContactMapper::class, 'contact', $request->getOrigin()); + $this->createStandardDeleteResponse($request, $response, $contact); } @@ -3527,7 +3532,9 @@ final class ApiController extends Controller private function validateContactDelete(RequestAbstract $request) : array { $val = []; - if (($val['id'] = !$request->hasData('id'))) { + if (($val['id'] = !$request->hasData('id')) + || ($val['account'] = !$request->hasData('account')) + ) { return $val; } @@ -3642,4 +3649,235 @@ final class ApiController extends Controller return []; } + + /** + * Api method to delete Contact + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param array $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ + public function apiAddressDelete(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void + { + if (!empty($val = $this->validateAddressDelete($request))) { + $response->header->status = RequestStatusCode::R_400; + $this->createInvalidDeleteResponse($request, $response, $val); + + return; + } + + /** @var \Modules\Admin\Models\Address $address */ + $address = AddressMapper::get()->where('id', (int) $request->getData('id'))->execute(); + $this->deleteModelRelation($request->header->account, (int) $request->getData('account'), [$address->id], AccountMapper::class, 'addresses', 'account-address', $request->getOrigin()); + $this->deleteModel($request->header->account, $address, AddressMapper::class, 'address', $request->getOrigin()); + + $this->createStandardDeleteResponse($request, $response, $address); + } + + /** + * Validate Address delete request + * + * @param RequestAbstract $request Request + * + * @return array + * + * @todo Implement API validation function + * + * @since 1.0.0 + */ + private function validateAddressDelete(RequestAbstract $request) : array + { + $val = []; + if (($val['id'] = !$request->hasData('id')) + || ($val['account'] = !$request->hasData('account')) + ) { + return $val; + } + + return []; + } + + /** + * Api method to update Contact + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param array $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ + public function apiAddressUpdate(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void + { + if (!empty($val = $this->validateAddressUpdate($request))) { + $response->header->status = RequestStatusCode::R_400; + $this->createInvalidUpdateResponse($request, $response, $val); + + return; + } + + /** @var Address $old */ + $old = AddressMapper::get()->where('id', (int) $request->getData('id'))->execute(); + $new = $this->updateAddressFromRequest($request, clone $old); + + $this->updateModel($request->header->account, $old, $new, AddressMapper::class, 'address', $request->getOrigin()); + $this->createStandardUpdateResponse($request, $response, $new); + } + + /** + * Validate Contact update request + * + * @param RequestAbstract $request Request + * + * @return array + * + * @todo Implement API validation function + * + * @since 1.0.0 + */ + private function validateAddressUpdate(RequestAbstract $request) : array + { + $val = []; + if (($val['id'] = !$request->hasData('id'))) { + return $val; + } + + return []; + } + + /** + * Method to update an account from a request + * + * @param RequestAbstract $request Request + * @param Address $address Address + * + * @return Address + * + * @since 1.0.0 + */ + public function updateAddressFromRequest(RequestAbstract $request, Address $address) : Address + { + $hasLocationChange = ($request->getDataString('address') ?? $address->address) !== $address->address + || ($request->getDataString('postal') ?? $address->postal) !== $address->postal + || ($request->getDataString('city') ?? $address->city) !== $address->city + || ($request->getDataString('state') ?? $address->state) !== $address->state + || ($request->getDataString('country') ?? $address->country) !== $address->country; + + $address->name = $request->getDataString('name') ?? $address->name; + $address->fao = $request->getDataString('fao') ?? $address->fao; + $address->address = $request->getDataString('address') ?? $address->address; + $address->addressAddition = $request->getDataString('addition') ?? $address->addressAddition; + $address->postal = $request->getDataString('postal') ?? $address->postal; + $address->city = $request->getDataString('city') ?? $address->city; + $address->state = $request->getDataString('state') ?? $address->state; + $address->setCountry($request->getDataString('country') ?? $address->country); + + if ($hasLocationChange) { + $geocoding = Nominatim::geocoding($address->country, $address->city, $address->address); + if ($geocoding === ['lat' => 0.0, 'lon' => 0.0]) { + $geocoding = Nominatim::geocoding($address->country, $address->city); + } + + $address->lat = $geocoding['lat']; + $address->lon = $geocoding['lon']; + } + + return $address; + } + + /** + * Routing end-point for application behavior. + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param array $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ + public function apiAddressCreate(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void + { + if (!empty($val = $this->validateAddressCreate($request))) { + $response->header->status = RequestStatusCode::R_400; + $this->createInvalidCreateResponse($request, $response, $val); + + return; + } + + $address = $this->createAddressFromRequest($request); + $this->createModel($request->header->account, $address, AddressMapper::class, 'account_address', $request->getOrigin()); + + $this->createModelRelation( + $request->header->account, + (int) $request->getData('account'), + $address->id, + AccountMapper::class, 'addresses', '', $request->getOrigin() + ); + + $this->createStandardCreateResponse($request, $response, $address); + } + + /** + * Validate contact element create request + * + * @param RequestAbstract $request Request + * + * @return array + * + * @since 1.0.0 + */ + public function validateAddressCreate(RequestAbstract $request) : array + { + $val = []; + if (($val['account'] = !$request->hasData('account')) + ) { + return $val; + } + + return []; + } + + /** + * Method to create unit from request. + * + * @param RequestAbstract $request Request + * + * @return Address + * + * @since 1.0.0 + */ + public function createAddressFromRequest(RequestAbstract $request) : Address + { + $address = new Address(); + $address->name = $request->getDataString('name') ?? ''; + $address->type = AddressType::tryFromValue($request->getDataInt('type')) ?? AddressType::BUSINESS; + $address->fao = $request->getDataString('fao') ?? ''; + $address->address = $request->getDataString('address') ?? ''; + $address->postal = $request->getDataString('postal') ?? ''; + $address->city = $request->getDataString('city') ?? ''; + $address->state = $request->getDataString('state') ?? ''; + $address->setCountry($request->getDataString('country') ?? ISO3166TwoEnum::_XXX); + + $geocoding = Nominatim::geocoding($address->country, $address->city, $address->address); + if ($geocoding === ['lat' => 0.0, 'lon' => 0.0]) { + $geocoding = Nominatim::geocoding($address->country, $address->city); + } + + $address->lat = $geocoding['lat']; + $address->lon = $geocoding['lon']; + + return $address; + } } diff --git a/Controller/BackendController.php b/Controller/BackendController.php index 4fd87cb..5380b1e 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -20,13 +20,11 @@ use Modules\Admin\Models\AccountPermissionMapper; use Modules\Admin\Models\AppMapper; use Modules\Admin\Models\GroupMapper; use Modules\Admin\Models\GroupPermissionMapper; -use Modules\Admin\Models\LocalizationMapper; use Modules\Admin\Models\ModuleMapper; use Modules\Admin\Models\SettingsEnum; use Modules\Auditor\Models\AuditMapper; use Modules\Media\Models\MediaMapper; use Modules\Organization\Models\UnitMapper; -use phpOMS\Asset\AssetType; use phpOMS\Autoloader; use phpOMS\Contract\RenderableInterface; use phpOMS\DataStorage\Database\Query\OrderType; @@ -110,7 +108,7 @@ final class BackendController extends Controller foreach ($searchFieldData as $key => $data) { if ($data === '1') { $split = \explode('-', $key); - $member = \end($split); + $member = \end($split); $searchField[] = $member; } @@ -203,7 +201,7 @@ final class BackendController extends Controller public function viewAccountSettings(RequestAbstract $request, ResponseAbstract $response, array $data = []) : RenderableInterface { $view = new View($this->app->l11nManager, $request, $response); - $view->setTemplate('/Modules/Admin/Theme/Backend/accounts-single'); + $view->setTemplate('/Modules/Admin/Theme/Backend/accounts-view'); $view->data['nav'] = $this->app->moduleManager->get('Navigation')->createNavigationMid(1000104001, $request, $response); /** @var \Modules\Admin\Models\Account $account */ @@ -234,7 +232,7 @@ final class BackendController extends Controller foreach ($searchFieldData as $key => $data) { if ($data === '1') { $split = \explode('-', $key); - $member = \end($split); + $member = \end($split); $searchField[] = $member; } @@ -355,7 +353,7 @@ final class BackendController extends Controller foreach ($searchFieldData as $key => $data) { if ($data === '1') { $split = \explode('-', $key); - $member = \end($split); + $member = \end($split); $searchField[] = $member; } @@ -451,7 +449,7 @@ final class BackendController extends Controller public function viewGroupSettings(RequestAbstract $request, ResponseAbstract $response, array $data = []) : RenderableInterface { $view = new View($this->app->l11nManager, $request, $response); - $view->setTemplate('/Modules/Admin/Theme/Backend/groups-single'); + $view->setTemplate('/Modules/Admin/Theme/Backend/groups-view'); $view->data['nav'] = $this->app->moduleManager->get('Navigation') ->createNavigationMid(1000103001, $request, $response); @@ -642,7 +640,7 @@ final class BackendController extends Controller $id = $request->getDataString('id') ?? ''; - $queryMapper = AuditMapper::getAll() + $queryMapper = AuditMapper::getAll() ->with('createdBy') ->where('module', $id); @@ -800,13 +798,13 @@ final class BackendController extends Controller $generalSettings = $this->app->appSettings->get( names: [ SettingsEnum::PASSWORD_PATTERN, SettingsEnum::LOGIN_TIMEOUT, SettingsEnum::PASSWORD_INTERVAL, SettingsEnum::PASSWORD_HISTORY, SettingsEnum::LOGIN_TRIES, SettingsEnum::LOGGING_STATUS, SettingsEnum::LOGGING_PATH, SettingsEnum::DEFAULT_UNIT, - SettingsEnum::LOGIN_STATUS, SettingsEnum::DEFAULT_LOCALIZATION, SettingsEnum::MAIL_SERVER_ADDR, + SettingsEnum::LOGIN_STATUS, SettingsEnum::MAIL_SERVER_ADDR, ], module: 'Admin' ); - $view->data['generalSettings'] = $generalSettings; - $view->data['default_localization'] = LocalizationMapper::get()->where('id', (int) $generalSettings[SettingsEnum::DEFAULT_LOCALIZATION]->content)->execute(); + $view->data['generalSettings'] = $generalSettings; + $view->data['default_localization'] = $this->app->l11nServer; return $view; } diff --git a/Docs/Help/de/groups.md b/Docs/Help/de/groups.md index 682100c..3b7155f 100755 --- a/Docs/Help/de/groups.md +++ b/Docs/Help/de/groups.md @@ -42,7 +42,7 @@ The type is a `module` specific subpart which only should be set if the module i ### Element -The element is a `module` and `type` specific subpart which only should be set if the `type` is defined in the permission. For further information what kind of elements are available for a module and type please refer to the module specific documentation. Usually it referes to a section on a module page. +The element is a `module` and `type` specific subpart which only should be set if the `type` is defined in the permission. For further information what kind of elements are available for a module and type please refer to the module specific documentation. Usually it refers to a section on a module page. ### Component diff --git a/Docs/Help/en/groups.md b/Docs/Help/en/groups.md index 682100c..3b7155f 100755 --- a/Docs/Help/en/groups.md +++ b/Docs/Help/en/groups.md @@ -42,7 +42,7 @@ The type is a `module` specific subpart which only should be set if the module i ### Element -The element is a `module` and `type` specific subpart which only should be set if the `type` is defined in the permission. For further information what kind of elements are available for a module and type please refer to the module specific documentation. Usually it referes to a section on a module page. +The element is a `module` and `type` specific subpart which only should be set if the `type` is defined in the permission. For further information what kind of elements are available for a module and type please refer to the module specific documentation. Usually it refers to a section on a module page. ### Component diff --git a/LICENSE.txt b/LICENSE.txt index 18d430e..4ba0161 100755 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -27,7 +27,7 @@ Version 2.0 Subject to the terms and conditions of this License, each Contributor grants to You after purchase a perpetual, worldwide, non-exclusive, irrevocable copyright license to prepare Derivative Works of, publicly display, publicly perform the Work and such Derivative Works in Source or Object form. You are not allowed to sublicense, reproduce, or distribute the Work and such Derivative Works in Source or Object form. -3. Redistribution. +3. Redistribution You may not reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form. diff --git a/Models/Account.php b/Models/Account.php index 2f9ebe6..c4ba4f6 100755 --- a/Models/Account.php +++ b/Models/Account.php @@ -62,7 +62,7 @@ class Account extends \phpOMS\Account\Account * @var Address[] * @since 1.0.0 */ - public array $locations = []; + public array $addresses = []; /** * Contact data. @@ -71,4 +71,24 @@ class Account extends \phpOMS\Account\Account * @since 1.0.0 */ public array $contacts = []; + + /** + * Get the main contact element by type + * + * @param int $type Contact element type + * + * @return Contact + * + * @since 1.0.0 + */ + public function getContactByType(int $type) : Contact + { + foreach ($this->contacts as $element) { + if ($element->type === $type) { + return $element; + } + } + + return new NullContact(); + } } diff --git a/Models/AccountExternalMapper.php b/Models/AccountExternalMapper.php index c24373c..4b303ba 100755 --- a/Models/AccountExternalMapper.php +++ b/Models/AccountExternalMapper.php @@ -36,16 +36,16 @@ class AccountExternalMapper extends DataMapperFactory * @since 1.0.0 */ public const COLUMNS = [ - 'account_external_id' => ['name' => 'account_external_id', 'type' => 'int', 'internal' => 'id'], - '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_name' => ['name' => 'account_external_name', 'type' => 'string', 'internal' => 'name'], - '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_id' => ['name' => 'account_external_id', 'type' => 'int', 'internal' => 'id'], + '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_name' => ['name' => 'account_external_name', 'type' => 'string', 'internal' => 'name'], + '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/AccountMapper.php b/Models/AccountMapper.php index f0bca3c..5f354b1 100755 --- a/Models/AccountMapper.php +++ b/Models/AccountMapper.php @@ -39,18 +39,18 @@ class AccountMapper extends DataMapperFactory * @since 1.0.0 */ public const COLUMNS = [ - 'account_id' => ['name' => 'account_id', 'type' => 'int', 'internal' => 'id'], - 'account_status' => ['name' => 'account_status', 'type' => 'int', 'internal' => 'status'], - 'account_type' => ['name' => 'account_type', 'type' => 'int', 'internal' => 'type'], - 'account_login' => ['name' => 'account_login', 'type' => 'string', 'internal' => 'login', 'autocomplete' => true], - 'account_name1' => ['name' => 'account_name1', 'type' => 'string', 'internal' => 'name1', 'autocomplete' => true, 'annotations' => ['gdpr' => true]], - 'account_name2' => ['name' => 'account_name2', 'type' => 'string', 'internal' => 'name2', 'autocomplete' => true, 'annotations' => ['gdpr' => true]], - 'account_name3' => ['name' => 'account_name3', 'type' => 'string', 'internal' => 'name3', 'autocomplete' => true, 'annotations' => ['gdpr' => true]], - 'account_email' => ['name' => 'account_email', 'type' => 'string', 'internal' => 'email', 'autocomplete' => true, 'annotations' => ['gdpr' => true]], - 'account_tries' => ['name' => 'account_tries', 'type' => 'int', 'internal' => 'tries'], - 'account_lactive' => ['name' => 'account_lactive', 'type' => 'DateTime', 'internal' => 'lastActive'], - 'account_localization' => ['name' => 'account_localization', 'type' => 'int', 'internal' => 'l11n'], - 'account_created_at' => ['name' => 'account_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true], + 'account_id' => ['name' => 'account_id', 'type' => 'int', 'internal' => 'id'], + 'account_status' => ['name' => 'account_status', 'type' => 'int', 'internal' => 'status'], + 'account_type' => ['name' => 'account_type', 'type' => 'int', 'internal' => 'type'], + 'account_login' => ['name' => 'account_login', 'type' => 'string', 'internal' => 'login', 'autocomplete' => true], + 'account_name1' => ['name' => 'account_name1', 'type' => 'string', 'internal' => 'name1', 'autocomplete' => true, 'annotations' => ['gdpr' => true]], + 'account_name2' => ['name' => 'account_name2', 'type' => 'string', 'internal' => 'name2', 'autocomplete' => true, 'annotations' => ['gdpr' => true]], + 'account_name3' => ['name' => 'account_name3', 'type' => 'string', 'internal' => 'name3', 'autocomplete' => true, 'annotations' => ['gdpr' => true]], + 'account_email' => ['name' => 'account_email', 'type' => 'string', 'internal' => 'email', 'autocomplete' => true, 'annotations' => ['gdpr' => true]], + 'account_tries' => ['name' => 'account_tries', 'type' => 'int', 'internal' => 'tries'], + 'account_lactive' => ['name' => 'account_lactive', 'type' => 'DateTime', 'internal' => 'lastActive'], + 'account_localization' => ['name' => 'account_localization', 'type' => 'int', 'internal' => 'l11n'], + 'account_created_at' => ['name' => 'account_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true], ]; /** @@ -60,9 +60,9 @@ class AccountMapper extends DataMapperFactory * @since 1.0.0 */ public const OWNS_ONE = [ - 'l11n' => [ - 'mapper' => LocalizationMapper::class, - 'external' => 'account_localization', + 'l11n' => [ + 'mapper' => LocalizationMapper::class, + 'external' => 'account_localization', ], ]; @@ -91,7 +91,7 @@ class AccountMapper extends DataMapperFactory 'external' => 'account_account_rel_root', 'self' => 'account_account_rel_child', ], - 'locations' => [ + 'addresses' => [ 'mapper' => AddressMapper::class, 'table' => 'account_address_rel', 'external' => 'account_address_rel_address', @@ -99,9 +99,9 @@ class AccountMapper extends DataMapperFactory ], 'contacts' => [ 'mapper' => ContactMapper::class, - 'table' => 'account_contact', - 'self' => 'account_contact_account', - 'external' => null, + 'table' => 'account_contact_rel', + 'external' => 'account_contact_rel_contact', + 'self' => 'account_contact_rel_account', ], ]; diff --git a/Models/AccountPermission.php b/Models/AccountPermission.php index 712bb55..6f66555 100755 --- a/Models/AccountPermission.php +++ b/Models/AccountPermission.php @@ -54,13 +54,13 @@ class AccountPermission extends PermissionAbstract */ public function __construct( int $account = 0, - int $unit = null, - int $app = null, - string $module = null, - string $from = null, - int $category = null, - int $element = null, - int $component = null, + ?int $unit = null, + ?int $app = null, + ?string $module = null, + ?string $from = null, + ?int $category = null, + ?int $element = null, + ?int $component = null, int $permission = PermissionType::NONE ) { $this->account = $account; diff --git a/Models/AccountPermissionMapper.php b/Models/AccountPermissionMapper.php index 6085930..c1eff88 100755 --- a/Models/AccountPermissionMapper.php +++ b/Models/AccountPermissionMapper.php @@ -36,22 +36,22 @@ final class AccountPermissionMapper extends DataMapperFactory * @since 1.0.0 */ public const COLUMNS = [ - 'account_permission_id' => ['name' => 'account_permission_id', 'type' => 'int', 'internal' => 'id'], - 'account_permission_account' => ['name' => 'account_permission_account', 'type' => 'int', 'internal' => 'account'], - 'account_permission_unit' => ['name' => 'account_permission_unit', 'type' => 'int', 'internal' => 'unit'], - 'account_permission_app' => ['name' => 'account_permission_app', 'type' => 'int', 'internal' => 'app'], - 'account_permission_module' => ['name' => 'account_permission_module', 'type' => 'string', 'internal' => 'module'], - 'account_permission_from' => ['name' => 'account_permission_from', 'type' => 'string', 'internal' => 'from'], - 'account_permission_category' => ['name' => 'account_permission_category', 'type' => 'int', 'internal' => 'category'], - 'account_permission_element' => ['name' => 'account_permission_element', 'type' => 'int', 'internal' => 'element'], - 'account_permission_component' => ['name' => 'account_permission_component', 'type' => 'int', 'internal' => 'component'], - 'account_permission_hasread' => ['name' => 'account_permission_hasread', 'type' => 'bool', 'internal' => 'hasRead'], - 'account_permission_hascreate' => ['name' => 'account_permission_hascreate', 'type' => 'bool', 'internal' => 'hasCreate'], - 'account_permission_defaultcperm' => ['name' => 'account_permission_defaultcperm', 'type' => 'string', 'internal' => 'defaultCPermissions'], - 'account_permission_hasmodify' => ['name' => 'account_permission_hasmodify', 'type' => 'bool', 'internal' => 'hasModify'], - 'account_permission_hasdelete' => ['name' => 'account_permission_hasdelete', 'type' => 'bool', 'internal' => 'hasDelete'], - 'account_permission_haspermission' => ['name' => 'account_permission_haspermission', 'type' => 'bool', 'internal' => 'hasPermission'], - 'account_permission_defaultpperm' => ['name' => 'account_permission_defaultpperm', 'type' => 'string', 'internal' => 'defaultPPermissions'], + 'account_permission_id' => ['name' => 'account_permission_id', 'type' => 'int', 'internal' => 'id'], + 'account_permission_account' => ['name' => 'account_permission_account', 'type' => 'int', 'internal' => 'account'], + 'account_permission_unit' => ['name' => 'account_permission_unit', 'type' => 'int', 'internal' => 'unit'], + 'account_permission_app' => ['name' => 'account_permission_app', 'type' => 'int', 'internal' => 'app'], + 'account_permission_module' => ['name' => 'account_permission_module', 'type' => 'string', 'internal' => 'module'], + 'account_permission_from' => ['name' => 'account_permission_from', 'type' => 'string', 'internal' => 'from'], + 'account_permission_category' => ['name' => 'account_permission_category', 'type' => 'int', 'internal' => 'category'], + 'account_permission_element' => ['name' => 'account_permission_element', 'type' => 'int', 'internal' => 'element'], + 'account_permission_component' => ['name' => 'account_permission_component', 'type' => 'int', 'internal' => 'component'], + 'account_permission_hasread' => ['name' => 'account_permission_hasread', 'type' => 'bool', 'internal' => 'hasRead'], + 'account_permission_hascreate' => ['name' => 'account_permission_hascreate', 'type' => 'bool', 'internal' => 'hasCreate'], + 'account_permission_defaultcperm' => ['name' => 'account_permission_defaultcperm', 'type' => 'string', 'internal' => 'defaultCPermissions'], + 'account_permission_hasmodify' => ['name' => 'account_permission_hasmodify', 'type' => 'bool', 'internal' => 'hasModify'], + 'account_permission_hasdelete' => ['name' => 'account_permission_hasdelete', 'type' => 'bool', 'internal' => 'hasDelete'], + 'account_permission_haspermission' => ['name' => 'account_permission_haspermission', 'type' => 'bool', 'internal' => 'hasPermission'], + 'account_permission_defaultpperm' => ['name' => 'account_permission_defaultpperm', 'type' => 'string', 'internal' => 'defaultPPermissions'], ]; /** diff --git a/Models/App.php b/Models/App.php index 9466267..bacd3cf 100755 --- a/Models/App.php +++ b/Models/App.php @@ -81,10 +81,10 @@ class App implements \JsonSerializable public function toArray() : array { return [ - 'id' => $this->id, - 'name' => $this->name, - 'type' => $this->type, - 'status' => $this->status, + 'id' => $this->id, + 'name' => $this->name, + 'type' => $this->type, + 'status' => $this->status, ]; } diff --git a/Models/AppMapper.php b/Models/AppMapper.php index c8abbec..88479f3 100755 --- a/Models/AppMapper.php +++ b/Models/AppMapper.php @@ -36,12 +36,12 @@ final class AppMapper extends DataMapperFactory * @since 1.0.0 */ public const COLUMNS = [ - 'app_id' => ['name' => 'app_id', 'type' => 'int', 'internal' => 'id'], - 'app_name' => ['name' => 'app_name', 'type' => 'string', 'internal' => 'name'], - 'app_theme' => ['name' => 'app_theme', 'type' => 'string', 'internal' => 'theme'], - 'app_status' => ['name' => 'app_status', 'type' => 'int', 'internal' => 'status'], - 'app_type' => ['name' => 'app_type', 'type' => 'int', 'internal' => 'type'], - 'app_unit_default' => ['name' => 'app_unit_default', 'type' => 'int', 'internal' => 'defaultUnit'], + 'app_id' => ['name' => 'app_id', 'type' => 'int', 'internal' => 'id'], + 'app_name' => ['name' => 'app_name', 'type' => 'string', 'internal' => 'name'], + 'app_theme' => ['name' => 'app_theme', 'type' => 'string', 'internal' => 'theme'], + 'app_status' => ['name' => 'app_status', 'type' => 'int', 'internal' => 'status'], + 'app_type' => ['name' => 'app_type', 'type' => 'int', 'internal' => 'type'], + 'app_unit_default' => ['name' => 'app_unit_default', 'type' => 'int', 'internal' => 'defaultUnit'], ]; /** diff --git a/Models/Contact.php b/Models/Contact.php index 834155f..1e39525 100755 --- a/Models/Contact.php +++ b/Models/Contact.php @@ -50,6 +50,8 @@ class Contact */ public int $subtype = 0; + public string $title = ''; + /** * Content. * @@ -57,80 +59,4 @@ class Contact * @since 1.0.0 */ public string $content = ''; - - /** - * Order. - * - * @var int - * @since 1.0.0 - */ - public int $order = 0; - - public int $account = 0; - - public string $module = ''; - - /** - * Get id. - * - * @return int Model id - * - * @since 1.0.0 - */ - public function getId() : int - { - return $this->id; - } - - /** - * Set type - * - * @param int $type Type - * - * @return void - * - * @since 1.0.0 - */ - public function setType(int $type) : void - { - $this->type = $type; - } - - /** - * Get type - * - * @return int - * - * @since 1.0.0 - */ - public function getType() : int - { - return $this->type; - } - - /** - * Set subtype - * - * @param int $subtype Subtype - * - * @return void - * - * @since 1.0.0 - */ - public function setSubtype(int $subtype) : void - { - $this->subtype = $subtype; - } - - /** - * Get subtype - * - * @return int - * - * @since 1.0.0 - */ - public function getSubtype() : int - { - return $this->subtype; - } } diff --git a/Models/ContactMapper.php b/Models/ContactMapper.php index 7783ce9..fca34ce 100755 --- a/Models/ContactMapper.php +++ b/Models/ContactMapper.php @@ -36,13 +36,11 @@ final class ContactMapper extends DataMapperFactory * @since 1.0.0 */ public const COLUMNS = [ - 'account_contact_id' => ['name' => 'account_contact_id', 'type' => 'int', 'internal' => 'id'], - 'account_contact_type' => ['name' => 'account_contact_type', 'type' => 'int', 'internal' => 'type'], - 'account_contact_subtype' => ['name' => 'account_contact_subtype', 'type' => 'int', 'internal' => 'subtype'], - 'account_contact_order' => ['name' => 'account_contact_order', 'type' => 'int', 'internal' => 'order'], - 'account_contact_content' => ['name' => 'account_contact_content', 'type' => 'string', 'internal' => 'content'], - 'account_contact_module' => ['name' => 'account_contact_module', 'type' => 'string', 'internal' => 'module'], - 'account_contact_account' => ['name' => 'account_contact_account', 'type' => 'int', 'internal' => 'account'], + 'contact_id' => ['name' => 'contact_id', 'type' => 'int', 'internal' => 'id'], + 'contact_title' => ['name' => 'contact_title', 'type' => 'string', 'internal' => 'title'], + 'contact_type' => ['name' => 'contact_type', 'type' => 'int', 'internal' => 'type'], + 'contact_subtype' => ['name' => 'contact_subtype', 'type' => 'int', 'internal' => 'subtype'], + 'contact_content' => ['name' => 'contact_content', 'type' => 'string', 'internal' => 'content'], ]; /** @@ -51,7 +49,7 @@ final class ContactMapper extends DataMapperFactory * @var string * @since 1.0.0 */ - public const TABLE = 'account_contact'; + public const TABLE = 'contact'; /** * Primary field name. @@ -59,5 +57,5 @@ final class ContactMapper extends DataMapperFactory * @var string * @since 1.0.0 */ - public const PRIMARYFIELD = 'account_contact_id'; + public const PRIMARYFIELD = 'contact_id'; } diff --git a/Models/DataChange.php b/Models/DataChange.php index 6f30ee2..4578d06 100755 --- a/Models/DataChange.php +++ b/Models/DataChange.php @@ -113,8 +113,8 @@ class DataChange public function toArray() : array { return [ - 'id' => $this->id, - 'data' => $this->data, + 'id' => $this->id, + 'data' => $this->data, ]; } diff --git a/Models/GroupPermission.php b/Models/GroupPermission.php index 92ced6e..5235f61 100755 --- a/Models/GroupPermission.php +++ b/Models/GroupPermission.php @@ -54,13 +54,13 @@ class GroupPermission extends PermissionAbstract */ public function __construct( int $group = 0, - int $unit = null, - int $app = null, - string $module = null, - string $from = null, - int $category = null, - int $element = null, - int $component = null, + ?int $unit = null, + ?int $app = null, + ?string $module = null, + ?string $from = null, + ?int $category = null, + ?int $element = null, + ?int $component = null, int $permission = PermissionType::NONE ) { $this->group = $group; diff --git a/Models/GroupPermissionMapper.php b/Models/GroupPermissionMapper.php index c2a00f9..22a4543 100755 --- a/Models/GroupPermissionMapper.php +++ b/Models/GroupPermissionMapper.php @@ -36,22 +36,22 @@ final class GroupPermissionMapper extends DataMapperFactory * @since 1.0.0 */ public const COLUMNS = [ - 'group_permission_id' => ['name' => 'group_permission_id', 'type' => 'int', 'internal' => 'id'], - 'group_permission_group' => ['name' => 'group_permission_group', 'type' => 'int', 'internal' => 'group'], - 'group_permission_unit' => ['name' => 'group_permission_unit', 'type' => 'int', 'internal' => 'unit'], - 'group_permission_app' => ['name' => 'group_permission_app', 'type' => 'int', 'internal' => 'app'], - 'group_permission_module' => ['name' => 'group_permission_module', 'type' => 'string', 'internal' => 'module'], - 'group_permission_from' => ['name' => 'group_permission_from', 'type' => 'string', 'internal' => 'from'], - 'group_permission_category' => ['name' => 'group_permission_category', 'type' => 'int', 'internal' => 'category'], - 'group_permission_element' => ['name' => 'group_permission_element', 'type' => 'int', 'internal' => 'element'], - 'group_permission_component' => ['name' => 'group_permission_component', 'type' => 'int', 'internal' => 'component'], - 'group_permission_hasread' => ['name' => 'group_permission_hasread', 'type' => 'bool', 'internal' => 'hasRead'], - 'group_permission_hascreate' => ['name' => 'group_permission_hascreate', 'type' => 'bool', 'internal' => 'hasCreate'], - 'group_permission_defaultcperm' => ['name' => 'group_permission_defaultcperm', 'type' => 'string', 'internal' => 'defaultCPermissions'], - 'group_permission_hasmodify' => ['name' => 'group_permission_hasmodify', 'type' => 'bool', 'internal' => 'hasModify'], - 'group_permission_hasdelete' => ['name' => 'group_permission_hasdelete', 'type' => 'bool', 'internal' => 'hasDelete'], - 'group_permission_haspermission' => ['name' => 'group_permission_haspermission', 'type' => 'bool', 'internal' => 'hasPermission'], - 'group_permission_defaultpperm' => ['name' => 'group_permission_defaultpperm', 'type' => 'string', 'internal' => 'defaultPPermissions'], + 'group_permission_id' => ['name' => 'group_permission_id', 'type' => 'int', 'internal' => 'id'], + 'group_permission_group' => ['name' => 'group_permission_group', 'type' => 'int', 'internal' => 'group'], + 'group_permission_unit' => ['name' => 'group_permission_unit', 'type' => 'int', 'internal' => 'unit'], + 'group_permission_app' => ['name' => 'group_permission_app', 'type' => 'int', 'internal' => 'app'], + 'group_permission_module' => ['name' => 'group_permission_module', 'type' => 'string', 'internal' => 'module'], + 'group_permission_from' => ['name' => 'group_permission_from', 'type' => 'string', 'internal' => 'from'], + 'group_permission_category' => ['name' => 'group_permission_category', 'type' => 'int', 'internal' => 'category'], + 'group_permission_element' => ['name' => 'group_permission_element', 'type' => 'int', 'internal' => 'element'], + 'group_permission_component' => ['name' => 'group_permission_component', 'type' => 'int', 'internal' => 'component'], + 'group_permission_hasread' => ['name' => 'group_permission_hasread', 'type' => 'bool', 'internal' => 'hasRead'], + 'group_permission_hascreate' => ['name' => 'group_permission_hascreate', 'type' => 'bool', 'internal' => 'hasCreate'], + 'group_permission_defaultcperm' => ['name' => 'group_permission_defaultcperm', 'type' => 'string', 'internal' => 'defaultCPermissions'], + 'group_permission_hasmodify' => ['name' => 'group_permission_hasmodify', 'type' => 'bool', 'internal' => 'hasModify'], + 'group_permission_hasdelete' => ['name' => 'group_permission_hasdelete', 'type' => 'bool', 'internal' => 'hasDelete'], + 'group_permission_haspermission' => ['name' => 'group_permission_haspermission', 'type' => 'bool', 'internal' => 'hasPermission'], + 'group_permission_defaultpperm' => ['name' => 'group_permission_defaultpperm', 'type' => 'string', 'internal' => 'defaultPPermissions'], ]; /** diff --git a/Models/LocalizationMapper.php b/Models/LocalizationMapper.php index 476b17b..834e72d 100755 --- a/Models/LocalizationMapper.php +++ b/Models/LocalizationMapper.php @@ -99,23 +99,23 @@ final class LocalizationMapper extends DataMapperFactory * @since 1.0.0 */ public const OWNS_ONE = [ - 'country' => [ - 'mapper' => CountryMapper::class, - 'external' => 'l11n_country', - 'by' => 'code2', - 'column' => 'code2', + 'country' => [ + 'mapper' => CountryMapper::class, + 'external' => 'l11n_country', + 'by' => 'code2', + 'column' => 'code2', ], - 'language' => [ - 'mapper' => LanguageMapper::class, - 'external' => 'l11n_language', - 'by' => 'code2', - 'column' => 'code2', + 'language' => [ + 'mapper' => LanguageMapper::class, + 'external' => 'l11n_language', + 'by' => 'code2', + 'column' => 'code2', ], - 'currency' => [ - 'mapper' => CurrencyMapper::class, - 'external' => 'l11n_currency', - 'by' => 'code', - 'column' => 'code', + 'currency' => [ + 'mapper' => CurrencyMapper::class, + 'external' => 'l11n_currency', + 'by' => 'code', + 'column' => 'code', ], ]; diff --git a/Models/Module.php b/Models/Module.php index 8c8e159..443992a 100755 --- a/Models/Module.php +++ b/Models/Module.php @@ -15,7 +15,6 @@ declare(strict_types=1); namespace Modules\Admin\Models; use phpOMS\Module\ModuleStatus; -use phpOMS\Stdlib\Base\Exception\InvalidEnumValue; /** * Module class. @@ -93,50 +92,6 @@ class Module $this->createdAt = new \DateTimeImmutable('now'); } - /** - * Get module id. - * - * @return string - * - * @since 1.0.0 - */ - public function getId() : string - { - return $this->id; - } - - /** - * Get module status. - * - * @return int Module status - * - * @since 1.0.0 - */ - public function getStatus() : int - { - return $this->status; - } - - /** - * Set module status. - * - * @param int $status Module status - * - * @return void - * - * @throws InvalidEnumValue - * - * @since 1.0.0 - */ - public function setStatus(int $status) : void - { - if (!ModuleStatusUpdateType::isValidValue($status)) { - throw new InvalidEnumValue($status); - } - - $this->status = $status; - } - /** * Get string representation. * @@ -163,12 +118,12 @@ class Module public function toArray() : array { return [ - 'id' => $this->id, - 'name' => $this->name, - 'path' => $this->path, - 'version' => $this->version, - 'status' => $this->status, - 'createdAt' => $this->createdAt, + 'id' => $this->id, + 'name' => $this->name, + 'path' => $this->path, + 'version' => $this->version, + 'status' => $this->status, + 'createdAt' => $this->createdAt, ]; } } diff --git a/Models/NullContact.php b/Models/NullContact.php new file mode 100644 index 0000000..8d03c7f --- /dev/null +++ b/Models/NullContact.php @@ -0,0 +1,46 @@ +id = $id; + } + + /** + * {@inheritdoc} + */ + public function jsonSerialize() : mixed + { + return ['id' => $this->id]; + } +} diff --git a/Models/PermissionCategory.php b/Models/PermissionCategory.php index 1340b05..97ff2eb 100755 --- a/Models/PermissionCategory.php +++ b/Models/PermissionCategory.php @@ -44,5 +44,9 @@ abstract class PermissionCategory extends Enum public const SEARCH = 9; - public const API = 9; + public const API = 10; + + public const ADDRESS = 11; + + public const CONTACT = 12; } diff --git a/Theme/Backend/Components/AccountPermissionSelector/BaseView.php b/Theme/Backend/Components/AccountPermissionSelector/BaseView.php index d2a224e..6e7d7e2 100644 --- a/Theme/Backend/Components/AccountPermissionSelector/BaseView.php +++ b/Theme/Backend/Components/AccountPermissionSelector/BaseView.php @@ -59,7 +59,7 @@ class BaseView extends View /** * {@inheritdoc} */ - public function __construct(L11nManager $l11n = null, RequestAbstract $request, ResponseAbstract $response) + public function __construct(?L11nManager $l11n = null, RequestAbstract $request, ResponseAbstract $response) { parent::__construct($l11n, $request, $response); $this->setTemplate('/Modules/Admin/Theme/Backend/Components/AccountPermissionSelector/account-permission-selector'); diff --git a/Theme/Backend/Components/AddressEditor/AddressView.php b/Theme/Backend/Components/AddressEditor/AddressView.php index 26ee9dd..259de00 100644 --- a/Theme/Backend/Components/AddressEditor/AddressView.php +++ b/Theme/Backend/Components/AddressEditor/AddressView.php @@ -39,15 +39,31 @@ class AddressView extends View public array $addresses = []; /** - * Units + * Form id * - * @var \Modules\Organization\Models\Unit[] + * @var string * @since 1.0.0 */ - public array $units = []; + public string $form = ''; /** - * API Uri for address actions + * Virtual path of the media file + * + * @var string + * @since 1.0.0 + */ + public string $virtualPath = ''; + + /** + * Name of the image preview + * + * @var string + * @since 1.0.0 + */ + public string $name = ''; + + /** + * API Uri for attribute actions * * @var string * @since 1.0.0 @@ -65,7 +81,7 @@ class AddressView extends View /** * {@inheritdoc} */ - public function __construct(L11nManager $l11n = null, RequestAbstract $request, ResponseAbstract $response) + public function __construct(?L11nManager $l11n = null, RequestAbstract $request, ResponseAbstract $response) { parent::__construct($l11n, $request, $response); $this->setTemplate('/Modules/Admin/Theme/Backend/Components/AddressEditor/addresses'); @@ -76,11 +92,10 @@ class AddressView extends View */ public function render(mixed ...$data) : string { - /** @var array{0:\phpOMS\Stdlib\Base\Address[]} $data */ - $this->addresses = $data[0]; - $this->units = $data[1]; - $this->apiUri = $data[2]; - $this->refId = $data[3]; + /** @var array{0:string, 1?:string, 2?:array} $data */ + $this->form = $data[0]; + $this->virtualPath = $data[1] ?? $this->virtualPath; + $this->addresses = $data[2] ?? $this->addresses; return parent::render(); } diff --git a/Theme/Backend/Components/AddressEditor/addresses.tpl.php b/Theme/Backend/Components/AddressEditor/addresses.tpl.php index 79fcf86..b0cff85 100644 --- a/Theme/Backend/Components/AddressEditor/addresses.tpl.php +++ b/Theme/Backend/Components/AddressEditor/addresses.tpl.php @@ -4,7 +4,7 @@ * * PHP Version 8.1 * - * @package Modules\Admin + * @package Modules\Address * @copyright Dennis Eichhorn * @license OMS License 2.0 * @version 1.0.0 @@ -16,120 +16,162 @@ use phpOMS\Localization\ISO639Enum; use phpOMS\Stdlib\Base\AddressType; use phpOMS\Uri\UriFactory; -$address = $this->addresses; +$address = $this->addresses; $languages = ISO639Enum::getConstants(); $types = AddressType::getConstants(); -$units = $this->units; ?> -
-
-
-
getHtml('Address', 'Admin', 'Backend'); ?>
-
- +
+
+
+ +
getHtml('Address', 'Admin', 'Backend'); ?>
+
+ -
- - -
+
+ + +
-
- - +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + + foreach ($types as $type) : ?> +
- - + +
+
-
- -

-                
-
-
- - - -
- -
-
- -
-
-
getHtml('Address', 'Admin', 'Backend'); ?>download
-
- - - - - - $value) : ++$c; ?> + + + $value) : + ++$c; + ?> -
- getHtml('ID', '0', '0'); ?> - getHtml('Name', 'Admin', 'Backend'); ?>expand_lessexpand_more - getHtml('Value', 'Admin', 'Backend'); ?>expand_lessexpand_more - getHtml('Unit', 'Admin', 'Backend'); ?>expand_lessexpand_more -
getHtml('ID', '0', '0'); ?> + getHtml('Type', 'Admin', 'Backend'); ?>expand_lessexpand_more + getHtml('Name', 'Admin', 'Backend'); ?>expand_lessexpand_more + getHtml('FAO', 'Admin', 'Backend'); ?>expand_lessexpand_more + getHtml('Address', 'Admin', 'Backend'); ?>expand_lessexpand_more + getHtml('Addition', 'Admin', 'Backend'); ?>expand_lessexpand_more + getHtml('Postal', 'Admin', 'Backend'); ?>expand_lessexpand_more + getHtml('City', 'Admin', 'Backend'); ?>expand_lessexpand_more + getHtml('State', 'Admin', 'Backend'); ?>expand_lessexpand_more + getHtml('Country', 'Admin', 'Backend'); ?>expand_lessexpand_more +
settings - type->isRequired) : ?> - id; ?> - printHtml($value->type->getL11n()); ?> - value->getValue() instanceof \DateTime ? $value->value->getValue()->format('Y-m-d') : $this->printHtml((string) $value->value->getValue()); ?> - printHtml($value->value->unit); ?> - - -
getHtml('Empty', '0', '0'); ?> - -
-
-
+ getHtml(':address' . $value->type, 'Admin', 'Backend'); ?> + printHtml($value->name); ?> + printHtml($value->fao); ?> + printHtml($value->address); ?> + printHtml($value->addressAddition); ?> + printHtml($value->postal); ?> + printHtml($value->city); ?> + printHtml($value->state); ?> + printHtml($value->country); ?> + + + + getHtml('Empty', '0', '0'); ?> + + +
+ + diff --git a/Theme/Backend/Components/ContactEditor/ContactView.php b/Theme/Backend/Components/ContactEditor/ContactView.php new file mode 100644 index 0000000..963568b --- /dev/null +++ b/Theme/Backend/Components/ContactEditor/ContactView.php @@ -0,0 +1,102 @@ +setTemplate('/Modules/Admin/Theme/Backend/Components/ContactEditor/contacts'); + } + + /** + * {@inheritdoc} + */ + public function render(mixed ...$data) : string + { + /** @var array{0:string, 1?:string, 2?:array} $data */ + $this->form = $data[0]; + $this->virtualPath = $data[1] ?? $this->virtualPath; + $this->contacts = $data[2] ?? $this->contacts; + + return parent::render(); + } +} diff --git a/Theme/Backend/Components/ContactEditor/contacts.tpl.php b/Theme/Backend/Components/ContactEditor/contacts.tpl.php new file mode 100644 index 0000000..e5aa2ea --- /dev/null +++ b/Theme/Backend/Components/ContactEditor/contacts.tpl.php @@ -0,0 +1,140 @@ +contacts; +$languages = ISO639Enum::getConstants(); +$types = ContactType::getConstants(); +$subtypes = AddressType::getConstants(); +?> + +
+
+
+
+
getHtml('Contact', 'Admin', 'Backend'); ?>
+
+ + +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+
+
+ + + +
+
+
+
+ +
+
+
getHtml('Contacts', 'Admin', 'Backend'); ?>download
+
+ + + + + + $value) : ++$c; ?> + +
+ getHtml('ID', '0', '0'); ?> + getHtml('Type', 'Admin', 'Backend'); ?>expand_lessexpand_more + getHtml('Subtype', 'Admin', 'Backend'); ?>expand_lessexpand_more + getHtml('Name', 'Admin', 'Backend'); ?>expand_lessexpand_more + getHtml('Content', 'Admin', 'Backend'); ?>expand_lessexpand_more +
+ settings + + + + + + + id; ?> + getHtml(':contact' . $value->type, 'Admin', 'Backend'); ?> + getHtml(':address' . $value->subtype, 'Admin', 'Backend'); ?> + printHtml($value->title); ?> + printHtml($value->content); ?> + + +
getHtml('Empty', '0', '0'); ?> + +
+
+
+
+
diff --git a/Theme/Backend/Components/GroupTagSelector/GroupTagSelectorPopupView.php b/Theme/Backend/Components/GroupTagSelector/GroupTagSelectorPopupView.php index 05b6228..2c935ba 100755 --- a/Theme/Backend/Components/GroupTagSelector/GroupTagSelectorPopupView.php +++ b/Theme/Backend/Components/GroupTagSelector/GroupTagSelectorPopupView.php @@ -41,38 +41,12 @@ class GroupTagSelectorPopupView extends View /** * {@inheritdoc} */ - public function __construct(L11nManager $l11n = null, RequestAbstract $request, ResponseAbstract $response) + public function __construct(?L11nManager $l11n = null, RequestAbstract $request, ResponseAbstract $response) { parent::__construct($l11n, $request, $response); $this->setTemplate('/Modules/Admin/Theme/Backend/Components/GroupTagSelector/group-selector-popup'); } - /** - * Set selector id - * - * @param string $id Id - * - * @return void - * - * @since 1.0.0 - */ - public function setId(string $id) : void - { - $this->id = $id; - } - - /** - * Get selector id - * - * @return string - * - * @since 1.0.0 - */ - public function getId() : string - { - return $this->id; - } - /** * {@inheritdoc} */ diff --git a/Theme/Backend/Components/GroupTagSelector/GroupTagSelectorView.php b/Theme/Backend/Components/GroupTagSelector/GroupTagSelectorView.php index 1118c1d..23cccbd 100755 --- a/Theme/Backend/Components/GroupTagSelector/GroupTagSelectorView.php +++ b/Theme/Backend/Components/GroupTagSelector/GroupTagSelectorView.php @@ -58,18 +58,6 @@ class GroupTagSelectorView extends View $this->addData('group-selector-popup', $view); } - /** - * Get selector id - * - * @return string - * - * @since 1.0.0 - */ - public function getId() : string - { - return $this->id; - } - /** * Is required? * @@ -91,7 +79,7 @@ class GroupTagSelectorView extends View $this->id = $data[0]; $this->isRequired = $data[1] ?? false; - $this->getData('group-selector-popup')->setId($this->id); + $this->getData('group-selector-popup')->id = $this->id; return parent::render(); } diff --git a/Theme/Backend/Lang/en.lang.php b/Theme/Backend/Lang/en.lang.php index 79b7c9e..9e0a3e5 100755 --- a/Theme/Backend/Lang/en.lang.php +++ b/Theme/Backend/Lang/en.lang.php @@ -17,6 +17,18 @@ return ['Admin' => [ ':s2' => 'Inactive', ':s3' => 'Timeout', ':s4' => 'Banned', + ':contact1' => 'Phone', + ':contact2' => 'Fax', + ':contact3' => 'Website', + ':contact4' => 'Email', + ':address1' => 'Home', + ':address2' => 'Business', + ':address3' => 'Delivery', + ':address4' => 'Billing', + ':address5' => 'Work', + ':address6' => 'Contract', + ':address8' => 'Education', + ':address99' => 'Other', 'Account' => 'Account', 'Account/Group' => 'Account/Group', 'Accounts' => 'Accounts', @@ -149,7 +161,7 @@ return ['Admin' => [ 'Status0' => 'None', 'Status1' => 'Active', 'Status2' => 'Inactive', - 'Status3' => 'Timehout', + 'Status3' => 'Timeout', 'Status4' => 'Banned', 'Tablespoon' => 'Tablespoon', 'Teaspoon' => 'Teaspoon', @@ -189,7 +201,7 @@ return ['Admin' => [ 'active' => 'active', 'available' => 'available', 'i:LoginRetries' => 'Amount of allowed retries (-1 = unlimited)', - 'i:PasswordChangeInterval' => 'Interval in which passwards need to be changed (-1 = never)', + 'i:PasswordChangeInterval' => 'Interval in which passwords need to be changed (-1 = never)', 'i:PasswordHistory' => 'New password has to be different from the last N passwords', 'i:PasswordRegex' => 'Password requirement for users', 'i:TimeoutPeriod' => 'Timeout period after too many logins', @@ -200,4 +212,13 @@ return ['Admin' => [ 'i:rem' => 'IP address or URL for remote access.', 'i:timef' => 'Time format.', 'inactive' => 'inactive', + 'FAO' => 'FAO', + 'Addition' => 'Addition', + 'Postal' => 'Postal', + 'State' => 'State', + 'Addresses' => 'Addresses', + 'Contact' => 'Contact', + 'Contacts' => 'Contacts', + 'Subtype' => 'Subtype', + 'Content' => 'Content', ]]; diff --git a/Theme/Backend/accounts-list.tpl.php b/Theme/Backend/accounts-list.tpl.php index cd0b093..3c19bb2 100755 --- a/Theme/Backend/accounts-list.tpl.php +++ b/Theme/Backend/accounts-list.tpl.php @@ -89,14 +89,14 @@ echo $this->data['nav']->render(); ?> $url = UriFactory::build('{/base}/admin/account/settings?{?}&id=' . $value->id); $color = 'darkred'; - if ($value->getStatus() === AccountStatus::ACTIVE) { $color = 'green'; } - elseif ($value->getStatus() === AccountStatus::INACTIVE) { $color = 'darkblue'; } - elseif ($value->getStatus() === AccountStatus::TIMEOUT) { $color = 'purple'; } - elseif ($value->getStatus() === AccountStatus::BANNED) { $color = 'red'; } + if ($value->status === AccountStatus::ACTIVE) { $color = 'green'; } + elseif ($value->status === AccountStatus::INACTIVE) { $color = 'darkblue'; } + elseif ($value->status === AccountStatus::TIMEOUT) { $color = 'purple'; } + elseif ($value->status === AccountStatus::BANNED) { $color = 'red'; } ?> id; ?> - getHtml('Status'. $value->getStatus()); ?> + getHtml('Status'. $value->status); ?> printHtml($this->renderUserName('%3$s %2$s %1$s', [$value->name1, $value->name2, $value->name3, $value->login])); ?> printHtml($value->getLastActive()->format('Y-m-d H:i:s')); ?> printHtml($value->createdAt->format('Y-m-d H:i:s')); ?> diff --git a/Theme/Backend/accounts-single.tpl.php b/Theme/Backend/accounts-view.tpl.php old mode 100755 new mode 100644 similarity index 98% rename from Theme/Backend/accounts-single.tpl.php rename to Theme/Backend/accounts-view.tpl.php index a607faf..41d66a8 --- a/Theme/Backend/accounts-single.tpl.php +++ b/Theme/Backend/accounts-view.tpl.php @@ -85,17 +85,17 @@ echo $this->data['nav']->render(); ?>
@@ -153,7 +153,7 @@ echo $this->data['nav']->render(); ?> "key": 1, "listener": "click", "action": [ {"key": 1, "type": "event.prevent"}, {"key": 2, "type": "dom.getvalue", "base": "", "selector": "#iId"}, - {"key": 3, "type": "message.request", "uri": "{/base}/{/lang}/api/profile", "method": "PUT", "request_type": "json"}, + {"key": 3, "type": "message.request", "uri": "{/base}/{/lang}/api/view", "method": "PUT", "request_type": "json"}, {"key": 4, "type": "message.log"} ] } @@ -538,15 +538,15 @@ echo $this->data['nav']->render(); ?>
@@ -916,7 +916,7 @@ echo $this->data['nav']->render(); ?> $audit) : ++$count; - $url = UriFactory::build('{/base}/admin/audit/single?id=' . $audit->id); ?> + $url = UriFactory::build('{/base}/admin/audit/view?id=' . $audit->id); ?> id; ?> printHtml($audit->module); ?> diff --git a/Theme/Backend/groups-list.tpl.php b/Theme/Backend/groups-list.tpl.php index 7f1ef5f..78f895a 100755 --- a/Theme/Backend/groups-list.tpl.php +++ b/Theme/Backend/groups-list.tpl.php @@ -87,14 +87,14 @@ echo $this->data['nav']->render(); ?> foreach ($groups as $key => $value) : ++$c; $url = UriFactory::build('{/base}/admin/group/settings?{?}&id=' . $value->id); - $color = 'darkred'; - if ($value->getStatus() === GroupStatus::ACTIVE) { $color = 'green'; } - elseif ($value->getStatus() === GroupStatus::INACTIVE) { $color = 'darkblue'; } - elseif ($value->getStatus() === GroupStatus::HIDDEN) { $color = 'purple'; } + $color = 'darkred'; + if ($value->status === GroupStatus::ACTIVE) { $color = 'green'; } + elseif ($value->status === GroupStatus::INACTIVE) { $color = 'darkblue'; } + elseif ($value->status === GroupStatus::HIDDEN) { $color = 'purple'; } ?> id; ?> - getHtml('Status'. $value->getStatus()); ?> + getHtml('Status' . $value->status); ?> printHtml($value->name); ?> id] ?? 0; ?> diff --git a/Theme/Backend/groups-single.tpl.php b/Theme/Backend/groups-view.tpl.php old mode 100755 new mode 100644 similarity index 99% rename from Theme/Backend/groups-single.tpl.php rename to Theme/Backend/groups-view.tpl.php index ffaa3e8..fc3e526 --- a/Theme/Backend/groups-single.tpl.php +++ b/Theme/Backend/groups-view.tpl.php @@ -29,7 +29,7 @@ $audits = $this->data['auditlogs'] ?? []; $previous = empty($audits) ? HttpHeader::getAllHeaders()['Referer'] ?? 'admin/group/settings?id={?id}#{\#}' : 'admin/group/settings?{?}&audit=' . \reset($audits)->id . '&ptype=p#{\#}'; -$next = empty($audits) +$next = empty($audits) ? HttpHeader::getAllHeaders()['Referer'] ?? 'admin/group/settings?id={?id}#{\#}' : 'admin/group/settings?{?}&audit=' . \end($audits)->id . '&ptype=n#{\#}'; @@ -65,7 +65,7 @@ echo $this->data['nav']->render(); ?>
@@ -387,7 +387,7 @@ echo $this->data['nav']->render(); ?> getHtml('Date', 'Auditor'); ?> $audit) : ++$count; - $url = UriFactory::build('{/base}/admin/audit/single?{?}&id=' . $audit->id); ?> + $url = UriFactory::build('{/base}/admin/audit/view?{?}&id=' . $audit->id); ?> id; ?> printHtml($audit->module); ?> diff --git a/Theme/Backend/modules-list.tpl.php b/Theme/Backend/modules-list.tpl.php index 356d5db..e37e52f 100755 --- a/Theme/Backend/modules-list.tpl.php +++ b/Theme/Backend/modules-list.tpl.php @@ -85,7 +85,7 @@ $tableView->setObjects($modules); } ?> - getId(); ?> + id; ?> printHtml($module->getExternalName()); ?> printHtml($module->getVersion()); ?> diff --git a/Theme/Backend/modules-log.tpl.php b/Theme/Backend/modules-log.tpl.php index e96387b..8249e25 100755 --- a/Theme/Backend/modules-log.tpl.php +++ b/Theme/Backend/modules-log.tpl.php @@ -54,7 +54,7 @@ echo $this->data['nav']->render(); $audit) : ++$count; - $url = UriFactory::build('{/base}/admin/audit/single?{?}&id=' . $audit->id); ?> + $url = UriFactory::build('{/base}/admin/audit/view?{?}&id=' . $audit->id); ?> id; ?> printHtml($audit->module); ?> diff --git a/Theme/Backend/modules-settings.tpl.php b/Theme/Backend/modules-settings.tpl.php index f6c5af9..efd49b8 100755 --- a/Theme/Backend/modules-settings.tpl.php +++ b/Theme/Backend/modules-settings.tpl.php @@ -121,7 +121,7 @@ else : ?> $name = $this->getData('settings_class')::getName($setting->name); if (!\is_string($name)) { - $name= $setting->name; + $name = $setting->name; } } ?> diff --git a/Theme/Backend/page-list.tpl.php b/Theme/Backend/page-list.tpl.php index e424cfd..286f285 100755 --- a/Theme/Backend/page-list.tpl.php +++ b/Theme/Backend/page-list.tpl.php @@ -89,16 +89,16 @@ echo $this->data['nav']->render(); ?> filter_alt - $value) : ++$c; - $url = UriFactory::build('{/base}/admin/account/settings?{?}&id=' . $value->id); - $color = 'darkred'; - if ($value->getStatus() === AccountStatus::ACTIVE) { $color = 'green'; } - elseif ($value->getStatus() === AccountStatus::INACTIVE) { $color = 'darkblue'; } - elseif ($value->getStatus() === AccountStatus::TIMEOUT) { $color = 'purple'; } - elseif ($value->getStatus() === AccountStatus::BANNED) { $color = 'red'; } ?> + $value) : ++$c; + $url = UriFactory::build('{/base}/admin/account/settings?{?}&id=' . $value->id); + $color = 'darkred'; + if ($value->status === AccountStatus::ACTIVE) { $color = 'green'; } + elseif ($value->status === AccountStatus::INACTIVE) { $color = 'darkblue'; } + elseif ($value->status === AccountStatus::TIMEOUT) { $color = 'purple'; } + elseif ($value->status === AccountStatus::BANNED) { $color = 'red'; } ?> id; ?> - getHtml('Status'. $value->getStatus()); ?> + getHtml('Status' . $value->status); ?> printHtml($this->renderUserName('%3$s %2$s %1$s', [$value->name1, $value->name2, $value->name3, $value->login])); ?> printHtml($value->getLastActive()->format('Y-m-d H:i:s')); ?> printHtml($value->createdAt->format('Y-m-d H:i:s')); ?> diff --git a/Theme/Backend/settings-general.tpl.php b/Theme/Backend/settings-general.tpl.php index 22f7700..f4b42cd 100755 --- a/Theme/Backend/settings-general.tpl.php +++ b/Theme/Backend/settings-general.tpl.php @@ -37,7 +37,7 @@ $lengths = \phpOMS\Utils\Converter\LengthType::getConstants(); $volumes = \phpOMS\Utils\Converter\VolumeType::getConstants(); $temperatures = \phpOMS\Utils\Converter\TemperatureType::getConstants(); -$l11n = $this->getData('default_localization') ?? new NullLocalization(); +$l11n = $this->data['default_localization'] ?? new NullLocalization(); ?>
@@ -186,7 +186,7 @@ $l11n = $this->getData('default_localization') ?? new NullLocalization();
@@ -267,7 +267,7 @@ $l11n = $this->getData('default_localization') ?? new NullLocalization(); @@ -275,8 +275,8 @@ $l11n = $this->getData('default_localization') ?? new NullLocalization();
diff --git a/tests/Autoloader.php b/tests/Autoloader.php index 450f830..02aa1fa 100755 --- a/tests/Autoloader.php +++ b/tests/Autoloader.php @@ -75,8 +75,8 @@ final class Autoloader */ public static function defaultAutoloader(string $class) : void { - $class = \ltrim($class, '\\'); - $class = \strtr($class, '_\\', '//'); + $class = \ltrim($class, '\\'); + $class = \strtr($class, '_\\', '//'); if (\stripos($class, 'Web/Backend') !== false || \stripos($class, 'Web/Api') !== false) { $class = \is_dir(__DIR__ . '/Web') ? $class : \str_replace('Web/', 'MainRepository/Web/', $class); diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php index ddc049d..aab174a 100755 --- a/tests/Bootstrap.php +++ b/tests/Bootstrap.php @@ -1,4 +1,15 @@ [ + 'db' => [ 'core' => [ 'masters' => [ - 'admin' => [ + 'admin' => [ 'db' => 'mysql', /* db type */ 'host' => '127.0.0.1', /* db host address */ 'port' => '3306', /* db host port */ @@ -80,7 +91,7 @@ $CONFIG = [ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'insert' => [ + 'insert' => [ 'db' => 'mysql', /* db type */ 'host' => '127.0.0.1', /* db host address */ 'port' => '3306', /* db host port */ @@ -90,7 +101,7 @@ $CONFIG = [ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'select' => [ + 'select' => [ 'db' => 'mysql', /* db type */ 'host' => '127.0.0.1', /* db host address */ 'port' => '3306', /* db host port */ @@ -100,7 +111,7 @@ $CONFIG = [ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'update' => [ + 'update' => [ 'db' => 'mysql', /* db type */ 'host' => '127.0.0.1', /* db host address */ 'port' => '3306', /* db host port */ @@ -110,7 +121,7 @@ $CONFIG = [ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'delete' => [ + 'delete' => [ 'db' => 'mysql', /* db type */ 'host' => '127.0.0.1', /* db host address */ 'port' => '3306', /* db host port */ @@ -120,7 +131,7 @@ $CONFIG = [ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'schema' => [ + 'schema' => [ 'db' => 'mysql', /* db type */ 'host' => '127.0.0.1', /* db host address */ 'port' => '3306', /* db host port */ @@ -132,7 +143,7 @@ $CONFIG = [ ], ], 'postgresql' => [ - 'admin' => [ + 'admin' => [ 'db' => 'pgsql', /* db type */ 'host' => '127.0.0.1', /* db host address */ 'port' => '5432', /* db host port */ @@ -142,7 +153,7 @@ $CONFIG = [ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'insert' => [ + 'insert' => [ 'db' => 'pgsql', /* db type */ 'host' => '127.0.0.1', /* db host address */ 'port' => '5432', /* db host port */ @@ -152,7 +163,7 @@ $CONFIG = [ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'select' => [ + 'select' => [ 'db' => 'pgsql', /* db type */ 'host' => '127.0.0.1', /* db host address */ 'port' => '5432', /* db host port */ @@ -162,7 +173,7 @@ $CONFIG = [ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'update' => [ + 'update' => [ 'db' => 'pgsql', /* db type */ 'host' => '127.0.0.1', /* db host address */ 'port' => '5432', /* db host port */ @@ -172,7 +183,7 @@ $CONFIG = [ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'delete' => [ + 'delete' => [ 'db' => 'pgsql', /* db type */ 'host' => '127.0.0.1', /* db host address */ 'port' => '5432', /* db host port */ @@ -182,7 +193,7 @@ $CONFIG = [ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'schema' => [ + 'schema' => [ 'db' => 'pgsql', /* db type */ 'host' => '127.0.0.1', /* db host address */ 'port' => '5432', /* db host port */ @@ -194,37 +205,37 @@ $CONFIG = [ ], ], 'sqlite' => [ - 'admin' => [ + 'admin' => [ 'db' => 'sqlite', /* db type */ 'database' => __DIR__ . '/../Karaka/phpOMS/Localization/Defaults/localization.sqlite', /* db name */ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'insert' => [ + 'insert' => [ 'db' => 'sqlite', /* db type */ 'database' => __DIR__ . '/../Karaka/phpOMS/Localization/Defaults/localization.sqlite', /* db name */ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'select' => [ + 'select' => [ 'db' => 'sqlite', /* db type */ 'database' => __DIR__ . '/../Karaka/phpOMS/Localization/Defaults/localization.sqlite', /* db name */ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'update' => [ + 'update' => [ 'db' => 'sqlite', /* db type */ 'database' => __DIR__ . '/../Karaka/phpOMS/Localization/Defaults/localization.sqlite', /* db name */ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'delete' => [ + 'delete' => [ 'db' => 'sqlite', /* db type */ 'database' => __DIR__ . '/../Karaka/phpOMS/Localization/Defaults/localization.sqlite', /* db name */ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'schema' => [ + 'schema' => [ 'db' => 'sqlite', /* db type */ 'database' => __DIR__ . '/../Karaka/phpOMS/Localization/Defaults/localization.sqlite', /* db name */ 'weight' => 1000, /* db table prefix */ @@ -232,7 +243,7 @@ $CONFIG = [ ], ], 'mssql' => [ - 'admin' => [ + 'admin' => [ 'db' => 'mssql', /* db type */ 'host' => '127.0.0.1', /* db host address */ 'port' => '1433', /* db host port */ @@ -242,7 +253,7 @@ $CONFIG = [ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'insert' => [ + 'insert' => [ 'db' => 'mssql', /* db type */ 'host' => '127.0.0.1', /* db host address */ 'port' => '1433', /* db host port */ @@ -252,7 +263,7 @@ $CONFIG = [ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'select' => [ + 'select' => [ 'db' => 'mssql', /* db type */ 'host' => '127.0.0.1', /* db host address */ 'port' => '1433', /* db host port */ @@ -262,7 +273,7 @@ $CONFIG = [ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'update' => [ + 'update' => [ 'db' => 'mssql', /* db type */ 'host' => '127.0.0.1', /* db host address */ 'port' => '1433', /* db host port */ @@ -272,7 +283,7 @@ $CONFIG = [ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'delete' => [ + 'delete' => [ 'db' => 'mssql', /* db type */ 'host' => '127.0.0.1', /* db host address */ 'port' => '1433', /* db host port */ @@ -282,7 +293,7 @@ $CONFIG = [ 'weight' => 1000, /* db table prefix */ 'datetimeformat' => 'Y-m-d H:i:s', ], - 'schema' => [ + 'schema' => [ 'db' => 'mssql', /* db type */ 'host' => '127.0.0.1', /* db host address */ 'port' => '1433', /* db host port */ @@ -322,16 +333,16 @@ $CONFIG = [ 'password' => '123456', ], ], - 'log' => [ + 'log' => [ 'file' => [ 'path' => __DIR__ . '/Logs', ], ], - 'page' => [ + 'page' => [ 'root' => '/', 'https' => false, ], - 'app' => [ + 'app' => [ 'path' => __DIR__, 'default' => [ 'app' => 'Backend', @@ -350,7 +361,7 @@ $CONFIG = [ ], ], ], - 'socket' => [ + 'socket' => [ 'master' => [ 'host' => '127.0.0.1', 'limit' => 300, @@ -360,7 +371,7 @@ $CONFIG = [ 'language' => [ 'en', ], - 'apis' => [ + 'apis' => [ ], ]; diff --git a/tests/Controller/Api/ApiControllerAccountTrait.php b/tests/Controller/Api/ApiControllerAccountTrait.php index 932adf0..6a329bf 100755 --- a/tests/Controller/Api/ApiControllerAccountTrait.php +++ b/tests/Controller/Api/ApiControllerAccountTrait.php @@ -19,7 +19,6 @@ use phpOMS\Account\AccountType; use phpOMS\Message\Http\HttpRequest; use phpOMS\Message\Http\HttpResponse; use phpOMS\Message\Http\RequestStatusCode; -use phpOMS\Uri\HttpUri; trait ApiControllerAccountTrait { @@ -31,7 +30,7 @@ trait ApiControllerAccountTrait public function testApiAccountGet() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('id', '1'); @@ -50,7 +49,7 @@ trait ApiControllerAccountTrait public function testApiAccountUpdate() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('id', 1); @@ -72,7 +71,7 @@ trait ApiControllerAccountTrait public function testApiAccountFind() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('search', 'admin'); @@ -90,7 +89,7 @@ trait ApiControllerAccountTrait public function testApiAccountAndProfileCreate() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('user', 'guest'); @@ -113,7 +112,7 @@ trait ApiControllerAccountTrait public function testApiAccountCreateWithCustomLocale() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('user', 'guest2'); @@ -138,7 +137,7 @@ trait ApiControllerAccountTrait public function testApiAccountDelete() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; // mustn't create a profile otherwise it will not be possible to delete the account because of FK constraints @@ -162,7 +161,7 @@ trait ApiControllerAccountTrait public function testApiAccountCreateInvalid() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('status', 999); @@ -180,7 +179,7 @@ trait ApiControllerAccountTrait public function testApiAddRemoveGroupToAccount() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('account', 1); @@ -203,7 +202,7 @@ trait ApiControllerAccountTrait public function testApiRemoveAdminGroupFromOneselfAccount() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('account', 1); @@ -220,7 +219,7 @@ trait ApiControllerAccountTrait public function testApiAccountLogin() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('user', 'admin'); @@ -237,7 +236,7 @@ trait ApiControllerAccountTrait public function testApiAccountLoginInvalid() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('user', 'admin'); @@ -254,7 +253,7 @@ trait ApiControllerAccountTrait public function testApiAccountLogout() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('user', 'admin'); diff --git a/tests/Controller/Api/ApiControllerApplicationTrait.php b/tests/Controller/Api/ApiControllerApplicationTrait.php index 1bd8f1d..e5b9c88 100755 --- a/tests/Controller/Api/ApiControllerApplicationTrait.php +++ b/tests/Controller/Api/ApiControllerApplicationTrait.php @@ -17,7 +17,6 @@ namespace Modules\Admin\tests\Controller\Api; use phpOMS\Message\Http\HttpRequest; use phpOMS\Message\Http\HttpResponse; use phpOMS\Message\Http\RequestStatusCode; -use phpOMS\Uri\HttpUri; trait ApiControllerApplicationTrait { @@ -28,7 +27,7 @@ trait ApiControllerApplicationTrait public function testApiInvalidAppplicationPathInstall() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('appSrc', 'invalid'); diff --git a/tests/Controller/Api/ApiControllerGroupTrait.php b/tests/Controller/Api/ApiControllerGroupTrait.php index 4bcca5a..550055f 100755 --- a/tests/Controller/Api/ApiControllerGroupTrait.php +++ b/tests/Controller/Api/ApiControllerGroupTrait.php @@ -18,7 +18,6 @@ use phpOMS\Account\GroupStatus; use phpOMS\Message\Http\HttpRequest; use phpOMS\Message\Http\HttpResponse; use phpOMS\Message\Http\RequestStatusCode; -use phpOMS\Uri\HttpUri; trait ApiControllerGroupTrait { @@ -30,7 +29,7 @@ trait ApiControllerGroupTrait public function testApiGroupGet() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('id', '3'); @@ -49,7 +48,7 @@ trait ApiControllerGroupTrait public function testApiGroupSet() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('id', '3'); @@ -72,7 +71,7 @@ trait ApiControllerGroupTrait public function testApiGroupFind() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('search', 'admin'); @@ -90,7 +89,7 @@ trait ApiControllerGroupTrait public function testApiGroupCreateDelete() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('name', 'test'); @@ -117,7 +116,7 @@ trait ApiControllerGroupTrait public function testApiGroupDeleteAdminInvalid() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; @@ -134,7 +133,7 @@ trait ApiControllerGroupTrait public function testApiGroupCreateInvalid() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('status', 999); @@ -152,7 +151,7 @@ trait ApiControllerGroupTrait public function testApiAddRemoveAccountToGroup() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('group', 1); @@ -175,7 +174,7 @@ trait ApiControllerGroupTrait public function testApiRemoveAdminAccountFromAdminGroup() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('group', 3); @@ -193,7 +192,7 @@ trait ApiControllerGroupTrait public function testApiAccountGroupFind() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('search', 'admin'); diff --git a/tests/Controller/Api/ApiControllerModuleTrait.php b/tests/Controller/Api/ApiControllerModuleTrait.php index 09769e9..97f2ae6 100755 --- a/tests/Controller/Api/ApiControllerModuleTrait.php +++ b/tests/Controller/Api/ApiControllerModuleTrait.php @@ -18,7 +18,6 @@ use Modules\Admin\Models\ModuleStatusUpdateType; use phpOMS\Message\Http\HttpRequest; use phpOMS\Message\Http\HttpResponse; use phpOMS\Message\Http\RequestStatusCode; -use phpOMS\Uri\HttpUri; trait ApiControllerModuleTrait { @@ -30,7 +29,7 @@ trait ApiControllerModuleTrait public function testApiModuleStatusUpdate() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('module', 'TestModule'); @@ -60,7 +59,7 @@ trait ApiControllerModuleTrait public function testApiModuleStatusUpdateEmptyModule() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; @@ -79,7 +78,7 @@ trait ApiControllerModuleTrait public function testApiModuleStatusUpdateInvalidStatus() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('module', 'TestModule'); @@ -97,7 +96,7 @@ trait ApiControllerModuleTrait public function testApiModuleStatusUpdateInvalidModule() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('module', 'invalid'); @@ -115,7 +114,7 @@ trait ApiControllerModuleTrait public function testApiReInit() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; diff --git a/tests/Controller/Api/ApiControllerPermissionTrait.php b/tests/Controller/Api/ApiControllerPermissionTrait.php index 3fb19c8..5b1c7d1 100755 --- a/tests/Controller/Api/ApiControllerPermissionTrait.php +++ b/tests/Controller/Api/ApiControllerPermissionTrait.php @@ -19,7 +19,6 @@ use phpOMS\Account\PermissionType; use phpOMS\Message\Http\HttpRequest; use phpOMS\Message\Http\HttpResponse; use phpOMS\Message\Http\RequestStatusCode; -use phpOMS\Uri\HttpUri; trait ApiControllerPermissionTrait { @@ -31,7 +30,7 @@ trait ApiControllerPermissionTrait public function testApiAddGroupPermission() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('permissionowner', PermissionOwner::GROUP); @@ -49,7 +48,7 @@ trait ApiControllerPermissionTrait public function testApiAddGroupPermissionToAdmin() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('permissionowner', PermissionOwner::GROUP); @@ -67,7 +66,7 @@ trait ApiControllerPermissionTrait public function testApiGroupPermissionGet() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('id', '2'); @@ -86,7 +85,7 @@ trait ApiControllerPermissionTrait public function testApiGroupPermissionCreateDelete() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('permissionowner', PermissionOwner::GROUP); @@ -111,7 +110,7 @@ trait ApiControllerPermissionTrait public function testApiAddGroupPermissionInvalidData() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('permissionowner', PermissionOwner::GROUP); @@ -128,7 +127,7 @@ trait ApiControllerPermissionTrait public function testApiAddGroupPermissionInvalidType() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('permissionowner', PermissionOwner::ACCOUNT); @@ -146,7 +145,7 @@ trait ApiControllerPermissionTrait public function testApiGroupPermissionUpdate() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('id', 1); @@ -173,7 +172,7 @@ trait ApiControllerPermissionTrait public function testApiAddAccountPermission() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('permissionowner', PermissionOwner::ACCOUNT); @@ -192,7 +191,7 @@ trait ApiControllerPermissionTrait public function testApiAccountPermissionGet() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('id', '1'); @@ -211,7 +210,7 @@ trait ApiControllerPermissionTrait public function testApiAccountPermissionCreateDelete() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('permissionowner', PermissionOwner::ACCOUNT); @@ -236,7 +235,7 @@ trait ApiControllerPermissionTrait public function testApiAddAccountPermissionInvalidData() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('permissionowner', PermissionOwner::ACCOUNT); @@ -253,7 +252,7 @@ trait ApiControllerPermissionTrait public function testApiAddAccountPermissionInvalidType() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('permissionowner', PermissionOwner::GROUP); @@ -271,7 +270,7 @@ trait ApiControllerPermissionTrait public function testApiAccountPermissionUpdate() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('id', 1); diff --git a/tests/Controller/Api/ApiControllerSettingsTrait.php b/tests/Controller/Api/ApiControllerSettingsTrait.php index 10f3396..0277bc6 100755 --- a/tests/Controller/Api/ApiControllerSettingsTrait.php +++ b/tests/Controller/Api/ApiControllerSettingsTrait.php @@ -18,7 +18,6 @@ use Modules\Admin\Models\SettingsEnum; use phpOMS\Message\Http\HttpRequest; use phpOMS\Message\Http\HttpResponse; use phpOMS\Message\Http\RequestStatusCode; -use phpOMS\Uri\HttpUri; trait ApiControllerSettingsTrait { @@ -30,7 +29,7 @@ trait ApiControllerSettingsTrait public function testApiSettingsGet() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('name', SettingsEnum::PASSWORD_INTERVAL); @@ -47,7 +46,7 @@ trait ApiControllerSettingsTrait public function testApiSettingsSet() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('settings', \json_encode([['name' => SettingsEnum::PASSWORD_INTERVAL, 'content' => '60']])); @@ -68,7 +67,7 @@ trait ApiControllerSettingsTrait public function testApiAccountLocalizationLoadSet() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('account_id', 1); @@ -93,7 +92,7 @@ trait ApiControllerSettingsTrait public function testApiAccountLocalizationSet() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('account_id', 1); @@ -107,7 +106,7 @@ trait ApiControllerSettingsTrait $this->module->apiSettingsAccountLocalizationSet($request, $response); $l11n = $response->getDataArray('')['response']; - self::assertEquals($l11n->getCurrency(), 'EUR'); + self::assertEquals($l11n->currency, 'EUR'); } /** @@ -117,7 +116,7 @@ trait ApiControllerSettingsTrait public function testInvalidPermissionAccountLocalizationSet() : void { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 2; $request->setData('account_id', 1); diff --git a/tests/Controller/ApiControllerTest.php b/tests/Controller/ApiControllerTest.php index 333553d..238595a 100755 --- a/tests/Controller/ApiControllerTest.php +++ b/tests/Controller/ApiControllerTest.php @@ -59,13 +59,13 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase protected string $appName = 'Api'; }; - $this->app->dbPool = $GLOBALS['dbpool']; - $this->app->unitId = 1; - $this->app->accountManager = new AccountManager($GLOBALS['session']); - $this->app->appSettings = new CoreSettings(); - $this->app->moduleManager = new ModuleManager($this->app, __DIR__ . '/../../../../Modules/'); - $this->app->dispatcher = new Dispatcher($this->app); - $this->app->eventManager = new EventManager($this->app->dispatcher); + $this->app->dbPool = $GLOBALS['dbpool']; + $this->app->unitId = 1; + $this->app->accountManager = new AccountManager($GLOBALS['session']); + $this->app->appSettings = new CoreSettings(); + $this->app->moduleManager = new ModuleManager($this->app, __DIR__ . '/../../../../Modules/'); + $this->app->dispatcher = new Dispatcher($this->app); + $this->app->eventManager = new EventManager($this->app->dispatcher); $this->app->eventManager->importFromFile(__DIR__ . '/../../../../Web/Api/Hooks.php'); $this->app->sessionManager = new HttpSession(36000); $this->app->l11nManager = new L11nManager(); diff --git a/tests/Helper.php b/tests/Helper.php index ac892c1..8b780a3 100644 --- a/tests/Helper.php +++ b/tests/Helper.php @@ -38,8 +38,8 @@ class Helper { $account->name3 = \ucfirst(Text::LOREM_IPSUM[\mt_rand(0, $LOREM_COUNT - 1)]); $account->tries = 0; $account->setEmail(Email::generateEmail()); - $account->setStatus(AccountStatus::ACTIVE); - $account->setType(AccountType::USER); + $account->status = AccountStatus::ACTIVE; + $account->type = AccountType::USER; AccountMapper::create()->execute($account); diff --git a/tests/Models/AccountMapperTest.php b/tests/Models/AccountMapperTest.php index ccbd0f7..4c2bd1d 100755 --- a/tests/Models/AccountMapperTest.php +++ b/tests/Models/AccountMapperTest.php @@ -44,8 +44,8 @@ final class AccountMapperTest extends \PHPUnit\Framework\TestCase $account->name3 = 'Duck'; $account->tries = 0; $account->setEmail('d.duck@duckburg.com'); - $account->setStatus(AccountStatus::ACTIVE); - $account->setType(AccountType::USER); + $account->status = AccountStatus::ACTIVE; + $account->type = AccountType::USER; $id = AccountMapper::create()->execute($account); self::assertGreaterThan(0, $account->id); @@ -57,8 +57,8 @@ final class AccountMapperTest extends \PHPUnit\Framework\TestCase self::assertEquals($account->name1, $accountR->name1); self::assertEquals($account->name2, $accountR->name2); self::assertEquals($account->name3, $accountR->name3); - self::assertEquals($account->getStatus(), $accountR->getStatus()); - self::assertEquals($account->getType(), $accountR->getType()); + self::assertEquals($account->status, $accountR->status); + self::assertEquals($account->type, $accountR->type); self::assertEquals($account->getEmail(), $accountR->getEmail()); self::assertEquals($account->tries, $accountR->tries); } @@ -126,13 +126,13 @@ final class AccountMapperTest extends \PHPUnit\Framework\TestCase public function testInvalidLoginAccountStatus() : void { /** @var Account $accountR */ - $accountR = AccountMapper::get()->where('id', 1)->execute(); - $accountR->setStatus(AccountStatus::BANNED); + $accountR = AccountMapper::get()->where('id', 1)->execute(); + $accountR->status = AccountStatus::BANNED; AccountMapper::update()->execute($accountR); self::assertEquals(LoginReturnType::INACTIVE, AccountMapper::login($accountR->login, 'orange')); - $accountR->setStatus(AccountStatus::ACTIVE); + $accountR->status = AccountStatus::ACTIVE; AccountMapper::update()->execute($accountR); } diff --git a/tests/Models/AddressMapperTest.php b/tests/Models/AddressMapperTest.php index 8347a57..c0273f1 100755 --- a/tests/Models/AddressMapperTest.php +++ b/tests/Models/AddressMapperTest.php @@ -37,13 +37,13 @@ final class AddressMapperTest extends \PHPUnit\Framework\TestCase $address->fao = 'fao'; $address->addressAddition = 'addition'; $address->postal = '0123456789'; - $address->setType(AddressType::BUSINESS); - $address->city = 'city'; - $address->address = 'Some address here'; - $address->state = 'This is a state 123'; - $address->setCountry('DE'); - $address->lat = 12.1; - $address->lon = 11.2; + $address->type = AddressType::BUSINESS; + $address->city = 'city'; + $address->address = 'Some address here'; + $address->state = 'This is a state 123'; + $address->country = 'DE'; + $address->lat = 12.1; + $address->lon = 11.2; $id = AddressMapper::create()->execute($address); self::assertGreaterThan(0, $address->id); @@ -53,7 +53,7 @@ final class AddressMapperTest extends \PHPUnit\Framework\TestCase self::assertEquals($address->name, $addressR->name); self::assertEquals($address->fao, $addressR->fao); self::assertEquals($address->addressAddition, $addressR->addressAddition); - self::assertEquals($address->getType(), $addressR->getType()); + self::assertEquals($address->type, $addressR->type); self::assertEquals($address->postal, $addressR->postal); self::assertEquals($address->address, $addressR->address); self::assertEquals($address->state, $addressR->state); diff --git a/tests/Models/ModuleTest.php b/tests/Models/ModuleTest.php index 9480584..ef0f926 100755 --- a/tests/Models/ModuleTest.php +++ b/tests/Models/ModuleTest.php @@ -44,7 +44,7 @@ final class ModuleTest extends \PHPUnit\Framework\TestCase self::assertEquals('', $this->module->id); self::assertInstanceOf('\DateTimeImmutable', $this->module->createdAt); self::assertEquals('', $this->module->name); - self::assertEquals(ModuleStatus::INACTIVE, $this->module->getStatus()); + self::assertEquals(ModuleStatus::INACTIVE, $this->module->status); self::assertEquals(\json_encode($this->module->jsonSerialize()), $this->module->__toString()); self::assertEquals($this->module->jsonSerialize(), $this->module->toArray()); } @@ -67,8 +67,8 @@ final class ModuleTest extends \PHPUnit\Framework\TestCase */ public function testStatusInputOutput() : void { - $this->module->setStatus(ModuleStatus::ACTIVE); - self::assertEquals(ModuleStatus::ACTIVE, $this->module->getStatus()); + $this->module->status = ModuleStatus::ACTIVE; + self::assertEquals(ModuleStatus::ACTIVE, $this->module->status); } /** @@ -81,16 +81,4 @@ final class ModuleTest extends \PHPUnit\Framework\TestCase self::assertEquals(\json_encode($this->module->jsonSerialize()), $this->module->__toString()); self::assertEquals($this->module->jsonSerialize(), $this->module->toArray()); } - - /** - * @testdox A invalid status throws a InvalidEnumValue exception - * @covers Modules\Admin\Models\Module - * @group module - */ - public function testInvalidStatus() : void - { - $this->expectException(\phpOMS\Stdlib\Base\Exception\InvalidEnumValue::class); - - $this->module->setStatus(9999); - } }