diff --git a/Admin/Install/Navigation.install.json b/Admin/Install/Navigation.install.json index c0afb28..9102ad1 100755 --- a/Admin/Install/Navigation.install.json +++ b/Admin/Install/Navigation.install.json @@ -114,7 +114,7 @@ "uri": "{/lang}/{/app}/admin/module/list", "target": "self", "icon": null, - "order": 5, + "order": 6, "from": "Admin", "permission": { "permission": 2, "category": null, "element": null }, "parent": 1000101001, diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 2ecec21..03d0e0d 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -342,7 +342,7 @@ final class ApiController extends Controller $mail = new Email(); $mail->setFrom($emailSettings[SettingsEnum::MAIL_SERVER_ADDR], 'Karaka'); - $mail->addTo($account->email, \trim($account->name1 . ' ' . $account->name2 . ' ' . $account->name3)); + $mail->addTo($account->getEmail(), \trim($account->name1 . ' ' . $account->name2 . ' ' . $account->name3)); $mail->subject = 'Karaka: Password reset'; $mail->body = ''; $mail->msgHTML('Your new password: ' . $pass . '' diff --git a/Controller/BackendController.php b/Controller/BackendController.php index 9718698..aa03c9c 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -218,13 +218,9 @@ final class BackendController extends Controller $view->addData('account', $account); /** @var \Modules\Admin\Models\AccountPermission[] $permissions */ - $permissions = AccountPermissionMapper::getAll()->where('account', (int) $request->getData('id'))->execute(); - - if (!isset($permissions) || $permissions instanceof NullAccountPermission) { - $permissions = []; - } elseif (!\is_array($permissions)) { - $permissions = [$permissions]; - } + $permissions = AccountPermissionMapper::getAll() + ->where('account', (int) $request->getData('id')) + ->execute(); $view->addData('permissions', $permissions); @@ -396,14 +392,10 @@ final class BackendController extends Controller GroupMapper::get()->with('accounts')->where('id', (int) $request->getData('id'))->execute() ); - /** @var null|\Modules\Admin\Models\GroupPermission[] $permissions */ - $permissions = GroupPermissionMapper::getAll()->where('group', (int) $request->getData('id'))->execute(); - - if ($permissions === null || $permissions instanceof NullGroupPermission) { - $permissions = []; - } elseif (!\is_array($permissions)) { - $permissions = [$permissions]; - } + /** @var \Modules\Admin\Models\GroupPermission[] $permissions */ + $permissions = GroupPermissionMapper::getAll() + ->where('group', (int) $request->getData('id')) + ->execute(); $view->addData('permissions', $permissions); @@ -712,16 +704,17 @@ final class BackendController extends Controller $id = $request->getData('id') ?? ''; - /** @var \Model\Setting[] $settings */ + /** @var null|\Model\NullSetting|\Model\Setting[] $settings */ $settings = SettingMapper::getAll()->where('module', $id)->execute(); if (!($settings instanceof NullSetting)) { $view->setData('settings', !\is_array($settings) ? [$settings] : $settings); } if ($request->getData('id') === 'Admin') { - $view->setTemplate('/Modules/' . ($request->getData('id') ?? '') . '/Admin/Settings/Theme/Backend/settings'); + $view->setTemplate('/Modules/' . $request->getData('id') . '/Admin/Settings/Theme/Backend/settings'); } elseif (\is_file(__DIR__ . '/../../' . ($request->getData('id') ?? '') . '/Admin/Settings/Theme/Backend/settings.tpl.php')) { - return $this->app->moduleManager->get($request->getData('id'))->viewModuleSettings($request, $response, $data); + return $this->app->moduleManager->get($request->getData('id') ?? '') + ->viewModuleSettings($request, $response, $data); } else { $view->setTemplate('/Modules/Admin/Theme/Backend/modules-settings'); } diff --git a/Models/AccountMapper.php b/Models/AccountMapper.php index e6864ec..9971ab7 100755 --- a/Models/AccountMapper.php +++ b/Models/AccountMapper.php @@ -127,8 +127,14 @@ class AccountMapper extends DataMapperFactory */ public static function getWithPermissions(int $id) : Account { - $account = self::get()->with('groups')->with('groups/permissions')->with('l11n')->where('id', $id)->execute(); - $groups = \array_keys($account->getGroups()); + $account = self::get() + ->with('groups') + ->with('groups/permissions') + ->with('l11n') + ->where('id', $id) + ->execute(); + + $groups = \array_keys($account->getGroups()); /** @var \Modules\Admin\Models\GroupPermission[] $groupPermissions */ $groupPermissions = empty($groups) @@ -139,17 +145,17 @@ class AccountMapper extends DataMapperFactory ->execute(); foreach ($groupPermissions as $permission) { - $account->addPermissions(\is_array($permission) ? $permission : [$permission]); + $account->addPermission($permission); } - /** @var \Modules\Admin\Models\AccountPermission[] $accountPermission */ + /** @var \Modules\Admin\Models\AccountPermission[] $accountPermissions */ $accountPermissions = AccountPermissionMapper::getAll() ->where('account', $id) ->where('element', null) ->execute(); foreach ($accountPermissions as $permission) { - $account->addPermissions(\is_array($permission) ? $permission : [$permission]); + $account->addPermission($permission); } return $account; diff --git a/Models/NullApp.php b/Models/NullApp.php new file mode 100644 index 0000000..68984c1 --- /dev/null +++ b/Models/NullApp.php @@ -0,0 +1,46 @@ +id = $id; + } + + /** + * {@inheritdoc} + */ + public function jsonSerialize() : mixed + { + return ['id' => $this->id]; + } +} diff --git a/Theme/Backend/accounts-single.tpl.php b/Theme/Backend/accounts-single.tpl.php index e18f99e..6e1e57d 100755 --- a/Theme/Backend/accounts-single.tpl.php +++ b/Theme/Backend/accounts-single.tpl.php @@ -831,11 +831,11 @@ echo $this->getData('nav')->render(); ?> ?> getId(); ?> - printHtml($audit->getModule()); ?> + printHtml($audit->module); ?> getType(); ?> - printHtml($audit->getTrigger()); ?> + printHtml($audit->trigger); ?> printHtml($audit->createdBy->login); ?> - printHtml($audit->getRef()); ?> + printHtml($audit->ref); ?> createdAt->format('Y-m-d H:i'); ?> diff --git a/Theme/Backend/groups-single.tpl.php b/Theme/Backend/groups-single.tpl.php index 52b4f2f..718422c 100755 --- a/Theme/Backend/groups-single.tpl.php +++ b/Theme/Backend/groups-single.tpl.php @@ -323,11 +323,11 @@ echo $this->getData('nav')->render(); ?> $url = UriFactory::build('{/lang}/{/app}/admin/audit/single?{?}&id=' . $audit->getId()); ?> getId(); ?> - printHtml($audit->getModule()); ?> + printHtml($audit->module); ?> getType(); ?> - printHtml($audit->getTrigger()); ?> + printHtml($audit->trigger); ?> printHtml($audit->createdBy->login); ?> - printHtml($audit->getRef()); ?> + printHtml($audit->ref); ?> createdAt->format('Y-m-d H:i'); ?> diff --git a/Theme/Backend/modules-log.tpl.php b/Theme/Backend/modules-log.tpl.php index 587b479..ecd07ce 100755 --- a/Theme/Backend/modules-log.tpl.php +++ b/Theme/Backend/modules-log.tpl.php @@ -57,12 +57,12 @@ echo $this->getData('nav')->render(); $url = UriFactory::build('{/lang}/{/app}/admin/audit/single?{?}&id=' . $audit->getId()); ?> getId(); ?> - printHtml($audit->getModule()); ?> + printHtml($audit->module); ?> getType(); ?> - printHtml($audit->getTrigger()); ?> - printHtml($audit->getContent()); ?> + printHtml($audit->trigger); ?> + printHtml($audit->content); ?> printHtml($audit->createdBy->login); ?> - printHtml($audit->getRef()); ?> + printHtml($audit->ref); ?> createdAt->format('Y-m-d H:i'); ?> diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php index d46fd31..b5d36a8 100755 --- a/tests/Bootstrap.php +++ b/tests/Bootstrap.php @@ -257,6 +257,25 @@ $CONFIG = [ 'root' => '/', 'https' => false, ], + 'app' => [ + 'path' => __DIR__, + 'default' => [ + 'app' => 'Backend', + 'id' => 'backend', + 'lang' => 'en', + 'theme' => 'Backend', + 'org' => 1, + ], + 'domains' => [ + '127.0.0.1' => [ + 'app' => 'Backend', + 'id' => 'backend', + 'lang' => 'en', + 'theme' => 'Backend', + 'org' => 1, + ], + ], + ], 'socket' => [ 'master' => [ 'host' => '127.0.0.1', diff --git a/tests/Models/AccountMapperTest.php b/tests/Models/AccountMapperTest.php index 74f80f8..5f96ace 100755 --- a/tests/Models/AccountMapperTest.php +++ b/tests/Models/AccountMapperTest.php @@ -146,7 +146,7 @@ final class AccountMapperTest extends \PHPUnit\Framework\TestCase TestUtils::setMember($accountR, 'password', ''); AccountMapper::update()->with('password')->execute($accountR); - self::assertEquals(LoginReturnType::EMPTY_PASSWORD, AccountMapper::login($accountR->login, 'orange')); + self::assertEquals(LoginReturnType::WRONG_PASSWORD, AccountMapper::login($accountR->login, 'invalidPassword')); $accountR->generatePassword('orange'); AccountMapper::update()->with('password')->execute($accountR);