Gestion des permissions

This commit is contained in:
Fred Tempez 2023-03-29 19:28:03 +02:00
parent a65e8dcd63
commit 70b500443f
6 changed files with 303 additions and 204 deletions

View File

@ -343,7 +343,7 @@ class layout extends common
$items .= $this->getData(['theme', 'footer', 'displaymemberAccount']) === false ? ' class="displayNone">' : '>'; $items .= $this->getData(['theme', 'footer', 'displaymemberAccount']) === false ? ' class="displayNone">' : '>';
$items .= '<wbr>&nbsp;|&nbsp;'; $items .= '<wbr>&nbsp;|&nbsp;';
if ( if (
$this->getPermission('folder', 'share') === true $this->getUser('group') >= self::GROUP_MEMBER && $this->getPermission('folder', 'share') === true
) { ) {
$items .= '<wbr>' . template::ico('folder', [ $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']), '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 && $this->getData(['theme', 'menu', 'memberBar']) === true
) { ) {
if ( if (
$this->getPermission('folder', 'share') === true $this->getUser('group') >= self::GROUP_MEMBER && $this->getPermission('folder', 'share') === true
) { ) {
$itemsRight .= '<li>' . template::ico('folder', [ $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']), '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

@ -964,6 +964,10 @@ if ($this->getData(['core', 'dataVersion']) < 12400) {
if (file_exists('core/module/install/ressource/i18n/gr_GR.json')) if (file_exists('core/module/install/ressource/i18n/gr_GR.json'))
unlink('core/module/install/ressource/i18n/gr_GR.json'); unlink('core/module/install/ressource/i18n/gr_GR.json');
// Création du dossier partga pour les nouveaux droits
if (!is_dir(self::FILE_DIR . 'source/partage')) {
mkdir(self::FILE_DIR . 'source/partage');
}
// Mise à jour // Mise à jour
$this->setData(['core', 'dataVersion', 12400]); $this->setData(['core', 'dataVersion', 12400]);

View File

@ -335,81 +335,134 @@ class init extends common
'blacklist' => [], 'blacklist' => [],
'language'=> [], 'language'=> [],
'permission' => [ 'permission' => [
"banned" => [ '-1' => [
'name' => 'Banni', 'name' => 'Banni',
'readonly' => true, 'readonly' => true,
'comment' => 'Accès désactivé', 'comment' => 'Accès désactivé',
'group' => -1,
], ],
"visitor" => [ '0' => [
'name' => 'Visiteur', 'name' => 'Visiteur',
'readonly' => true, 'readonly' => true,
'comment' => 'Accède au site', 'comment' => 'Accède au site',
'group' => 0,
], ],
'member' => [ '1' => [
'name' => 'Membre', '0' => [
'readonly' => false, 'name' => 'Membre simple',
'comment' => 'Accède aux pages réservées et à un dossier partagé', 'readonly' => false,
'group' => 0, 'comment' => 'Accède aux pages réservées',
'file' => [ 'file' => [
'download' => false, 'download' => false,
'edit' => false, 'edit' => false,
'create' => false, 'create' => false,
'rename' => false, 'rename' => false,
'upload' => false, 'upload' => false,
'delete' => false, 'delete' => false,
'preview' => false, 'preview' => false,
'duplicate' => false, 'duplicate' => false,
'extract' => false, 'extract' => false,
'copycut' => false, 'copycut' => false,
'permission' => false 'permission' => false
],
'folder' => [
'create' => false,
'delete' => false,
'rename' => false,
'copycut' => false,
'permission' => false,
'share' => false,
'path' => './site/file/source/partage/',
]
], ],
'folder' => [ '1' => [
'create' => false, 'name' => 'Membre',
'delete' => false, 'readonly' => false,
'rename' => false, 'comment' => 'Accède aux pages réservées et à un dossier partagé',
'copycut' => false, 'file' => [
'permission' => false, 'download' => false,
'share' => false, 'edit' => false,
'path' => './site/file/source/partage/', 'create' => false,
] 'rename' => false,
], 'upload' => false,
"moderator" => [ 'delete' => false,
'name' => 'Moderateur', 'preview' => false,
'readonly' => false, 'duplicate' => false,
'comment' => 'Edition des pages', 'extract' => false,
'group' => 2, 'copycut' => false,
'file' => [ 'permission' => false
'download' => true, ],
'edit' => true, 'folder' => [
'create' => true, 'create' => false,
'rename' => true, 'delete' => false,
'upload' => true, 'rename' => false,
'delete' => false, 'copycut' => false,
'preview' => true, 'permission' => false,
'duplicate' => false, 'share' => true,
'extract' => false, 'path' => './site/file/source/partage/',
'copycut' => false, ]
'permission' => false ],
],
'2' => [
'0' => [
'name' => 'Modérateur',
'readonly' => false,
'comment' => 'Edition des pages',
'file' => [
'download' => true,
'edit' => true,
'create' => true,
'rename' => true,
'upload' => true,
'delete' => false,
'preview' => true,
'duplicate' => false,
'extract' => false,
'copycut' => false,
'permission' => false
],
'folder' => [
'create' => true,
'delete' => true,
'rename' => true,
'copycut' => false,
'permission' => false,
'share' => true,
'path' => './site/file/source/partage/',
]
],
'1' => [
'name' => 'Editeur avec gestion des fichiers',
'readonly' => false,
'comment' => 'Edition des pages',
'file' => [
'download' => true,
'edit' => true,
'create' => true,
'rename' => true,
'upload' => true,
'delete' => false,
'preview' => true,
'duplicate' => false,
'extract' => false,
'copycut' => false,
'permission' => false
],
'folder' => [
'create' => true,
'delete' => true,
'rename' => true,
'copycut' => false,
'permission' => false,
'share' => true,
'path' => './site/file/source/',
]
], ],
'folder' => [
'create' => true,
'delete' => true,
'rename' => true,
'copycut' => false,
'permission' => false,
'share' => false,
'path' => './site/file/source/partage/',
]
], ],
"admin" => [ '3' => [
'name' => 'Administrateur', 'name' => 'Administrateur',
'readonly' => true, 'readonly' => true,
'comment' => 'Contrôle total', 'comment' => 'Contrôle total',
'group' => 3,
] ]
], ]
]; ];
public static $defaultDataI18n = [ public static $defaultDataI18n = [
'en_EN' => [ 'en_EN' => [

View File

@ -386,7 +386,7 @@ class user extends common
self::$users[] = [ self::$users[] = [
$userId, $userId,
$userFirstname . ' ' . $this->getData(['user', $userId, 'lastname']), $userFirstname . ' ' . $this->getData(['user', $userId, 'lastname']),
helper::translate(self::$groups[(int)$this->getData(['user', $userId, 'group'])]), helper::translate(self::$groups[(int) $this->getData(['user', $userId, 'group'])]),
template::button('userEdit' . $userId, [ template::button('userEdit' . $userId, [
'href' => helper::baseUrl() . 'user/edit/' . $userId . '/' . $_SESSION['csrf'], 'href' => helper::baseUrl() . 'user/edit/' . $userId . '/' . $_SESSION['csrf'],
'value' => template::ico('pencil'), 'value' => template::ico('pencil'),
@ -413,25 +413,56 @@ class user extends common
*/ */
public function permission() public function permission()
{ {
$g = $this->getData(['permission']); foreach ($this->getData(['permission']) as $groupId => $groupData) {
foreach ($g as $groupId => $groupData) {
self::$userGroups[$groupId] = [ // Membres sans permissions spécifiques
$groupData['name'], if (
$groupData['comment'], $groupId == -1 ||
template::button('permissionEdit' . $groupId, [ $groupId == 0 ||
'href' => helper::baseUrl() . 'user/permissionEdit/' . $groupId . '/' . $_SESSION['csrf'], $groupId == 3
'value' => template::ico('pencil'), ) {
'help' => 'Éditer', self::$userGroups[$groupId] = [
'disabled' => $groupData['readonly'], $groupId,
]), $groupData['name'],
template::button('permissionDelete' . $groupId, [ $groupData['comment'],
'class' => 'userDelete buttonRed', template::button('permissionEdit' . $groupId, [
'href' => helper::baseUrl() . 'user/permissionDelete/' . $groupId . '/' . $_SESSION['csrf'], 'href' => helper::baseUrl() . 'user/permissionEdit/' . $groupId . '/' . $_SESSION['csrf'],
'value' => template::ico('trash'), 'value' => template::ico('pencil'),
'help' => 'Supprimer', 'help' => 'Éditer',
'disabled' => $groupData['readonly'], 'disabled' => $groupData['readonly'],
]) ]),
]; template::button('permissionDelete' . $groupId, [
'class' => 'userDelete buttonRed',
'href' => helper::baseUrl() . 'user/permissionDelete/' . $groupId . '/' . $_SESSION['csrf'],
'value' => template::ico('trash'),
'help' => 'Supprimer',
'disabled' => $groupData['readonly'],
])
];
} else {
// Enumérer les sous groupes MEMBER et MODERATOR
foreach ($groupData as $subGroupId => $subGroupData) {
echo $subGroupId;
self::$userGroups[$groupId.'.'.$subGroupId] = [
$groupId . '-' . $subGroupId,
$subGroupData['name'],
$subGroupData['comment'],
template::button('permissionEdit' . $groupId.$subGroupId, [
'href' => helper::baseUrl() . 'user/permissionEdit/' . $groupId . '-' . $subGroupId . '/' . $_SESSION['csrf'],
'value' => template::ico('pencil'),
'help' => 'Éditer',
'disabled' => $subGroupData['readonly'],
]),
template::button('permissionDelete' . $groupId.$subGroupId, [
'class' => 'userDelete buttonRed',
'href' => helper::baseUrl() . 'user/permissionDelete/' . $groupId . '-' . $subGroupId . '/' . $_SESSION['csrf'],
'value' => template::ico('trash'),
'help' => 'Supprimer',
'disabled' => $subGroupData['readonly'],
])
];
}
}
} }
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
@ -500,7 +531,7 @@ class user extends common
self::$sharePath = $this->getSubdirectories('./site/file/source'); self::$sharePath = $this->getSubdirectories('./site/file/source');
self::$sharePath = array_flip(self::$sharePath); self::$sharePath = array_flip(self::$sharePath);
self::$sharePath = array_merge( ['./site/file/source/' => '/'], self::$sharePath); self::$sharePath = array_merge(['./site/file/source/' => '/'], self::$sharePath);
// Valeurs en sortie; // Valeurs en sortie;
$this->addOutput([ $this->addOutput([
@ -625,8 +656,8 @@ class user extends common
$this->setData(['user', $userId, 'connectTimeout', time()]); $this->setData(['user', $userId, 'connectTimeout', time()]);
} }
// Cas 3 le délai de bloquage court // Cas 3 le délai de bloquage court
if ($this->getData(['user', $userId, 'connectTimeout']) + $this->getData(['config', 'connect', 'timeout']) > time()) { if ($this->getData(['user', $userId, 'connectTimeout']) + $this->getData(['config', 'connect', 'timeout']) > time()) {
$notification = sprintf(helper::translate('Accès bloqué %d minutes'), ($this->getData(['config', 'connect', 'timeout']) / 60)); $notification = sprintf(helper::translate('Accès bloqué %d minutes'), ($this->getData(['config', 'connect', 'timeout']) / 60));
} }
// Valeurs en sortie // Valeurs en sortie
@ -889,32 +920,33 @@ class user extends common
/** /**
* Liste les dossier contenus dans RFM * Liste les dossier contenus dans RFM
*/ */
function getSubdirectories($dir, $basePath = '') { function getSubdirectories($dir, $basePath = '')
{
$subdirs = array(); $subdirs = array();
// Ouvrez le répertoire spécifié // Ouvrez le répertoire spécifié
$dh = opendir($dir); $dh = opendir($dir);
// Parcourez tous les fichiers et répertoires dans le répertoire // Parcourez tous les fichiers et répertoires dans le répertoire
while (($file = readdir($dh)) !== false) { while (($file = readdir($dh)) !== false) {
// Ignorer les entrées de répertoire parent et actuel // Ignorer les entrées de répertoire parent et actuel
if ($file == '.' || $file == '..') { if ($file == '.' || $file == '..') {
continue; continue;
} }
// Construisez le chemin complet du fichier ou du répertoire // Construisez le chemin complet du fichier ou du répertoire
$path = $dir . '/' . $file; $path = $dir . '/' . $file;
// Vérifiez si c'est un répertoire // Vérifiez si c'est un répertoire
if (is_dir($path)) { if (is_dir($path)) {
// Construisez la clé et la valeur pour le tableau associatif // Construisez la clé et la valeur pour le tableau associatif
$key = $basePath . '/' . $file; $key = $basePath . '/' . $file;
$value = $path . '/'; $value = $path . '/';
// Ajouter la clé et la valeur au tableau associatif // Ajouter la clé et la valeur au tableau associatif
$subdirs[$key] = $value; $subdirs[$key] = $value;
// Appeler la fonction récursivement pour ajouter les sous-répertoires // Appeler la fonction récursivement pour ajouter les sous-répertoires
$subdirs = array_merge($subdirs, $this->getSubdirectories($path, $key)); $subdirs = array_merge($subdirs, $this->getSubdirectories($path, $key));
} }
} }
// Fermez le gestionnaire de dossier // Fermez le gestionnaire de dossier
closedir($dh); closedir($dh);
return $subdirs; return $subdirs;
} }
} }

View File

@ -7,4 +7,4 @@
]); ?> ]); ?>
</div> </div>
</div> </div>
<?php echo template::table([3, 7, 1, 1], $module::$userGroups, ['Nom', 'Commentaire', '', '']); ?> <?php echo template::table([1, 3, 7, 1, 1], $module::$userGroups, ['#', 'Nom', 'Commentaire', '', '']); ?>

View File

@ -15,117 +15,127 @@
<div class="col12"> <div class="col12">
<div class="block"> <div class="block">
<h4> <h4>
<?php echo helper::translate('Opérations sur les fichiers'); ?> <?php echo helper::translate('Gestionnaire de fichiers'); ?>
</h4> </h4>
<div class="row"> <div class="row">
<div class="col2"> <div class="col3">
<?php echo template::checkbox('permissionEditDownload', true, 'Téléchargement', [ <?php echo template::checkbox('permissionEditShare', true, 'Activé', [
'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']) 'checked' => $this->getData(['permission', $this->getUrl(2), 'folder', 'share'])
]); ?> ]); ?>
</div> </div>
<div class="col6"> <div class="col6">
<?php echo template::select('permissionEditPath', $module::$sharePath, [ <?php echo template::select('permissionEditPath', $module::$sharePath, [
'label' => 'Racine du partage', 'label' => 'Racine du dossier',
'selected' => $this->getData(['permission', $this->getUrl(2), 'folder', 'path']) 'selected' => $this->getData(['permission', $this->getUrl(2), 'folder', 'path'])
]); ?> ]); ?>
</div> </div>
</div> </div>
<div class="row">
<div class="col12">
<div class="block">
<h4>
<?php echo helper::translate('Permissions 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>
</div>
</div>
<div class="row">
<div class="col12">
<div class="block">
<h4>
<?php echo helper::translate('Permissions 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> </div>
</div> </div>
</div> </div>
<?php echo template::formClose(); ?> <?php echo template::formClose(); ?>