feat: Implement module permissions system with database-driven access control

- Added `users_permissions` table for managing user permissions.
- Created `PermissionRepository` for handling permission logic.
- Refactored `controls\Users::permissions()` to utilize the new database structure.
- Introduced AJAX endpoint for saving user permissions.
- Enhanced user management UI with permission checkboxes.
- Added vacation management template for handling employee absences.
- Implemented tests for `PermissionRepository`.
This commit is contained in:
2026-02-26 20:17:03 +01:00
parent 76d3ac33a8
commit a4a35c8d62
35 changed files with 2654 additions and 901 deletions

View File

@@ -18,6 +18,7 @@
<th style="width: 60px;">ID</th>
<th>Imi&#281; i nazwisko</th>
<th>Email</th>
<th>Uprawnienia</th>
<th style="width: 240px;">Akcje</th>
</tr>
</thead>
@@ -33,6 +34,23 @@
<? endif;?>
</td>
<td class="left"><?= htmlspecialchars( $user_tmp['email'] );?></td>
<td class="left">
<? if ( (int)$user_tmp['id'] === 1 ):?>
<span class="label label-info">Pelny dostep</span>
<? elseif ( isset( $this -> permissions_map[ (int)$user_tmp['id'] ] ) ):?>
<? foreach ( $this -> modules as $mod ):?>
<label style="margin-right: 10px; font-weight: normal; white-space: nowrap;">
<input type="checkbox"
class="permission-checkbox"
data-user-id="<?= (int)$user_tmp['id'];?>"
data-module="<?= $mod;?>"
<?= $this -> permissions_map[ (int)$user_tmp['id'] ][ $mod ] ? 'checked' : '';?>
>
<?= htmlspecialchars( $this -> module_labels[ $mod ] );?>
</label>
<? endforeach;?>
<? endif;?>
</td>
<td class="center">
<? if ( $is_current ):?>
<span class="btn btn-default btn_small disabled">Aktywna sesja</span>
@@ -46,10 +64,40 @@
</tr>
<? endforeach; else:?>
<tr>
<td colspan="4" class="center">Brak u&#380;ytkownik&#243;w.</td>
<td colspan="5" class="center">Brak u&#380;ytkownik&#243;w.</td>
</tr>
<? endif;?>
</tbody>
</table>
</div>
</div>
<script>
$( document ).on( 'change', '.permission-checkbox', function()
{
var $cb = $( this );
$.ajax({
url: '/users/permission_save/',
type: 'POST',
data: {
user_id: $cb.data( 'user-id' ),
perm_module: $cb.data( 'module' ),
value: $cb.is( ':checked' ) ? 1 : 0,
csrf_token: '<?= \S::csrf_token();?>'
},
dataType: 'json',
success: function( r )
{
if ( r.status !== 'success' )
{
alert( r.msg || 'Blad zapisu uprawnien.' );
$cb.prop( 'checked', !$cb.is( ':checked' ) );
}
},
error: function()
{
alert( 'Blad polaczenia z serwerem.' );
$cb.prop( 'checked', !$cb.is( ':checked' ) );
}
});
});
</script>