diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..fa06938 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,97 @@ +# CLAUDE.md + +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. + +## Project Overview + +This is ModuleUsersUI, a MikoPBX module that provides user rights management and access control functionality. It allows multi-user access to MikoPBX with role-based permissions and includes LDAP/AD authentication support. + +## Development Commands + +### Code Quality +- Use `phpstan` to check code quality after creating or modifying PHP files +- PHP version requirement: ^7.4 (platform version: 7.4.0) + +### JavaScript Build Process +- Source JS files are in `public/assets/js/src/` +- Compiled JS files are in `public/assets/js/` +- Use Babel for JS compilation: `/Users/nb/PhpstormProjects/mikopbx/MikoPBXUtils/node_modules/.bin/babel "$INPUT_FILE" --out-dir "$OUTPUT_DIR" --source-maps inline --presets airbnb` + +### Dependencies +- Run `composer install` to install PHP dependencies +- Main dependency: `directorytree/ldaprecord` for LDAP functionality + +## Architecture Overview + +### Core Components +1. **Module Structure** - Standard MikoPBX module following Phalcon framework patterns +2. **Access Control System** - Multi-layered ACL implementation with role-based permissions +3. **Authentication** - Dual authentication: local credentials and LDAP/AD integration +4. **User Interface** - Tabbed interface using Semantic UI with Volt templating + +### Key Directories +- `App/` - Main application logic (Controllers, Forms, Views, Providers) +- `Lib/` - Core libraries and ACL system +- `Models/` - Phalcon ORM models for database entities +- `Setup/` - Module installation and configuration +- `Messages/` - Internationalization files +- `public/assets/` - Frontend assets (CSS, JS, images) + +### Database Models +- `AccessGroups` - User access groups with permissions +- `AccessGroupsRights` - Granular rights assignment to groups +- `AccessGroupCDRFilter` - CDR filtering rules per group +- `UsersCredentials` - User authentication credentials +- `LdapConfig` - LDAP/AD server configuration + +### Controllers Architecture +- `ModuleUsersUIBaseController` - Base controller with common functionality +- `ModuleUsersUIController` - Main module interface (groups, users, LDAP tabs) +- `AccessGroupsController` - Access group management +- `AccessGroupsRightsController` - Rights assignment +- `AccessGroupCDRFilterController` - CDR filtering configuration +- `UsersCredentialsController` - User credential management +- `LdapConfigController` - LDAP configuration + +### ACL System +The module implements a sophisticated ACL system: +- `UsersUIACL` - Main ACL modifier that integrates with MikoPBX core ACL +- `CoreACL` and various `Module*ACL` classes - Define permissions for different MikoPBX modules +- Role-based access with prefix: `Constants::MODULE_ROLE_PREFIX` +- Dynamic permission assignment based on access group configuration + +### Authentication Flow +1. `UsersUIAuthenticator` - Handles login authentication +2. Supports both local password and LDAP authentication +3. `UsersUILdapAuth` - LDAP authentication implementation +4. Session management integrated with MikoPBX core + +### Frontend Architecture +- Uses Semantic UI framework for styling +- JavaScript modules for each tab functionality: + - `module-users-ui-index.js` - Main module initialization + - `module-users-ui-index-users.js` - Users tab functionality + - `module-users-ui-index-ldap.js` - LDAP configuration tab + - `module-users-ui-modify-ag.js` - Access group modification + - `module-users-ui-extensions-modify.js` - Extension modifications +- Volt templating engine for server-side rendering + +### Configuration +- `module.json` - Module metadata and release settings +- `composer.json` - PHP dependencies and autoloading (PSR-4) +- License: GPL-3.0-or-later + +## Development Patterns +- Follow MikoPBX module development standards +- Use Phalcon ORM for database operations +- Implement proper ACL checks in all controllers +- Maintain separation between frontend source and compiled assets +- Use dependency injection container for service registration +- Follow PSR-4 autoloading standards with namespace `Modules\ModuleUsersUI\` + +## Key Files to Understand +- `App/Module.php` - Main module definition and service registration +- `Setup/PbxExtensionSetup.php` - Module installation and sidebar integration +- `Lib/UsersUIACL.php` - Core ACL modification logic +- `Lib/UsersUIAuthenticator.php` - Authentication handler +- `App/Controllers/ModuleUsersUIController.php` - Main controller \ No newline at end of file diff --git a/Lib/AnswerStructure.php b/Lib/AnswerStructure.php new file mode 100644 index 0000000..712b75e --- /dev/null +++ b/Lib/AnswerStructure.php @@ -0,0 +1,102 @@ +. + */ + +namespace Modules\ModuleUsersUI\Lib; + + +use MikoPBX\PBXCoreREST\Lib\PBXApiResult; + +/** + * Class AnswerStructure + * + * @package Modules\ModuleUsersUI\Lib + * + */ +class AnswerStructure +{ + /** + * Request result + * + * @var bool + */ + public bool $success = false; + + /** + * Array of result fields + * + * @var array + */ + public array $data; + + /** + * Error messages, description of failure + * + * @var array + */ + public array $messages; + + /** + * AnswerStructure constructor. + * + * @param PBXApiResult|null $res The PBXApiResult object to initialize from (optional). + */ + public function __construct(PBXApiResult $res = null) + { + // Initialize default values + $this->success = false; + $this->data = []; + $this->messages = []; + + // If PBXApiResult is provided, copy attributes + if ($res) { + $this->copyAttributesFrom($res); + } + } + + + /** + * Prepare structured result + * + * @return array The structured result as an array + */ + public function getResult(): array + { + return [ + 'result' => $this->success, + 'data' => $this->data, + 'messages' => $this->messages, + ]; + } + + /** + * Copies attributes from a PBXApiResult to this AnswerStructure. + * + * @param PBXApiResult $res The PBXApiResult object to copy attributes from. + */ + private function copyAttributesFrom(PBXApiResult $res): void + { + // Iterate through the attributes of this object and copy values from PBXApiResult + foreach ($this as $attribute => $value) { + if (!empty($res->$attribute)) { + $this->$attribute = $res->$attribute; + } + } + } + +} \ No newline at end of file diff --git a/Lib/UsersUILdapAuth.php b/Lib/UsersUILdapAuth.php index 2de449e..0ba065d 100644 --- a/Lib/UsersUILdapAuth.php +++ b/Lib/UsersUILdapAuth.php @@ -24,6 +24,7 @@ use LdapRecord\Container; use MikoPBX\Common\Handlers\CriticalErrorsHandler; use MikoPBX\Common\Providers\LoggerAuthProvider; +use Modules\ModuleUsersUI\Lib\AnswerStructure; use Phalcon\Di\Injectable; include_once __DIR__ . '/../vendor/autoload.php';