Skip to content

Commit

Permalink
refactor: Improve ModuleUsersUI code structure and add validation
Browse files Browse the repository at this point in the history
- Replace ModuleBaseForm with specific LdapConfigForm for better type safety
- Add validation for user UI related POST data in UsersUIConf
- Improve code readability with descriptive comments
- Update code style according to PSR-12 standards
  • Loading branch information
jorikfon committed Jan 21, 2025
1 parent e11175a commit ae36f20
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
Binary file modified .DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions App/Controllers/ModuleUsersUIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
namespace Modules\ModuleUsersUI\App\Controllers;

use MikoPBX\AdminCabinet\Providers\AssetProvider;
use Modules\ModuleUsersUI\App\Forms\ModuleBaseForm;
use Modules\ModuleUsersUI\App\Forms\LdapConfigForm;
use Modules\ModuleUsersUI\Models\AccessGroups;
use Modules\ModuleUsersUI\Models\LdapConfig;
use Modules\ModuleUsersUI\Models\UsersCredentials;
Expand Down Expand Up @@ -82,7 +82,7 @@ public function indexAction(): void
$this->view->members = $this->getTheListOfUsersForDisplayInTheFilter();

$ldapConfig = LdapConfig::findFirst();
$this->view->ldapForm = new ModuleBaseForm($ldapConfig);
$this->view->ldapForm = new LdapConfigForm($ldapConfig);
$this->view->submitMode = null;
}
}
16 changes: 15 additions & 1 deletion Lib/UsersUIConf.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,21 @@ public function onAfterExecuteRestAPIRoute(Micro $app): void
if (!empty($response->result) and $response->result === true) {
$userController = new UsersCredentialsController();
$postData = $app->request->getPost();
$userController->saveUserCredential($postData, $response);

// Check if any key in postData contains "module_users_ui_"
$hasUserUIKeys = false;
foreach ($postData as $key => $value) {
if (strpos($key, 'module_users_ui_') !== false) {
$hasUserUIKeys = true;
break;
}
}

// Only save credentials if relevant keys are present
if ($hasUserUIKeys) {
$userController->saveUserCredential($postData, $response);
}

$app->response->setContent(json_encode($response));
}
}
Expand Down

0 comments on commit ae36f20

Please sign in to comment.