Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -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
102 changes: 102 additions & 0 deletions Lib/AnswerStructure.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php
/*
* MikoPBX - free phone system for small business
* Copyright © 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 <https://www.gnu.org/licenses/>.
*/

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;
}
}
}

}
1 change: 1 addition & 0 deletions Lib/UsersUILdapAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down