diff --git a/.DS_Store b/.DS_Store index 5d1c4fb..c1ebbad 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..be2649c --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,15 @@ +name: Build and Publish + +on: + push: + branches: + - master + - develop + workflow_dispatch: + +jobs: + build: + uses: mikopbx/.github-workflows/.github/workflows/extension-publish.yml@master + with: + initial_version: "1.80" + secrets: inherit \ No newline at end of file diff --git a/App/Controllers/AccessGroupCDRFilterController.php b/App/Controllers/AccessGroupCDRFilterController.php index 7fe9ab4..86e860f 100644 --- a/App/Controllers/AccessGroupCDRFilterController.php +++ b/App/Controllers/AccessGroupCDRFilterController.php @@ -1,4 +1,5 @@ userid]['mobile'] = ''; } - $extensionTable[$extension->userid]['avatar'] = $this->url->get().'assets/img/unknownPerson.jpg'; + $extensionTable[$extension->userid]['avatar'] = $this->url->get() . 'assets/img/unknownPerson.jpg'; if ($extension->avatar) { $filename = md5($extension->avatar); $imgCacheDir = appPath('sites/admin-cabinet/assets/img/cache'); $imgFile = "{$imgCacheDir}/{$filename}.jpg"; if (file_exists($imgFile)) { - $extensionTable[$extension->userid]['avatar'] = $this->url->get()."assets/img/cache/{$filename}.jpg"; + $extensionTable[$extension->userid]['avatar'] = $this->url->get() . "assets/img/cache/{$filename}.jpg"; } } break; @@ -153,4 +155,4 @@ public function saveCdrFilter(string $accessGroupId, array $cdrFilterUsers): boo } return true; } -} \ No newline at end of file +} diff --git a/App/Controllers/AccessGroupsController.php b/App/Controllers/AccessGroupsController.php index bcb780b..70c4764 100644 --- a/App/Controllers/AccessGroupsController.php +++ b/App/Controllers/AccessGroupsController.php @@ -1,4 +1,5 @@ addJs('js/pbx/main/form.js', true) ->addJs('js/vendor/datatable/dataTables.semanticui.js', true) - ->addJs('js/cache/'.$this->moduleUniqueID.'/module-users-ui-modify-ag.js', true); + ->addJs('js/cache/' . $this->moduleUniqueID . '/module-users-ui-modify-ag.js', true); $record = AccessGroups::findFirstById($id); if ($record === null) { @@ -52,13 +54,13 @@ public function modifyAction(string $id = null): void $record->name = ''; $record->description = ''; } else { - $this->view->members = $this->getTheListOfUsersForDisplayInTheFilter($record->id??''); + $this->view->members = $this->getTheListOfUsersForDisplayInTheFilter($record->id ?? ''); $cdrFilterController = new AccessGroupCDRFilterController(); $this->view->cdrFilterMembers = $cdrFilterController->getTheListOfUsersForCDRFilter($record->id); } $groupRightsController = new AccessGroupsRightsController(); - $groupRights = $groupRightsController->getGroupRights($record->id??''); - $this->view->form = new AccessGroupForm($record,['groupRights'=>$groupRights]); + $groupRights = $groupRightsController->getGroupRights($record->id ?? ''); + $this->view->form = new AccessGroupForm($record, ['groupRights' => $groupRights]); $this->view->represent = $record->getRepresent(); $this->view->id = $id; $this->view->groupRights = $groupRights; @@ -72,7 +74,7 @@ public function modifyAction(string $id = null): void public function saveAction(): void { if (!$this->request->isPost()) { - return; + return; } $data = $this->request->getPost(); @@ -82,17 +84,17 @@ public function saveAction(): void if (array_key_exists('id', $data)) { $accessGroupEntity = AccessGroups::findFirstById($data['id']); } - if ($accessGroupEntity===null) { - $accessGroupEntity=new AccessGroups(); + if ($accessGroupEntity === null) { + $accessGroupEntity = new AccessGroups(); $accessGroupEntity->id = $data['id']; } - if (empty($data['cdrFilterMode'])){ + if (empty($data['cdrFilterMode'])) { $accessGroupEntity->cdrFilterMode = Constants::CDR_FILTER_DISABLED; } else { $accessGroupEntity->cdrFilterMode = $data['cdrFilterMode']; } - if (empty($data['homePage'])){ + if (empty($data['homePage'])) { $accessGroupEntity->homePage = $this->url->get('session/end'); } else { $accessGroupEntity->homePage = $data['homePage']; @@ -103,7 +105,7 @@ public function saveAction(): void $accessGroupEntity->fullAccess = $data['fullAccess']; // Save the access group object - if ($this->saveEntity($accessGroupEntity)===false){ + if ($this->saveEntity($accessGroupEntity) === false) { // If there are validation errors, display them and return false $this->db->rollback(); return; @@ -112,8 +114,8 @@ public function saveAction(): void // Save access group rights $accessGroupController = new AccessGroupsRightsController(); // Parse access group rights from the posted JSON string - $accessGroupRightsFromPost = json_decode($data['access_group_rights'], true)??[]; - if ($accessGroupController->saveAccessGroupRights($accessGroupEntity->id, $accessGroupRightsFromPost)===false){ + $accessGroupRightsFromPost = json_decode($data['access_group_rights'], true) ?? []; + if ($accessGroupController->saveAccessGroupRights($accessGroupEntity->id, $accessGroupRightsFromPost) === false) { $this->db->rollback(); return; } @@ -121,8 +123,8 @@ public function saveAction(): void // Save users credentials $usersCredentialsController = new UsersCredentialsController(); // Parse group members from the posted JSON string - $membersOfTheGroup = json_decode($data['members'], true)??[]; - if ($usersCredentialsController->saveUsersCredentials($accessGroupEntity->id, $membersOfTheGroup)===false){ + $membersOfTheGroup = json_decode($data['members'], true) ?? []; + if ($usersCredentialsController->saveUsersCredentials($accessGroupEntity->id, $membersOfTheGroup) === false) { $this->db->rollback(); return; } @@ -130,8 +132,8 @@ public function saveAction(): void // Save CDR filter $cdrFilterController = new AccessGroupCDRFilterController(); // Parse cdr filter from the posted JSON string - $cdrFilterUsers = json_decode($data['cdrFilter'], true)??[]; - if ($cdrFilterController->saveCdrFilter($accessGroupEntity->id, $cdrFilterUsers)===false){ + $cdrFilterUsers = json_decode($data['cdrFilter'], true) ?? []; + if ($cdrFilterController->saveCdrFilter($accessGroupEntity->id, $cdrFilterUsers) === false) { $this->db->rollback(); return; } @@ -144,7 +146,6 @@ public function saveAction(): void if (empty($data['id'])) { $this->view->reload = "module-users-u-i/access-groups/modify/{$accessGroupEntity->id}"; } - } /** @@ -165,5 +166,4 @@ public function deleteAction(string $groupId): void $this->forward('module-users-u-i/module-users-u-i/index'); } - -} \ No newline at end of file +} diff --git a/App/Controllers/AccessGroupsRightsController.php b/App/Controllers/AccessGroupsRightsController.php index d08adec..d4e8350 100644 --- a/App/Controllers/AccessGroupsRightsController.php +++ b/App/Controllers/AccessGroupsRightsController.php @@ -1,4 +1,5 @@ getExclusionsActionsControllers(); foreach ($controllerFiles as $file) { - $className = pathinfo($file)['filename']; $controllerClass = 'MikoPBX\AdminCabinet\Controllers\\' . $className; @@ -105,7 +106,6 @@ private function getAvailableUIControllersActions(): array if (count($publicMethods) > 0) { $controllers[Constants::ADMIN_CABINET]['APP'][$controllerClass] = $publicMethods; } - } // Sort the controllers array by translated controller name uksort($controllers[Constants::ADMIN_CABINET]['APP'], function ($a, $b) { @@ -137,11 +137,11 @@ private function getExclusionsActionsControllers(): array $arrayOfExclusions = []; // Get the list of linked controllers and actions which we hide from settings - foreach (UsersUIACL::getLinkedControllerActions() as $controllerClass=> $actions) { + foreach (UsersUIACL::getLinkedControllerActions() as $controllerClass => $actions) { // Iterate through the main controllers actions - foreach ($actions as $action=>$linkedControllers) { + foreach ($actions as $action => $linkedControllers) { // Iterate through the linked controllers actions - foreach ($linkedControllers as $linkedController=>$linkedActions) { + foreach ($linkedControllers as $linkedController => $linkedActions) { if (array_key_exists($linkedController, $arrayOfExclusions)) { $arrayOfExclusions[$linkedController] = array_merge($arrayOfExclusions[$linkedController], $linkedActions); $arrayOfExclusions[$linkedController] = array_unique($arrayOfExclusions[$linkedController]); @@ -155,11 +155,13 @@ private function getExclusionsActionsControllers(): array $arrayOfExclusions = array_merge_recursive(UsersUIACL::getAlwaysAllowed(), UsersUIACL::getAlwaysDenied(), $arrayOfExclusions); // Iterate through the always allowed and disallowed controllers and actions foreach ($arrayOfExclusions as $controllerClass => $actions) { - if ($actions === '*' - || (is_array($actions) && in_array('*', $actions))) { + if ( + $actions === '*' + || (is_array($actions) && in_array('*', $actions)) + ) { // Add the controller with all actions to the excluded from settings array $excludedControllers[] = $controllerClass; - } elseif (is_array($actions)){ + } elseif (is_array($actions)) { // Add the controller with defined actions to the excluded from settings array $excludedActions[$controllerClass] = $actions; } @@ -197,7 +199,7 @@ private function getControllersActions(string $controllerClass, array $excludedA // Remove "Action" from the action name $actionName = substr($actionName, 0, -6); // Remove always allowed or always disallowed actions - if (!in_array($actionName, $excludedActions[$controllerClass])) { + if (!in_array($actionName, $excludedActions[$controllerClass] ?? [])) { $publicMethods[$actionName] = false; } } @@ -224,7 +226,6 @@ private function getAvailableRESTControllersActions(): array [$excludedControllers, $excludedActions] = $this->getExclusionsActionsControllers(); foreach ($controllerFiles as $file) { - $className = pathinfo($file)['filename']; $subClassName = basename(pathinfo($file)['dirname']); $controllerClass = 'MikoPBX\PBXCoreREST\Controllers\\' . $subClassName . '\\' . $className; @@ -328,8 +329,8 @@ private function getAvailableRESTActionsInModules(): array // Create a reflection of the controller class $reflection = new Reflection($parsedClass); - - $controllerName = '/pbxcore/api/modules/' . Text::uncamelize($configObject->moduleUniqueId, '-'); + $textClass = MikoPBXVersion::getTextClass(); + $controllerName = '/pbxcore/api/modules/' . $textClass::uncamelize($configObject->moduleUniqueId, '-'); // Get the actions of the controller if they are defined in the method description $actions = []; @@ -402,7 +403,6 @@ private function getAvailableRESTActionsInModules(): array $currentContext = array_merge($currentContext ?? [], $actions); } } - } return $controllers; } @@ -424,7 +424,8 @@ public function fillAllowed(array $combined, array $allowedRights): array foreach ($actions as $actionName => $value) { foreach ($allowedRights as $allowedRight) { $allowedActions = json_decode($allowedRight['actions'], true); - if ($allowedRight['module_id'] === $moduleId + if ( + $allowedRight['module_id'] === $moduleId && $allowedRight['controller'] === $controllerClass && in_array($actionName, $allowedActions) ) { @@ -472,9 +473,7 @@ public function saveAccessGroupRights(string $accessGroupId, array $accessGroupR // If there are validation errors, display them and return false return false; } - } - } return true; } diff --git a/App/Controllers/LdapConfigController.php b/App/Controllers/LdapConfigController.php index d9c0150..25953c5 100644 --- a/App/Controllers/LdapConfigController.php +++ b/App/Controllers/LdapConfigController.php @@ -1,4 +1,5 @@ $name = $data['administrativePasswordHidden']; } break; @@ -78,7 +80,7 @@ public function saveAction(): void * @return void * @throws Exception */ - public function searchLdapUserAction(string $pattern=''): void + public function searchLdapUserAction(string $pattern = ''): void { /** @var Redis $redis */ $redis = $this->di->getShared(ManagedCacheProvider::SERVICE_NAME); @@ -96,12 +98,14 @@ public function searchLdapUserAction(string $pattern=''): void } $pattern = urldecode($pattern); $usersForDropDown = []; - foreach ($availableUsers as $user){ - if ( stripos($user['name'], $pattern)!==false - || stripos($user['login'], $pattern)!==false){ - $usersForDropDown[]=[ - 'title'=>$user['login'], - 'description'=>$user['name'], + foreach ($availableUsers as $user) { + if ( + mb_stripos($user['name'], $pattern) !== false + || mb_stripos($user['login'], $pattern) !== false + ) { + $usersForDropDown[] = [ + 'title' => $user['login'], + 'description' => $user['name'], ]; } } @@ -169,15 +173,17 @@ private function prepareLdapCredentialsArrayFromPost(array $postData): array { // Admin password can be stored in DB on the time, on this way it has only xxxxxx value. // It can be empty as well, if some password manager tried to fill it. - if (empty($postData['administrativePasswordHidden']) - || $postData['administrativePasswordHidden'] === Constants::HIDDEN_PASSWORD) { + if ( + empty($postData['administrativePasswordHidden']) + || $postData['administrativePasswordHidden'] === Constants::HIDDEN_PASSWORD + ) { $ldapConfig = LdapConfig::findFirst(); - $postData['administrativePassword'] = $ldapConfig->administrativePassword??''; + $postData['administrativePassword'] = $ldapConfig->administrativePassword ?? ''; } else { $postData['administrativePassword'] = $postData['administrativePasswordHidden']; } - return [ + return [ 'serverName' => $postData['serverName'], 'serverPort' => $postData['serverPort'], 'baseDN' => $postData['baseDN'], @@ -190,4 +196,4 @@ private function prepareLdapCredentialsArrayFromPost(array $postData): array 'ldapType' => $postData['ldapType'], ]; } -} \ No newline at end of file +} diff --git a/App/Controllers/ModuleUsersUIController.php b/App/Controllers/ModuleUsersUIController.php index 918513a..0896cd8 100644 --- a/App/Controllers/ModuleUsersUIController.php +++ b/App/Controllers/ModuleUsersUIController.php @@ -1,4 +1,5 @@ . */ + namespace Modules\ModuleUsersUI\App\Controllers; + use MikoPBX\AdminCabinet\Providers\AssetProvider; use Modules\ModuleUsersUI\App\Forms\LdapConfigForm; use Modules\ModuleUsersUI\Models\AccessGroups; @@ -43,15 +46,15 @@ public function indexAction(): void $footerCollection = $this->assets->collection(AssetProvider::FOOTER_JS); $footerCollection ->addJs('js/vendor/datatable/dataTables.semanticui.js', true) - ->addJs('js/cache/'.$this->moduleUniqueID.'/module-users-ui-index.js', true) - ->addJs('js/cache/'.$this->moduleUniqueID.'/module-users-ui-index-users.js', true) + ->addJs('js/cache/' . $this->moduleUniqueID . '/module-users-ui-index.js', true) + ->addJs('js/cache/' . $this->moduleUniqueID . '/module-users-ui-index-users.js', true) ->addJs('js/pbx/main/form.js', true) - ->addJs('js/cache/'.$this->moduleUniqueID.'/module-users-ui-index-ldap.js', true); + ->addJs('js/cache/' . $this->moduleUniqueID . '/module-users-ui-index-ldap.js', true); $headerCollectionCSS = $this->assets->collection(AssetProvider::HEADER_CSS); $headerCollectionCSS ->addCss('css/vendor/datatable/dataTables.semanticui.min.css', true) - ->addCss('css/cache/'.$this->moduleUniqueID.'/module-users-ui.css', true); + ->addCss('css/cache/' . $this->moduleUniqueID . '/module-users-ui.css', true); $parameters = [ 'models' => [ @@ -62,7 +65,7 @@ public function indexAction(): void 'name' => 'AccessGroups.name', 'fullAccess' => 'AccessGroups.fullAccess=1', 'description' => 'AccessGroups.description', - 'countUsers'=> 'COUNT(UsersCredentials.id)', + 'countUsers' => 'COUNT(UsersCredentials.id)', ], 'joins' => [ 'UsersCredentials' => [ @@ -82,5 +85,4 @@ public function indexAction(): void $this->view->ldapForm = new LdapConfigForm($ldapConfig); $this->view->submitMode = null; } - -} \ No newline at end of file +} diff --git a/App/Controllers/UsersCredentialsController.php b/App/Controllers/UsersCredentialsController.php index e723cbe..da763dd 100644 --- a/App/Controllers/UsersCredentialsController.php +++ b/App/Controllers/UsersCredentialsController.php @@ -1,4 +1,5 @@ execute(); $ldapEnabled = LdapConfig::findFirst()->useLdapAuthMethod ?? '0' === '1'; - $security = new Security(); + $securityClass = MikoPBXVersion::getSecurityClass(); + $security = new $securityClass(); foreach ($newMembers as $member) { // Find or create a new user credential $groupMember = $this->findCreateNewUserCredential($member->id); - if (empty($groupMember->user_password)){ + if (empty($groupMember->user_password)) { $groupMember->user_password = $security->hash($member->password); if ($ldapEnabled) { $groupMember->use_ldap_auth = '1'; @@ -128,7 +128,7 @@ public function saveUsersCredentials(string $accessGroupId, array $members): boo * * @return void */ - public function saveUserCredential(array $postData) + public function saveUserCredential(array $postData, object &$response): void { // Get the current user ID from the request $currentUserId = $postData['user_id']; @@ -139,10 +139,10 @@ public function saveUserCredential(array $postData) } // Get the access group, user login, and user password from the request - $accessGroup = $postData['module_users_ui_access_group']??''; - $userLogin = $postData['module_users_ui_login']??''; - $userUseLdapAuth = $postData['module_users_ui_use_ldap_auth']??''; - $userPassword = $postData['module_users_ui_password']??''; + $accessGroup = $postData['module_users_ui_access_group'] ?? ''; + $userLogin = $postData['module_users_ui_login'] ?? ''; + $userUseLdapAuth = $postData['module_users_ui_use_ldap_auth'] ?? ''; + $userPassword = $postData['module_users_ui_password'] ?? ''; // Find the user credentials based on the parameters $groupMember = $this->findCreateNewUserCredential($currentUserId); @@ -154,12 +154,14 @@ public function saveUserCredential(array $postData) // Update the user password hash if it is not empty if (!empty($userPassword) and ($userPassword !== Constants::HIDDEN_PASSWORD)) { - $security = new Security(); + + $securityClass = MikoPBXVersion::getSecurityClass(); + $security = new $securityClass(); $groupMember->user_password = $security->hash($userPassword); } - // Update the user use LDAP authentication if it is not empty - if ($userUseLdapAuth === 'on') { + // Update the user uses LDAP authentication if it is not empty + if ($userUseLdapAuth === 'on' || $userUseLdapAuth === '1') { $groupMember->use_ldap_auth = '1'; } else { $groupMember->use_ldap_auth = '0'; @@ -174,7 +176,10 @@ public function saveUserCredential(array $postData) } // Save the updated user credentials - $groupMember->save(); + if (!$groupMember->save()) { + $response->messages['error'][] = implode('
', $groupMember->getMessages()); + $response->result = false; + } } /** @@ -271,7 +276,8 @@ public function changeUserCredentialsAction(): void // Update the user password hash if it is not empty if (!empty($userPassword) and ($userPassword !== Constants::HIDDEN_PASSWORD)) { - $security = new Security(); + $securityClass = MikoPBXVersion::getSecurityClass(); + $security = new $securityClass(); $groupMember->user_password = $security->hash($userPassword); } diff --git a/App/Forms/AccessGroupForm.php b/App/Forms/AccessGroupForm.php index cb40246..7df4b5f 100644 --- a/App/Forms/AccessGroupForm.php +++ b/App/Forms/AccessGroupForm.php @@ -1,7 +1,8 @@ id===null){ + if ($entity->id === null) { $disabledClass = "disabled"; } @@ -59,11 +55,7 @@ public function initialize($entity = null, $options = null): void $this->add(new Text('name')); // FullAccess checkbox - $checkArr = []; - if ($entity->fullAccess === '1') { - $checkArr['checked'] = 'checked'; - } - $this->add(new Check('fullAccess', $checkArr)); + $this->addCheckBox('fullAccess', intval($entity->fullAccess) === 1); // Add textarea for Description $this->addTextArea('description', $entity->description ?? '', 80); @@ -74,7 +66,9 @@ public function initialize($entity = null, $options = null): void // Select User to assign the user group field $extension = new Select( - 'select-extension-field', [], [ + 'select-extension-field', + [], + [ 'using' => [ 'id', 'name', @@ -89,14 +83,13 @@ public function initialize($entity = null, $options = null): void foreach ($options['groupRights'] as $module => $types) { foreach ($types as $type => $controllers) { foreach ($controllers as $controllerClass => $actions) { - $controllerParts = explode('\\', $controllerClass); $controllerName = end($controllerParts); $controllerName = str_replace("Controller", "", $controllerName); // Main CheckBox $checkBox = new Check("{$controllerClass}_main"); - $checkBox->setLabel("" . $this->getControllerTranslation($controllerName) . ''); + $checkBox->setLabel($this->getControllerTranslation($controllerName)); $this->add($checkBox); foreach ($actions as $action => $allowed) { @@ -108,10 +101,11 @@ public function initialize($entity = null, $options = null): void 'data-controller' => $controllerClass, 'data-controller-name' => $controllerName, 'data-action' => $action, - 'tabindex' => '0' + 'tabindex' => '0', ]; if ($allowed) { - $parameters['checked'] = 'checked'; + $parameters['value'] = 'on'; + $parameters['checked'] = 'on'; } $checkBox = new Check($checkBoxId, $parameters); $checkBox->setLabel($this->getActionTranslation($module, $controllerName, $action)); @@ -124,17 +118,44 @@ public function initialize($entity = null, $options = null): void // CDR filter mode select $parameters = [ Constants::CDR_FILTER_DISABLED => - ['name'=>'cdrFilterMode', 'value'=>Constants::CDR_FILTER_DISABLED], + [ + 'name' => 'cdrFilterMode', + 'value' => Constants::CDR_FILTER_DISABLED, + 'checked' => $entity->cdrFilterMode ?? Constants::CDR_FILTER_DISABLED + ], Constants::CDR_FILTER_ONLY_SELECTED => - ['name'=>'cdrFilterMode', 'value'=>Constants::CDR_FILTER_ONLY_SELECTED], + [ + 'name' => 'cdrFilterMode', + 'value' => Constants::CDR_FILTER_ONLY_SELECTED, + 'checked' => $entity->cdrFilterMode ?? Constants::CDR_FILTER_DISABLED + ], + Constants::CDR_FILTER_OUTGOING_SELECTED => + [ + 'name' => 'cdrFilterMode', + 'value' => Constants::CDR_FILTER_OUTGOING_SELECTED, + 'checked' => $entity->cdrFilterMode ?? Constants::CDR_FILTER_DISABLED + ], Constants::CDR_FILTER_EXCEPT_SELECTED => - ['name'=>'cdrFilterMode', 'value'=>Constants::CDR_FILTER_EXCEPT_SELECTED], + [ + 'name' => 'cdrFilterMode', + 'value' => Constants::CDR_FILTER_EXCEPT_SELECTED , + 'checked' => $entity->cdrFilterMode ?? Constants::CDR_FILTER_DISABLED + ], ]; - $parameters[$entity->cdrFilterMode??Constants::CDR_FILTER_DISABLED]['checked'] = 'checked'; + + if(!MikoPBXVersion::isPhalcon5Version()){ + foreach ($parameters as $index => $parameter) { + if($index == $entity->cdrFilterMode) { + $parameters[$index]['checked'] = '1'; + }else{ + unset($parameters[$index]['checked']); + } + } + } $this->add(new Radio('cdr_filter_mode_off', $parameters[Constants::CDR_FILTER_DISABLED])); $this->add(new Radio('cdr_filter_mode_by_list', $parameters[Constants::CDR_FILTER_ONLY_SELECTED])); + $this->add(new Radio('cdr_filter_mode_outgoing_by_list', $parameters[Constants::CDR_FILTER_OUTGOING_SELECTED])); $this->add(new Radio('cdr_filter_mode_except_list', $parameters[Constants::CDR_FILTER_EXCEPT_SELECTED])); - } /** * Retrieves the translated controller name. @@ -192,4 +213,4 @@ private function getActionTranslation(string $module, string $controllerName, st return $actionTranslation; } -} \ No newline at end of file +} diff --git a/App/Forms/ExtensionEditAdditionalForm.php b/App/Forms/ExtensionEditAdditionalForm.php index cfa23b4..3499c64 100644 --- a/App/Forms/ExtensionEditAdditionalForm.php +++ b/App/Forms/ExtensionEditAdditionalForm.php @@ -1,4 +1,5 @@ 'user_id = :user_id:', 'bind' => [ 'user_id' => $entity->user_id, ] - ]; + ]; - // Find the user credentials based on the parameters - $credentials = UsersCredentials::findFirst($parameters); + // Find the user credentials based on the parameters + $credentials = UsersCredentials::findFirst($parameters); - // Get the access group ID from the credentials, or set it to null if not found - $accessGroupId = $credentials->enabled==='1'?$credentials->user_access_group_id ?? null:Constants::NO_ACCESS_GROUP_ID; + // Get the access group ID from the credentials, or set it to null if not found + $accessGroupId = $credentials->enabled === '1' ? $credentials->user_access_group_id ?? null : Constants::NO_ACCESS_GROUP_ID; - // Get the user login from the credentials, or set it to an empty string if not found - $userLogin = $credentials->user_login ?? ''; + // Get the user login from the credentials, or set it to an empty string if not found + $userLogin = $credentials->user_login ?? ''; - // Get the user password from the credentials, or set it to an empty string if not found or XXX if its hash was saved - $userPassword = empty($credentials->user_password)?'':Constants::HIDDEN_PASSWORD; + // Get the user password from the credentials, or set it to + // an empty string if not found or XXX if its hash was saved + $userPassword = empty($credentials->user_password) ? '' : Constants::HIDDEN_PASSWORD; - // Get the ldap auth value from the credentials, or set it to false if not found - $useLdapAuth = $credentials->use_ldap_auth ?? false; + // Get the ldap auth value from the credentials, or set it to false if not found + $useLdapAuth = $credentials->use_ldap_auth ?? false; - // Create a new Text form element for user login and set its value - $login = new Text('module_users_ui_login', [ + // Create a new Text form element for user login and set its value + $login = new Text('module_users_ui_login', [ 'value' => $userLogin, 'placeholder' => $form->translation->_('module_usersui_UserLoginPlaceholder'), - 'class'=>'prompt' - ]); - $form->add($login); + 'class' => 'prompt' + ]); + $form->add($login); - // Create a new Password form element for user password and set its value - $password = new Password('module_users_ui_password', [ + // Create a new Password form element for user password and set its value + $password = new Password('module_users_ui_password', [ 'value' => $userPassword, 'placeholder' => $form->translation->_('module_usersui_UserPasswordPlaceholder'), - ]); - $form->add($password); - - // Crete a new Checkbox element on the user form - $cheskArr = []; - if ($useLdapAuth === '1') { - $cheskArr['checked'] = 'checked'; - } - $form->add(new Check('module_users_ui_use_ldap_auth', $cheskArr)); - - // Retrieve all access groups from the database - $accessGroups = AccessGroups::find(); - $accessGroupsForSelect = []; - $accessGroupsForSelect[Constants::NO_ACCESS_GROUP_ID] = $form->translation->_('module_usersui_NoAccessGroupName'); - - // Prepare the access groups data for a Select form element - foreach ($accessGroups as $accessGroup) { - $accessGroupsForSelect[$accessGroup->id] = $accessGroup->name; - } - - // Create a new Select form element for user access group and set its properties - $accessGroup = new Select( - 'module_users_ui_access_group', $accessGroupsForSelect, [ + ]); + $form->add($password); + + // Crete a new Checkbox element on the user form + $form->addCheckBox('module_users_ui_use_ldap_auth', intval($useLdapAuth) === 1); + + // Retrieve all access groups from the database + $accessGroups = AccessGroups::find(); + $accessGroupsForSelect = []; + $accessGroupsForSelect[Constants::NO_ACCESS_GROUP_ID] = $form->translation->_('module_usersui_NoAccessGroupName'); + + // Prepare the access groups data for a Select form element + foreach ($accessGroups as $accessGroup) { + $accessGroupsForSelect[$accessGroup->id] = $accessGroup->name; + } + + // Create a new Select form element for user access group and set its properties + $accessGroup = new Select( + 'module_users_ui_access_group', + $accessGroupsForSelect, + [ 'using' => [ 'id', 'name', @@ -102,13 +99,12 @@ public static function prepareAdditionalFields(ExtensionEditForm $form, \stdClas 'value' => $accessGroupId, 'emptyValue' => Constants::NO_ACCESS_GROUP_ID, 'class' => 'ui selection dropdown', - ] - ); - $form->add($accessGroup); - - // Save if LDAP is enabled info to show or hide the LDAP checkbox - $ldapEnabled = LdapConfig::findFirst()->useLdapAuthMethod??'0'==='1'; - $form->add(new Hidden('module_users_ui_ldap_enabled', ['value' => $ldapEnabled])); - } - -} \ No newline at end of file + ] + ); + $form->add($accessGroup); + + // Save if LDAP is enabled info to show or hide the LDAP checkbox + $ldapEnabled = LdapConfig::findFirst()->useLdapAuthMethod ?? '0' === '1'; + $form->add(new Hidden('module_users_ui_ldap_enabled', ['value' => $ldapEnabled])); + } +} diff --git a/App/Forms/LdapConfigForm.php b/App/Forms/LdapConfigForm.php index 418bbdd..6b9e2ca 100644 --- a/App/Forms/LdapConfigForm.php +++ b/App/Forms/LdapConfigForm.php @@ -1,4 +1,5 @@ useLdapAuthMethod === '1') { - $checkArr['checked'] = 'checked'; - } - $this->add(new Check('useLdapAuthMethod', $checkArr)); + $this->addCheckBox('useLdapAuthMethod', intval($entity->useLdapAuthMethod) === 1); // ServerHost - $this->add(new Text('serverName', ['placeholder' =>'dc1.domain.com'])); + $this->add(new Text('serverName', ['placeholder' => 'dc1.domain.com'])); // ServerPort $this->add(new Text('serverPort', [ 'placeholder' => '389', - 'value' =>$entity->serverPort ?? '389' + 'value' => $entity->serverPort ?? '389' ])); // Use TLS dropdown - $this->add(new hidden('useTLS')); + $this->add(new Hidden('useTLS', ['value' => $entity->useTLS ?? '0'])); // AdministrativeLogin - $this->add(new Text('administrativeLogin', ['placeholder' =>'Domain admin login'])); + $this->add(new Text('administrativeLogin', ['placeholder' => 'Domain admin login'])); // AdministrativePassword - $this->add(new Password('administrativePasswordHidden', + $this->add(new Password( + 'administrativePasswordHidden', [ - 'autocomplete'=>'off', - 'placeholder' =>'Domain admin password', - 'value'=>Constants::HIDDEN_PASSWORD - ])); + 'autocomplete' => 'off', + 'placeholder' => 'Domain admin password', + 'value' => Constants::HIDDEN_PASSWORD + ] + )); // BaseDN $this->add(new Text('baseDN', [ @@ -75,10 +71,16 @@ public function initialize($entity = null, $options = null): void ]); // UserIdAttribute - $this->add(new Text('userIdAttribute', ['placeholder' =>'samaccountname'])); + $this->add(new Text('userIdAttribute', [ + 'placeholder' => 'samaccountname', + 'value' => $entity->userIdAttribute ?? 'samaccountname' + ])); // OrganizationUnit - $this->add(new Text('organizationalUnit', ['placeholder' =>'ou=users, dc=domain, dc=com'])); + $this->add(new Text('organizationalUnit', [ + 'placeholder' => 'ou=users, dc=domain, dc=com', + 'value' => $entity->organizationalUnit ?? 'ou=users, dc=domain, dc=com' + ])); // Select server type $types = [ @@ -88,7 +90,9 @@ public function initialize($entity = null, $options = null): void // 'FreeIPA' => 'FreeIPA', ]; $ldapType = new Select( - 'ldapType', $types, [ + 'ldapType', + $types, + [ 'using' => [ 'id', 'name', @@ -99,6 +103,5 @@ public function initialize($entity = null, $options = null): void ] ); $this->add($ldapType); - } -} \ No newline at end of file +} diff --git a/App/Forms/ModuleBaseForm.php b/App/Forms/ModuleBaseForm.php new file mode 100644 index 0000000..687d68c --- /dev/null +++ b/App/Forms/ModuleBaseForm.php @@ -0,0 +1,45 @@ +. + */ + +namespace Modules\ModuleUsersUI\App\Forms; + +use MikoPBX\AdminCabinet\Forms\BaseForm; +use Phalcon\Forms\Element\Check; + +class ModuleBaseForm extends BaseForm +{ + /** + * Adds a checkbox to the form field with the given name. + * Can be deleted if the module depends on MikoPBX later than 2024.3.0 + * + * @param string $fieldName The name of the form field. + * @param bool $checked Indicates whether the checkbox is checked by default. + * @param string $checkedValue The value assigned to the checkbox when it is checked. + * @return void + */ + public function addCheckBox(string $fieldName, bool $checked, string $checkedValue = 'on'): void + { + $checkAr = ['value' => null]; + if ($checked) { + $checkAr = ['checked' => $checkedValue, 'value' => $checkedValue]; + } + $this->add(new Check($fieldName, $checkAr)); + } +} diff --git a/App/Module.php b/App/Module.php index 1bddc0d..ea86df5 100644 --- a/App/Module.php +++ b/App/Module.php @@ -1,7 +1,7 @@ . */ -/* - * MikoPBX - free phone system for small business - * Copyright (C) 2017-2023 Alexey Portnov and Nikolay Beketov - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with this program. - * If not, see . - */ - - namespace Modules\ModuleUsersUI\App; use Modules\ModuleUsersUI\App\Providers\ViewProvider; diff --git a/App/Providers/ViewProvider.php b/App/Providers/ViewProvider.php index 43287b4..ac4f33b 100644 --- a/App/Providers/ViewProvider.php +++ b/App/Providers/ViewProvider.php @@ -1,7 +1,7 @@ . */ -/* - * MikoPBX - free phone system for small business - * Copyright (C) 2017-2023 Alexey Portnov and Nikolay Beketov - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with this program. - * If not, see . - */ declare(strict_types=1); diff --git a/App/Providers/VoltProvider.php b/App/Providers/VoltProvider.php index a359374..b4ecb41 100644 --- a/App/Providers/VoltProvider.php +++ b/App/Providers/VoltProvider.php @@ -1,25 +1,7 @@ . - */ - -/* - * MikoPBX - free phone system for small business - * Copyright (C) 2017-2023 Alexey Portnov and Nikolay Beketov + * Copyright © 2017-2024 Alexey Portnov and Nikolay Beketov * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/App/Views/AccessGroups/ModifyTabs/tabCDRFilter.volt b/App/Views/AccessGroups/ModifyTabs/tabCDRFilter.volt index 4ea9c2c..7642167 100644 --- a/App/Views/AccessGroups/ModifyTabs/tabCDRFilter.volt +++ b/App/Views/AccessGroups/ModifyTabs/tabCDRFilter.volt @@ -12,6 +12,12 @@ +
+
+ {{ form.render('cdr_filter_mode_outgoing_by_list') }} + +
+
{{ form.render('cdr_filter_mode_except_list') }} diff --git a/App/Views/AccessGroups/ModifyTabs/tabGroupRights.volt b/App/Views/AccessGroups/ModifyTabs/tabGroupRights.volt index 4c81850..5e1aeb1 100644 --- a/App/Views/AccessGroups/ModifyTabs/tabGroupRights.volt +++ b/App/Views/AccessGroups/ModifyTabs/tabGroupRights.volt @@ -25,7 +25,7 @@
{{ form.render(controller~'_main') }} - {{ form.label(controller~'_main') }} + {{ form.label(controller~'_main', ['class':'ui tiny header']) }}
{% for element in form %} diff --git a/App/Views/AccessGroups/modify.volt b/App/Views/AccessGroups/modify.volt index 366c242..3131643 100644 --- a/App/Views/AccessGroups/modify.volt +++ b/App/Views/AccessGroups/modify.volt @@ -1,38 +1,38 @@ -{{ form('module-users-u-i/access-groups/save', 'role': 'form', 'class': 'ui large form','id':'module-users-ui-form') }} +
+ + - - -{% if id is null %} -
- {{ partial("Modules/ModuleUsersUI/AccessGroups/ModifyTabs/tabGeneralSettingsSimple") }} -
-{% else %} -
- {{ partial("Modules/ModuleUsersUI/AccessGroups/ModifyTabs/tabGeneralSettingsFull") }} -
-
- {{ partial("Modules/ModuleUsersUI/AccessGroups/ModifyTabs/tabGroupRights") }} -
+
+ {{ partial("Modules/ModuleUsersUI/AccessGroups/ModifyTabs/tabGeneralSettingsFull") }} +
+
+ {{ partial("Modules/ModuleUsersUI/AccessGroups/ModifyTabs/tabGroupRights") }} +
-
- {{ partial("Modules/ModuleUsersUI/AccessGroups/ModifyTabs/tabUsers") }} -
+
+ {{ partial("Modules/ModuleUsersUI/AccessGroups/ModifyTabs/tabUsers") }} +
-
- {{ partial("Modules/ModuleUsersUI/AccessGroups/ModifyTabs/tabCDRFilter") }} -
-{% endif %} +
+ {{ partial("Modules/ModuleUsersUI/AccessGroups/ModifyTabs/tabCDRFilter") }} +
+ {% endif %} -{{ partial("partials/submitbutton",['indexurl':'module-users-u-i/module-users-u-i/index']) }} + {{ partial("partials/submitbutton",['indexurl':'module-users-u-i/module-users-u-i/index']) }} -{{ endform() }} \ No newline at end of file +
\ No newline at end of file diff --git a/App/Views/ModuleUsersUI/IndexTabs/tabLdap.volt b/App/Views/ModuleUsersUI/IndexTabs/tabLdap.volt index aa4c717..8cc8bed 100644 --- a/App/Views/ModuleUsersUI/IndexTabs/tabLdap.volt +++ b/App/Views/ModuleUsersUI/IndexTabs/tabLdap.volt @@ -1,4 +1,4 @@ -{{ form('module-users-u-i/ldap-config/save', 'role': 'form', 'class': 'ui large form','id':'module-users-ui-ldap-form') }} +
@@ -94,4 +94,4 @@
{{ partial("partials/submitbutton",['indexurl':'']) }} -{{ endform() }} \ No newline at end of file + \ No newline at end of file diff --git a/App/Views/ModuleUsersUI/IndexTabs/tabUsers.volt b/App/Views/ModuleUsersUI/IndexTabs/tabUsers.volt index c6fc1fc..7860a14 100644 --- a/App/Views/ModuleUsersUI/IndexTabs/tabUsers.volt +++ b/App/Views/ModuleUsersUI/IndexTabs/tabUsers.volt @@ -8,7 +8,7 @@ {{ t._('module_usersui_ColumnUseLdap') }} {{ t._('module_usersui_ColumnUserLogin') }} {{ t._('module_usersui_ColumnUserPassword') }} - {{ t._('module_usersui_ColumnGroupName') }} + {{ t._('module_usersui_ColumnGroupName') }} @@ -43,7 +43,7 @@
- +