La gestion des groupes devient permissions.

Les groupes étant immuables.
This commit is contained in:
Fred Tempez 2023-03-29 14:48:09 +02:00
parent 3d579cb689
commit 8ac66696cb
10 changed files with 223 additions and 246 deletions

View File

@ -343,7 +343,7 @@ class layout extends common
$items .= $this->getData(['theme', 'footer', 'displaymemberAccount']) === false ? ' class="displayNone">' : '>';
$items .= '<wbr>&nbsp;|&nbsp;';
if (
$this->getgroup('folder', 'share') === true
$this->getPermission('folder', 'share') === true
) {
$items .= '<wbr>' . template::ico('folder', [
'href' => helper::baseUrl(false) . 'core/vendor/filemanager/dialog.php?type=0&akey=' . md5_file(self::DATA_DIR . 'core.json') . '&lang=' . $this->getData(['user', $this->getUser('id'), 'language']),
@ -497,7 +497,7 @@ class layout extends common
&& $this->getData(['theme', 'menu', 'memberBar']) === true
) {
if (
$this->getGroup('folder', 'share') === true
$this->getPermission('folder', 'share') === true
) {
$itemsRight .= '<li>' . template::ico('folder', [
'href' => helper::baseUrl(false) . 'core/vendor/filemanager/dialog.php?type=0&akey=' . md5_file(self::DATA_DIR . 'core.json') . '&lang=' . $this->getData(['user', $this->getUser('id'), 'language']),

View File

@ -234,7 +234,7 @@ class common
'theme' => '',
'user' => '',
'language' => '',
'group'=> '',
'permission'=> '',
];
public static $fontsWebSafe = [
@ -534,7 +534,6 @@ class common
*/
public function getData($keys = [])
{
// Eviter une requete vide
if (count($keys) >= 1) {
// descripteur de la base
@ -912,17 +911,17 @@ class common
}
/**
* Accède aux données du groupe de l'utilisateur connecté
* @param int $key Clé de la valeur
* Retourne les permission de l'utilisateur connecté
* @param int $key Clé de la valeur du groupe
* @return string|null
*/
public function getGroup($key1, $key2 = null) {
public function getPermission($key1, $key2 = null) {
if (is_array($this->user) === false) {
return false;
} elseif ($key2 === null && array_key_exists($key1, $this->getData(['group', $this->user['group']]))) {
return $this->getData(['group', $this->user['group'], $key1]);
} elseif ($key2 && array_key_exists($key2, $this->getData(['group', $this->user['group'], $key1]))) {
return $this->getData(['group', $this->user['group'], $key1, $key2]);
} elseif ($key2 === null && array_key_exists($key1, $this->getData(['permission', $this->user['group']]))) {
return $this->getData(['permission', $this->user['group'], $key1]);
} elseif ($key2 && array_key_exists($key2, $this->getData(['permission', $this->user['group'], $key1]))) {
return $this->getData(['permission', $this->user['group'], $key1, $key2]);
} else {
return false;
}

View File

@ -334,22 +334,24 @@ class init extends common
],
'blacklist' => [],
'language'=> [],
'group' => [
'-1' => [
'permission' => [
"banned" => [
'name' => 'Banni',
'readonly' => true,
'comment' => 'Accès désactivé'
'comment' => 'Accès désactivé',
'group' => -1,
],
'0' => [
"visitor" => [
'name' => 'Visiteur',
'readonly' => true,
'comment' => 'Accède au site'
'comment' => 'Accède au site',
'group' => 0,
],
'1' => [
'member' => [
'name' => 'Membre',
'readonly' => false,
'comment' => 'Accède aux pages réservées et à un dossier partagé',
'path' => '/site/file/source/partage/',
'group' => 0,
'file' => [
'download' => false,
'edit' => false,
@ -373,11 +375,11 @@ class init extends common
'path' => '.\/site\/file\/source\/partage\/',
]
],
'2' => [
'name' => 'Editeur',
"moderator" => [
'name' => 'Moderateur',
'readonly' => false,
'comment' => 'Edition des pages',
'path' => '/site/file/source/',
'group' => 2,
'file' => [
'download' => true,
'edit' => true,
@ -401,33 +403,11 @@ class init extends common
'path' => '.\/site\/file\/source\/partage\/',
]
],
'3' => [
"admin" => [
'name' => 'Administrateur',
'readonly' => true,
'comment' => 'Contrôle total',
'path' => '/site/file/source/',
'file' => [
'download' => true,
'edit' => true,
'create' => true,
'rename' => true,
'upload' => true,
'delete' => true,
'preview' => true,
'duplicate' => true,
'extract' => true,
'copycut' => true,
'permission' => true,
'share' => false,
'path' => '.\/site\/file\/source\/',
],
'folder' => [
'create' => true,
'delete' => true,
'rename' => true,
'copycut' => true,
'permission' => false
]
'group' => 3,
]
],
];

View File

@ -27,9 +27,9 @@ class user extends common
'forgot' => self::GROUP_VISITOR,
'login' => self::GROUP_VISITOR,
'reset' => self::GROUP_VISITOR,
'group' => self::GROUP_ADMIN,
'groupAdd' => self::GROUP_ADMIN,
'groupEdit' => self::GROUP_ADMIN,
'permission' => self::GROUP_ADMIN,
'permissionEdit' => self::GROUP_ADMIN,
'permissionAdd' => self::GROUP_ADMIN,
];
public static $users = [];
@ -386,7 +386,7 @@ class user extends common
self::$users[] = [
$userId,
$userFirstname . ' ' . $this->getData(['user', $userId, 'lastname']),
helper::translate(self::$groups[$this->getData(['user', $userId, 'group'])]),
helper::translate(self::$groups[(int)$this->getData(['user', $userId, 'group'])]),
template::button('userEdit' . $userId, [
'href' => helper::baseUrl() . 'user/edit/' . $userId . '/' . $_SESSION['csrf'],
'value' => template::ico('pencil'),
@ -411,24 +411,22 @@ class user extends common
/**
* Table des groupes
*/
public function group()
public function permission()
{
$g = $this->getData(['group']);
$g = $this->getData(['permission']);
foreach ($g as $groupId => $groupData) {
self::$userGroups[$groupId] = [
$groupId,
$groupData['name'],
$groupData['comment'],
template::button('groupEdit' . $groupId, [
'href' => helper::baseUrl() . 'user/groupEdit/' . $groupId . '/' . $_SESSION['csrf'],
template::button('permissionEdit' . $groupId, [
'href' => helper::baseUrl() . 'user/permissionEdit/' . $groupId . '/' . $_SESSION['csrf'],
'value' => template::ico('pencil'),
'help' => 'Éditer',
'disabled' => $groupData['readonly'],
]),
template::button('userDelete' . $groupId, [
template::button('permissionDelete' . $groupId, [
'class' => 'userDelete buttonRed',
'href' => helper::baseUrl() . 'user/groupDelete/' . $groupId . '/' . $_SESSION['csrf'],
'href' => helper::baseUrl() . 'user/permissionDelete/' . $groupId . '/' . $_SESSION['csrf'],
'value' => template::ico('trash'),
'help' => 'Supprimer',
'disabled' => $groupData['readonly'],
@ -437,15 +435,15 @@ class user extends common
}
// Valeurs en sortie
$this->addOutput([
'title' => helper::translate('Groupes'),
'view' => 'group'
'title' => helper::translate('Permissions'),
'view' => 'permission'
]);
}
/**
* Edition d'un groupe
*/
public function groupEdit()
public function permissionEdit()
{
if (
$this->getUrl(3) !== $_SESSION['csrf']
@ -462,39 +460,39 @@ class user extends common
if ($this->isPost()) {
$group = $this->getUrl(2);
$this->setData([
'group',
'permission',
$group,
[
'name' => $this->getData(['group', $group, 'name']),
'readonly' => $this->getData(['group', $group, 'readonly']),
'comment' => $this->getData(['group', $group, 'comment']),
'name' => $this->getData(['permission', $group, 'name']),
'readonly' => $this->getData(['permission', $group, 'readonly']),
'comment' => $this->getData(['permission', $group, 'comment']),
'file' => [
'download' => $this->getInput('groupEditDownload', helper::FILTER_BOOLEAN),
'edit' => $this->getInput('groupEditEdit', helper::FILTER_BOOLEAN),
'create' => $this->getInput('groupEditCreate', helper::FILTER_BOOLEAN),
'rename' => $this->getInput('groupEditRename', helper::FILTER_BOOLEAN),
'upload' => $this->getInput('groupEditUpload', helper::FILTER_BOOLEAN),
'delete' => $this->getInput('groupEditDelete', helper::FILTER_BOOLEAN),
'preview' => $this->getInput('groupEditPreview', helper::FILTER_BOOLEAN),
'duplicate' => $this->getInput('groupEditDuplicate', helper::FILTER_BOOLEAN),
'extract' => $this->getInput('groupEditExtract', helper::FILTER_BOOLEAN),
'copycut' => $this->getInput('groupEditCopycut', helper::FILTER_BOOLEAN),
'permission' => $this->getInput('groupEditPermission', helper::FILTER_BOOLEAN),
'download' => $this->getInput('permissionEditDownload', helper::FILTER_BOOLEAN),
'edit' => $this->getInput('permissionEditEdit', helper::FILTER_BOOLEAN),
'create' => $this->getInput('permissionEditCreate', helper::FILTER_BOOLEAN),
'rename' => $this->getInput('permissionEditRename', helper::FILTER_BOOLEAN),
'upload' => $this->getInput('permissionEditUpload', helper::FILTER_BOOLEAN),
'delete' => $this->getInput('permissionEditDelete', helper::FILTER_BOOLEAN),
'preview' => $this->getInput('permissionEditPreview', helper::FILTER_BOOLEAN),
'duplicate' => $this->getInput('permissionEditDuplicate', helper::FILTER_BOOLEAN),
'extract' => $this->getInput('permissionEditExtract', helper::FILTER_BOOLEAN),
'copycut' => $this->getInput('permissionEditCopycut', helper::FILTER_BOOLEAN),
'permission' => $this->getInput('permissionEditPermission', helper::FILTER_BOOLEAN),
],
'folder' => [
'create' => $this->getInput('groupEditFolderCreate', helper::FILTER_BOOLEAN),
'delete' => $this->getInput('groupEditFolderDelete', helper::FILTER_BOOLEAN),
'rename' => $this->getInput('groupEditFolderRename', helper::FILTER_BOOLEAN),
'copycut' => $this->getInput('groupEditFolderCopycut', helper::FILTER_BOOLEAN),
'permission' => $this->getInput('groupEditFolderPermission', helper::FILTER_BOOLEAN),
'share' => $this->getInput('groupEditShare', helper::FILTER_BOOLEAN),
'path' => $this->getInput('groupEditPath'),
'create' => $this->getInput('permissionEditFolderCreate', helper::FILTER_BOOLEAN),
'delete' => $this->getInput('permissionEditFolderDelete', helper::FILTER_BOOLEAN),
'rename' => $this->getInput('permissionEditFolderRename', helper::FILTER_BOOLEAN),
'copycut' => $this->getInput('permissionEditFolderCopycut', helper::FILTER_BOOLEAN),
'permission' => $this->getInput('permissionEditFolderPermission', helper::FILTER_BOOLEAN),
'share' => $this->getInput('permissionEditShare', helper::FILTER_BOOLEAN),
'path' => $this->getInput('permissionEditPath'),
]
]
]);
// Valeurs en sortie
$this->addOutput([
'redirect' => helper::baseUrl() . 'user/group',
'redirect' => helper::baseUrl() . 'user/permission',
'notification' => helper::translate('Modifications enregistrées'),
'state' => true
]);
@ -506,8 +504,8 @@ class user extends common
// Valeurs en sortie;
$this->addOutput([
'title' => sprintf(helper::translate('Groupe %s'), $this->getData(['group', $this->getUrl(2), 'name'])),
'view' => 'groupEdit'
'title' => sprintf(helper::translate('Groupe %s'), $this->getData(['permission', $this->getUrl(2), 'name'])),
'view' => 'permissionEdit'
]);
}

View File

@ -1,131 +0,0 @@
<?php echo template::formOpen('groupEditForm'); ?>
<div class="row">
<div class="col1">
<?php echo template::button('groupEditBack', [
'class' => 'buttonGrey',
'href' => helper::baseUrl() . 'user/group',
'value' => template::ico('left')
]); ?>
</div>
<div class="col2 offset9">
<?php echo template::submit('groupEditSubmit'); ?>
</div>
</div>
<div class="row">
<div class="col12">
<div class="block">
<h4>
<?php echo helper::translate('Opérations sur les fichiers'); ?>
</h4>
<div class="row">
<div class="col2">
<?php echo template::checkbox('groupEditDownload', true, 'Téléchargement', [
'checked' => $this->getData(['group', $this->getUrl(2), 'file', 'download'])
]); ?>
</div>
<div class="col2">
<?php echo template::checkbox('groupEditEdit', true, 'Edition', [
'checked' => $this->getData(['group', $this->getUrl(2), 'file', 'edit'])
]); ?>
</div>
<div class="col2">
<?php echo template::checkbox('groupEditCreate', true, 'Création', [
'checked' => $this->getData(['group', $this->getUrl(2), 'file', 'create'])
]); ?>
</div>
<div class="col2">
<?php echo template::checkbox('groupEditRename', true, 'Nommage', [
'checked' => $this->getData(['group', $this->getUrl(2), 'file', 'rename'])
]); ?>
</div>
<div class="col2">
<?php echo template::checkbox('groupEditUpload', true, 'Téléversement', [
'checked' => $this->getData(['group', $this->getUrl(2), 'file', 'upload'])
]); ?>
</div>
<div class="col2">
<?php echo template::checkbox('groupEditDelete', true, 'Effacement', [
'checked' => $this->getData(['group', $this->getUrl(2), 'file', 'delete'])
]); ?>
</div>
</div>
<div class="row">
<div class="col2">
<?php echo template::checkbox('groupEditPreview', true, 'Prévisualisation', [
'checked' => $this->getData(['group', $this->getUrl(2), 'file', 'preview'])
]); ?>
</div>
<div class="col2">
<?php echo template::checkbox('groupEditDuplicate', true, 'Duplication', [
'checked' => $this->getData(['group', $this->getUrl(2), 'file', 'duplicate'])
]); ?>
</div>
<div class="col2">
<?php echo template::checkbox('groupEditExtract', true, 'Extraction', [
'checked' => $this->getData(['group', $this->getUrl(2), 'file', 'extract'])
]); ?>
</div>
<div class="col2">
<?php echo template::checkbox('groupEditCopycut', true, 'Coupé collé', [
'checked' => $this->getData(['group', $this->getUrl(2), 'file', 'copycut'])
]); ?>
</div>
<div class="col2">
<?php echo template::checkbox('groupEditPermission', true, 'Permissions', [
'checked' => $this->getData(['group', $this->getUrl(2), 'file', 'permission'])
]); ?>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col12">
<div class="block">
<h4>
<?php echo helper::translate('Opérations sur les dossiers'); ?>
</h4>
<div class="row">
<div class="col2">
<?php echo template::checkbox('groupEditFolderCreate', true, 'Création', [
'checked' => $this->getData(['group', $this->getUrl(2), 'folder', 'create'])
]); ?>
</div>
<div class="col2">
<?php echo template::checkbox('groupEditFolderDelete', true, 'Effacement', [
'checked' => $this->getData(['group', $this->getUrl(2), 'folder', 'delete'])
]); ?>
</div>
<div class="col2">
<?php echo template::checkbox('groupEditFolderRename', true, 'Nommage', [
'checked' => $this->getData(['group', $this->getUrl(2), 'folder', 'rename'])
]); ?>
</div>
<div class="col2">
<?php echo template::checkbox('groupEditFolderCopycut', true, 'Coupé collé', [
'checked' => $this->getData(['group', $this->getUrl(2), 'folder', 'copycut'])
]); ?>
</div>
<div class="col2">
<?php echo template::checkbox('groupEditFolderPermission', true, 'Permissions', [
'checked' => $this->getData(['group', $this->getUrl(2), 'folder', 'permission'])
]); ?>
</div>
</div>
<div class="row">
<div class="col2">
<?php echo template::checkbox('groupEditShare', true, 'Partage', [
'checked' => $this->getData(['group', $this->getUrl(2), 'folder', 'share'])
]); ?>
</div>
<div class="col6">
<?php echo template::select('groupEditPath', $module::$sharePath, [
'label' => 'Racine du partage',
'selected' => $this->getData(['group', $this->getUrl(2), 'folder', 'path'])
]); ?>
</div>
</div>
</div>
</div>
</div>
<?php echo template::formClose(); ?>

View File

@ -24,9 +24,9 @@
</div>
<div class="col1">
<?php echo template::button('userGroup', [
'href' => helper::baseUrl() . 'user/group',
'value' => template::ico('users'),
'help' => 'Gestion des groupes'
'href' => helper::baseUrl() . 'user/permission',
'value' => template::ico('lock'),
'help' => 'Gestion des permissions'
]); ?>
</div>
<div class="col1">

View File

@ -1,10 +1,10 @@
<div class="row">
<div class="col1">
<?php echo template::button('userGroupBack', [
'class' => 'buttonGrey',
'href' => helper::baseUrl() . 'user',
'value' => template::ico('left')
]); ?>
</div>
</div>
<?php echo template::table([1, 3, 6, 1, 1], $module::$userGroups, ['#', 'Nom', 'Commentaire', '', '']); ?>
<div class="row">
<div class="col1">
<?php echo template::button('userGroupBack', [
'class' => 'buttonGrey',
'href' => helper::baseUrl() . 'user',
'value' => template::ico('left')
]); ?>
</div>
</div>
<?php echo template::table([3, 7, 1, 1], $module::$userGroups, ['Nom', 'Commentaire', '', '']); ?>

View File

@ -1,18 +1,18 @@
/**
* This file is part of Zwii.
*
* For full copyright and license information, please see the LICENSE
* file that was distributed with this source code.
*
* @author Rémi Jean <remi.jean@outlook.com>
* @copyright Copyright (C) 2008-2018, Rémi Jean
* @author Frédéric Tempez <frederic.tempez@outlook.com>
* @copyright Copyright (C) 2018-2023, Frédéric Tempez
* @license CC Attribution-NonCommercial-NoDerivatives 4.0 International
* @link http://zwiicms.fr/
*/
/** NE PAS EFFACER
* admin.css
/**
* This file is part of Zwii.
*
* For full copyright and license information, please see the LICENSE
* file that was distributed with this source code.
*
* @author Rémi Jean <remi.jean@outlook.com>
* @copyright Copyright (C) 2008-2018, Rémi Jean
* @author Frédéric Tempez <frederic.tempez@outlook.com>
* @copyright Copyright (C) 2018-2023, Frédéric Tempez
* @license CC Attribution-NonCommercial-NoDerivatives 4.0 International
* @link http://zwiicms.fr/
*/
/** NE PAS EFFACER
* admin.css
*/

View File

@ -0,0 +1,131 @@
<?php echo template::formOpen('permissionEditForm'); ?>
<div class="row">
<div class="col1">
<?php echo template::button('permissionEditBack', [
'class' => 'buttonGrey',
'href' => helper::baseUrl() . 'user/permission',
'value' => template::ico('left')
]); ?>
</div>
<div class="col2 offset9">
<?php echo template::submit('permissionEditSubmit'); ?>
</div>
</div>
<div class="row">
<div class="col12">
<div class="block">
<h4>
<?php echo helper::translate('Opérations sur les fichiers'); ?>
</h4>
<div class="row">
<div class="col2">
<?php echo template::checkbox('permissionEditDownload', true, 'Téléchargement', [
'checked' => $this->getData(['permission', $this->getUrl(2), 'file', 'download'])
]); ?>
</div>
<div class="col2">
<?php echo template::checkbox('permissionEditEdit', true, 'Edition', [
'checked' => $this->getData(['permission', $this->getUrl(2), 'file', 'edit'])
]); ?>
</div>
<div class="col2">
<?php echo template::checkbox('permissionEditCreate', true, 'Création', [
'checked' => $this->getData(['permission', $this->getUrl(2), 'file', 'create'])
]); ?>
</div>
<div class="col2">
<?php echo template::checkbox('permissionEditRename', true, 'Nommage', [
'checked' => $this->getData(['permission', $this->getUrl(2), 'file', 'rename'])
]); ?>
</div>
<div class="col2">
<?php echo template::checkbox('permissionEditUpload', true, 'Téléversement', [
'checked' => $this->getData(['permission', $this->getUrl(2), 'file', 'upload'])
]); ?>
</div>
<div class="col2">
<?php echo template::checkbox('permissionEditDelete', true, 'Effacement', [
'checked' => $this->getData(['permission', $this->getUrl(2), 'file', 'delete'])
]); ?>
</div>
</div>
<div class="row">
<div class="col2">
<?php echo template::checkbox('permissionEditPreview', true, 'Prévisualisation', [
'checked' => $this->getData(['permission', $this->getUrl(2), 'file', 'preview'])
]); ?>
</div>
<div class="col2">
<?php echo template::checkbox('permissionEditDuplicate', true, 'Duplication', [
'checked' => $this->getData(['permission', $this->getUrl(2), 'file', 'duplicate'])
]); ?>
</div>
<div class="col2">
<?php echo template::checkbox('permissionEditExtract', true, 'Extraction', [
'checked' => $this->getData(['permission', $this->getUrl(2), 'file', 'extract'])
]); ?>
</div>
<div class="col2">
<?php echo template::checkbox('permissionEditCopycut', true, 'Coupé collé', [
'checked' => $this->getData(['permission', $this->getUrl(2), 'file', 'copycut'])
]); ?>
</div>
<div class="col2">
<?php echo template::checkbox('permissionEditPermission', true, 'Permissions', [
'checked' => $this->getData(['permission', $this->getUrl(2), 'file', 'permission'])
]); ?>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col12">
<div class="block">
<h4>
<?php echo helper::translate('Opérations sur les dossiers'); ?>
</h4>
<div class="row">
<div class="col2">
<?php echo template::checkbox('permissionEditFolderCreate', true, 'Création', [
'checked' => $this->getData(['permission', $this->getUrl(2), 'folder', 'create'])
]); ?>
</div>
<div class="col2">
<?php echo template::checkbox('permissionEditFolderDelete', true, 'Effacement', [
'checked' => $this->getData(['permission', $this->getUrl(2), 'folder', 'delete'])
]); ?>
</div>
<div class="col2">
<?php echo template::checkbox('permissionEditFolderRename', true, 'Nommage', [
'checked' => $this->getData(['permission', $this->getUrl(2), 'folder', 'rename'])
]); ?>
</div>
<div class="col2">
<?php echo template::checkbox('permissionEditFolderCopycut', true, 'Coupé collé', [
'checked' => $this->getData(['permission', $this->getUrl(2), 'folder', 'copycut'])
]); ?>
</div>
<div class="col2">
<?php echo template::checkbox('permissionEditFolderPermission', true, 'Permissions', [
'checked' => $this->getData(['permission', $this->getUrl(2), 'folder', 'permission'])
]); ?>
</div>
</div>
<div class="row">
<div class="col2">
<?php echo template::checkbox('permissionEditShare', true, 'Partage', [
'checked' => $this->getData(['permission', $this->getUrl(2), 'folder', 'share'])
]); ?>
</div>
<div class="col6">
<?php echo template::select('permissionEditPath', $module::$sharePath, [
'label' => 'Racine du partage',
'selected' => $this->getData(['permission', $this->getUrl(2), 'folder', 'path'])
]); ?>
</div>
</div>
</div>
</div>
</div>
<?php echo template::formClose(); ?>