Skip to content

Commit 81752d4

Browse files
authored
Merge pull request #14 from mikopbx/develop
fix: Add missing AnswerStructure import to resolve class not found er…
2 parents 79e2427 + 13eb265 commit 81752d4

File tree

3 files changed

+200
-0
lines changed

3 files changed

+200
-0
lines changed

CLAUDE.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
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.
8+
9+
## Development Commands
10+
11+
### Code Quality
12+
- Use `phpstan` to check code quality after creating or modifying PHP files
13+
- PHP version requirement: ^7.4 (platform version: 7.4.0)
14+
15+
### JavaScript Build Process
16+
- Source JS files are in `public/assets/js/src/`
17+
- Compiled JS files are in `public/assets/js/`
18+
- 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`
19+
20+
### Dependencies
21+
- Run `composer install` to install PHP dependencies
22+
- Main dependency: `directorytree/ldaprecord` for LDAP functionality
23+
24+
## Architecture Overview
25+
26+
### Core Components
27+
1. **Module Structure** - Standard MikoPBX module following Phalcon framework patterns
28+
2. **Access Control System** - Multi-layered ACL implementation with role-based permissions
29+
3. **Authentication** - Dual authentication: local credentials and LDAP/AD integration
30+
4. **User Interface** - Tabbed interface using Semantic UI with Volt templating
31+
32+
### Key Directories
33+
- `App/` - Main application logic (Controllers, Forms, Views, Providers)
34+
- `Lib/` - Core libraries and ACL system
35+
- `Models/` - Phalcon ORM models for database entities
36+
- `Setup/` - Module installation and configuration
37+
- `Messages/` - Internationalization files
38+
- `public/assets/` - Frontend assets (CSS, JS, images)
39+
40+
### Database Models
41+
- `AccessGroups` - User access groups with permissions
42+
- `AccessGroupsRights` - Granular rights assignment to groups
43+
- `AccessGroupCDRFilter` - CDR filtering rules per group
44+
- `UsersCredentials` - User authentication credentials
45+
- `LdapConfig` - LDAP/AD server configuration
46+
47+
### Controllers Architecture
48+
- `ModuleUsersUIBaseController` - Base controller with common functionality
49+
- `ModuleUsersUIController` - Main module interface (groups, users, LDAP tabs)
50+
- `AccessGroupsController` - Access group management
51+
- `AccessGroupsRightsController` - Rights assignment
52+
- `AccessGroupCDRFilterController` - CDR filtering configuration
53+
- `UsersCredentialsController` - User credential management
54+
- `LdapConfigController` - LDAP configuration
55+
56+
### ACL System
57+
The module implements a sophisticated ACL system:
58+
- `UsersUIACL` - Main ACL modifier that integrates with MikoPBX core ACL
59+
- `CoreACL` and various `Module*ACL` classes - Define permissions for different MikoPBX modules
60+
- Role-based access with prefix: `Constants::MODULE_ROLE_PREFIX`
61+
- Dynamic permission assignment based on access group configuration
62+
63+
### Authentication Flow
64+
1. `UsersUIAuthenticator` - Handles login authentication
65+
2. Supports both local password and LDAP authentication
66+
3. `UsersUILdapAuth` - LDAP authentication implementation
67+
4. Session management integrated with MikoPBX core
68+
69+
### Frontend Architecture
70+
- Uses Semantic UI framework for styling
71+
- JavaScript modules for each tab functionality:
72+
- `module-users-ui-index.js` - Main module initialization
73+
- `module-users-ui-index-users.js` - Users tab functionality
74+
- `module-users-ui-index-ldap.js` - LDAP configuration tab
75+
- `module-users-ui-modify-ag.js` - Access group modification
76+
- `module-users-ui-extensions-modify.js` - Extension modifications
77+
- Volt templating engine for server-side rendering
78+
79+
### Configuration
80+
- `module.json` - Module metadata and release settings
81+
- `composer.json` - PHP dependencies and autoloading (PSR-4)
82+
- License: GPL-3.0-or-later
83+
84+
## Development Patterns
85+
- Follow MikoPBX module development standards
86+
- Use Phalcon ORM for database operations
87+
- Implement proper ACL checks in all controllers
88+
- Maintain separation between frontend source and compiled assets
89+
- Use dependency injection container for service registration
90+
- Follow PSR-4 autoloading standards with namespace `Modules\ModuleUsersUI\`
91+
92+
## Key Files to Understand
93+
- `App/Module.php` - Main module definition and service registration
94+
- `Setup/PbxExtensionSetup.php` - Module installation and sidebar integration
95+
- `Lib/UsersUIACL.php` - Core ACL modification logic
96+
- `Lib/UsersUIAuthenticator.php` - Authentication handler
97+
- `App/Controllers/ModuleUsersUIController.php` - Main controller

Lib/AnswerStructure.php

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
/*
3+
* MikoPBX - free phone system for small business
4+
* Copyright © 2017-2023 Alexey Portnov and Nikolay Beketov
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License along with this program.
17+
* If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
namespace Modules\ModuleUsersUI\Lib;
21+
22+
23+
use MikoPBX\PBXCoreREST\Lib\PBXApiResult;
24+
25+
/**
26+
* Class AnswerStructure
27+
*
28+
* @package Modules\ModuleUsersUI\Lib
29+
*
30+
*/
31+
class AnswerStructure
32+
{
33+
/**
34+
* Request result
35+
*
36+
* @var bool
37+
*/
38+
public bool $success = false;
39+
40+
/**
41+
* Array of result fields
42+
*
43+
* @var array
44+
*/
45+
public array $data;
46+
47+
/**
48+
* Error messages, description of failure
49+
*
50+
* @var array
51+
*/
52+
public array $messages;
53+
54+
/**
55+
* AnswerStructure constructor.
56+
*
57+
* @param PBXApiResult|null $res The PBXApiResult object to initialize from (optional).
58+
*/
59+
public function __construct(PBXApiResult $res = null)
60+
{
61+
// Initialize default values
62+
$this->success = false;
63+
$this->data = [];
64+
$this->messages = [];
65+
66+
// If PBXApiResult is provided, copy attributes
67+
if ($res) {
68+
$this->copyAttributesFrom($res);
69+
}
70+
}
71+
72+
73+
/**
74+
* Prepare structured result
75+
*
76+
* @return array The structured result as an array
77+
*/
78+
public function getResult(): array
79+
{
80+
return [
81+
'result' => $this->success,
82+
'data' => $this->data,
83+
'messages' => $this->messages,
84+
];
85+
}
86+
87+
/**
88+
* Copies attributes from a PBXApiResult to this AnswerStructure.
89+
*
90+
* @param PBXApiResult $res The PBXApiResult object to copy attributes from.
91+
*/
92+
private function copyAttributesFrom(PBXApiResult $res): void
93+
{
94+
// Iterate through the attributes of this object and copy values from PBXApiResult
95+
foreach ($this as $attribute => $value) {
96+
if (!empty($res->$attribute)) {
97+
$this->$attribute = $res->$attribute;
98+
}
99+
}
100+
}
101+
102+
}

Lib/UsersUILdapAuth.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use LdapRecord\Container;
2525
use MikoPBX\Common\Handlers\CriticalErrorsHandler;
2626
use MikoPBX\Common\Providers\LoggerAuthProvider;
27+
use Modules\ModuleUsersUI\Lib\AnswerStructure;
2728
use Phalcon\Di\Injectable;
2829

2930
include_once __DIR__ . '/../vendor/autoload.php';

0 commit comments

Comments
 (0)