5.2 KiB
Specific Permissions Module Documentation
Overview
The Specific Permissions Module is a configuration system that allows administrators to define granular permission settings for different user levels within the DevQMS application. This module provides a flexible way to control access to specific features and functionalities based on user roles.
File Location
- View File:
resources/views/admin/type/settings/specific-permissions.blade.php - Guide Documentation:
resources/views/guide/specific-permissions-module.md
Features
1. Permission Management
- Define custom permission settings for different user levels
- Multi-select dropdown interface for easy configuration
- Real-time updates through form submission
- Integration with the existing settings system
2. User Level Integration
- Automatically retrieves available user levels from the system
- Dynamic option population in permission dropdowns
- Support for multiple user level selections per permission
3. Settings Storage
- Permissions are stored in the
settingstable - JSON format for storing multiple values
- Persistent configuration across sessions
Module Structure
Permission Definitions
The module defines specific permissions in the $permissions array:
$permissions = [
'Weld Log ISO Upload Permission' => 'weld_log_iso_upload_permission',
'Engineer Upload Permission' => 'engineer_upload_permission',
];
Key Components
- Form Handler: Processes permission updates via POST requests
- User Level Retrieval: Gets available user levels from the system
- Settings Integration: Uses the
firstOrUpdatefunction for database operations - Dynamic UI: Select2 integration for enhanced user experience
Technical Implementation
Database Operations
// Update settings when form is submitted
if(getisset("update")) {
foreach($_POST AS $key => $value) {
firstOrUpdate([
'title' => $key,
'html' => $value
],"settings",[
'title' => $key
]);
}
}
User Level Integration
// Retrieve available user levels
$userLevels = array_keys(levels());
Frontend Integration
The module uses Select2 for enhanced dropdown functionality:
$('.select2').select2({
placeholder: "Select User Levels",
allowClear: true,
width: '100%'
});
Usage
1. Accessing the Module
Navigate to the admin panel and access the specific permissions settings through the settings section.
2. Configuring Permissions
- Select the desired user levels for each permission
- Use the multi-select dropdown to choose multiple levels
- Click "Update" to save changes
3. Permission Types
Currently supported permission types:
- Weld Log ISO Upload Permission: Controls access to ISO upload functionality in weld log module
- Engineer Upload Permission: Controls engineer-level upload permissions
Integration with Other Modules
Settings System Integration
The module integrates with the global settings system:
// Retrieve permission settings
$selectedValues = j(setting($key));
User Level System
Leverages the existing user level system:
// Get user levels from the system
$userLevels = array_keys(levels());
Adding New Permissions
To add new permission types:
- Update the permissions array:
$permissions = [
'Weld Log ISO Upload Permission' => 'weld_log_iso_upload_permission',
'Engineer Upload Permission' => 'engineer_upload_permission',
'New Permission Name' => 'new_permission_key',
];
- The system will automatically:
- Create the form field
- Add it to the database
- Include it in the Select2 initialization
Security Considerations
- All form submissions include CSRF protection
- Permission changes require admin-level access
- Settings are stored securely in the database
- User level validation is performed server-side
Dependencies
- Laravel Framework: For form handling and database operations
- Select2: For enhanced dropdown functionality
- jQuery: For frontend interactions
- Bootstrap: For styling and modal functionality
Future Enhancements
Potential improvements for the module:
- Permission Categories: Group related permissions together
- Permission Inheritance: Allow permissions to inherit from parent levels
- Audit Logging: Track permission changes over time
- Bulk Operations: Enable bulk permission updates
- Permission Templates: Predefined permission sets for common scenarios
Troubleshooting
Common Issues
- Permissions not saving: Check CSRF token and form submission
- User levels not appearing: Verify the
levels()function returns correct data - Select2 not working: Ensure jQuery and Select2 are properly loaded
Debug Information
To debug permission settings:
// Check current permission values
$permissionValue = setting('weld_log_iso_upload_permission');
var_dump($permissionValue);