From a7efdbf6c5e552ea9cd5ad9cfd0d88bce9cd0760 Mon Sep 17 00:00:00 2001 From: Fred Tempez Date: Thu, 16 Jul 2020 18:50:57 +0200 Subject: [PATCH] Approbation des commentaires --- CHANGES.md | 6 +-- module/blog/blog.php | 61 ++++++++++++++++------- module/blog/view/add/add.js.php | 36 ++++++++++++++ module/blog/view/add/add.php | 82 ++++++++++++++++++++++--------- module/blog/view/edit/edit.js.php | 4 +- module/blog/view/edit/edit.php | 48 +++++++++++------- 6 files changed, 175 insertions(+), 62 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index cd55d25f..f18dae11 100755 --- a/CHANGES.md +++ b/CHANGES.md @@ -9,11 +9,9 @@ - Nombre maximal de caractère par commentaire. - Gestion des commentaires article par article. - Suppression des commentaires en masse. + - Limiter l'édition des articles et des commentaires à l'id de l'éditeur + - Approbation des commentaires En cours : - - Limiter l'édition des articles et des commentaires à l'id de l'éditeur - A réaliser : - - Approbation des commentaires - - Edition de l'article, afficher les signatures plutôt que les noms - Reprise de la date d'édition, bug avec Chrome git ## version 10.2.04 diff --git a/module/blog/blog.php b/module/blog/blog.php index dbde3e6b..cf7e6b05 100755 --- a/module/blog/blog.php +++ b/module/blog/blog.php @@ -15,10 +15,10 @@ class blog extends common { // Objets - // Propriétaire - groupe Editeur - groupe Admin - const EDIT_ALL = '011'; // Groupes Editeurs et admins - const EDIT_OWNER_ADMIN = '101'; // Propriétaire éditeur + groupe admin - const EDIT_ADMIN = '001'; // Groupe des admin + // Propriétaire - groupe + const EDIT_ALL = '02'; // Groupes Editeurs et admins + const EDIT_OWNER_ADMIN = '23'; // Propriétaire éditeur + groupe admin + const EDIT_ADMIN = '03'; // Groupe des admin public static $actions = [ 'add' => self::GROUP_MODERATOR, @@ -76,11 +76,15 @@ class blog extends common { '10000' => '10000' ]; - // Permission d'un article - public static $articlePermissions = [ - self::EDIT_ALL => 'Editeurs et administrateurs', - self::EDIT_OWNER_ADMIN => 'Auteur et groupe des administrateurs', - self::EDIT_ADMIN => 'Groupe des administrateurs', + // Permissions d'un article + public static $articleRightsAdmin = [ + self::EDIT_ALL => 'Groupes des éditeurs et des administrateurs', + self::EDIT_OWNER_ADMIN => 'Editeur et groupe des administrateurs', + self::EDIT_ADMIN => 'Groupe des administrateurs' + ]; + public static $articleRightsModerator = [ + self::EDIT_ALL => 'Groupes des éditeurs et des administrateurs', + self::EDIT_OWNER_ADMIN => 'Editeur et groupe des administrateurs' ]; public static $users = []; @@ -294,6 +298,24 @@ class blog extends common { public function config() { // Ids des articles par ordre de publication $articleIds = array_keys(helper::arrayCollumn($this->getData(['module', $this->getUrl(0)]), 'publishedOn', 'SORT_DESC')); + // Gestion des droits d'accès + $filterData=[]; + foreach ($articleIds as $key => $value) { + $rights = $this->getData(['module', $this->getUrl(0), $value,'editRights']); + // Compatibilité pas de droit stocké placer droit par défaut + $rights = empty($rights) ? '02' : $rights; + // Check les droits du propriétaire + // Check les droits du groupe + if ( + ( substr($rights,0,1) === '2' + AND $this->getData(['module', $this->getUrl(0), $value,'userId']) === $this->getUser('id') + ) + OR ( $this->getUser('group') >= substr($rights,1,1) ) + ) { + $filterData[] = $value; + } + } + $articleIds = $filterData; // Pagination $pagination = helper::pagination($articleIds, $this->getUrl(),$this->getData(['config','itemsperPage'])); // Liste des pages @@ -301,15 +323,19 @@ class blog extends common { // Articles en fonction de la pagination for($i = $pagination['first']; $i < $pagination['last']; $i++) { // Nombre de commentaires à approuver et approuvés - if ( !empty(helper::arrayCollumn($this->getData(['module', $this->getUrl(0), $articleIds[$i], 'comment' ]),'approval', 'SORT_DESC'))) { - $a = array_values(helper::arrayCollumn($this->getData(['module', $this->getUrl(0), $articleIds[$i], 'comment' ]),'approval', 'SORT_DESC')); - $toApprove = count(array_keys($a,false)); - $approved = count(array_keys($a,true)); - } else { + $approvals = []; + // Compatibilité : vérifier si les données sont disponibles + if ( $this->getData(['module', $this->getUrl(0), $articleIds[$i], 'comment' ,'approval' ]) !== NULL ) { + $approvals = helper::arrayCollumn($this->getData(['module', $this->getUrl(0), $articleIds[$i], 'comment' ]),'approval', 'SORT_DESC'); + } + if ( empty($approvals) ) { $toApprove = 0; $approved = count($this->getData(['module', $this->getUrl(0), $articleIds[$i],'comment'])); + } else { + $a = array_values($approvals); + $toApprove = count(array_keys($a,false)); + $approved = count(array_keys($a,true)); } - // Met en forme le tableau self::$articles[] = [ '' . @@ -426,7 +452,8 @@ class blog extends common { 'title' => $this->getInput('blogEditTitle', helper::FILTER_STRING_SHORT, true), 'userId' => $newuserid, 'commentMaxlength' => $this->getInput('blogEditCommentMaxlength'), - 'commentApprove' => $this->getInput('blogEditCommentApprove', helper::FILTER_BOOLEAN) + 'commentApprove' => $this->getInput('blogEditCommentApprove', helper::FILTER_BOOLEAN), + 'editRights' => $this->getInput('blogEditRights') ]]); // Supprime l'ancien article if($articleId !== $this->getUrl(2)) { @@ -443,7 +470,7 @@ class blog extends common { self::$users = helper::arrayCollumn($this->getData(['user']), 'firstname'); ksort(self::$users); foreach(self::$users as $userId => &$userFirstname) { - $userFirstname = $userFirstname . ' ' . $this->getData(['user', $userId, 'lastname']); + $userFirstname = $userFirstname . ' ' . $this->getData(['user', $userId, 'lastname']) . ' (' . self::$groupEdits[$this->getData(['user', $userId, 'group'])] . ')'; } unset($userFirstname); // Valeurs en sortie diff --git a/module/blog/view/add/add.js.php b/module/blog/view/add/add.js.php index bb843f65..aca2fb5f 100755 --- a/module/blog/view/add/add.js.php +++ b/module/blog/view/add/add.js.php @@ -16,4 +16,40 @@ $("#blogAddDraft").on("click", function() { $("#blogAddState").val(0); $("#blogAddForm").trigger("submit"); +}); + +/** + * Options de commentaires + */ +$("#blogAddCloseComment").on("change", function() { + if ($(this).is(':checked') ) { + $("#commentOptionsWrapper").slideUp(); + } else { + $("#commentOptionsWrapper").slideDown(); + } +}); + +$("#blogAddMailNotification").on("change", function() { + if ($(this).is(':checked') ) { + $("#blogAddGroupNotification").slideDown(); + } else { + $("#blogAddGroupNotification").slideUp(); + } +}); + + +$( document).ready(function() { + + if ($("#blogAddCloseComment").is(':checked') ) { + $("#commentOptionsWrapper").slideUp(); + } else { + $("#commentOptionsWrapper").slideDown(); + } + + if ($("#blogAddMailNotification").is(':checked') ) { + $("#blogAddGroupNotification").slideDown(); + } else { + $("#blogAddGroupNotification").slideUp(); + } + }); \ No newline at end of file diff --git a/module/blog/view/add/add.php b/module/blog/view/add/add.php index 149c81d7..058894c8 100755 --- a/module/blog/view/add/add.php +++ b/module/blog/view/add/add.php @@ -67,37 +67,75 @@ 'editorWysiwyg' ]); ?> +
+
+
+

Options de publication

+
+
+ 'Choix du nombre maximum de caractères pour chaque commentaire de l\'article, mise en forme html comprise.', + 'label' => 'Caractères par commentaire', + 'selected' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'commentMaxlength']) + ]); ?> +
+
+ 'Auteur', + 'selected' => $this->getUser('id'), + 'disabled' => $this->getUser('group') !== self::GROUP_ADMIN ? true : false + ]); ?> +
+
+ 'L\'article n\'est visible qu\'après la date de publication prévue.', + 'label' => 'Date de publication', + 'value' => time() + ]); ?> +
+
+
+
+
-

Options de publication

- 'Auteur', - 'selected' => $this->getUser('id'), - 'disabled' => $this->getUser('group') !== self::GROUP_ADMIN ? true : false - ]); ?> - 'L\'article n\'est visible qu\'après la date de publication prévue.', - 'label' => 'Date de publication', - 'value' => time() +

Permissions

+ getUser('group') === self::GROUP_ADMIN ? $module::$articleRightsAdmin : $module::$articleRightsModerator , [ + 'label' => 'Droits d\'édition et de modification', + 'selected' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'editRights']) ]); ?>
-

Options avancées

- 'Choix du nombre maximum de caractères pour chaque commentaire de l\'article, caractères de mise en forme html inclus.', - 'label' => 'Nombre maximum de caractères pour chaque commentaire', - 'selected' => '5000' - ]); ?> - - 'Editeurs = éditeurs + administrateurs
Membres = membres + éditeurs + administrateurs' - ]); ?> - '' +

Commentaires

+ $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'closeComment']) ]); ?> +
+
+
+ $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'commentApprove']), + '' + ]); ?> +
+
+
+
+ $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'mailNotification']), + ]); ?> +
+
+ $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'groupNotification']), + 'help' => 'Editeurs = éditeurs + administrateurs
Membres = membres + éditeurs + administrateurs' + ]); ?> +
+
+
diff --git a/module/blog/view/edit/edit.js.php b/module/blog/view/edit/edit.js.php index 0b4cc432..f7be9c2f 100755 --- a/module/blog/view/edit/edit.js.php +++ b/module/blog/view/edit/edit.js.php @@ -30,7 +30,9 @@ $("#blogEditDraft").on("click", function() { $("#blogEditForm").trigger("submit"); }); - +/** + * Options de commentaires + */ $("#blogEditCloseComment").on("change", function() { if ($(this).is(':checked') ) { $("#commentOptionsWrapper").slideUp(); diff --git a/module/blog/view/edit/edit.php b/module/blog/view/edit/edit.php index c5b3bf9c..56d507ef 100755 --- a/module/blog/view/edit/edit.php +++ b/module/blog/view/edit/edit.php @@ -76,32 +76,44 @@
-

Permissions

+

Options de publication

+
+
+ 'Choix du nombre maximum de caractères pour chaque commentaire de l\'article, mise en forme html comprise.', + 'label' => 'Caractères par commentaire', + 'selected' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'commentMaxlength']) + ]); ?> +
+
+ 'Auteur', + 'selected' => $this->getUser('id'), + 'disabled' => $this->getUser('group') !== self::GROUP_ADMIN ? true : false + ]); ?> +
+
+ 'L\'article n\'est visible qu\'après la date de publication prévue.', + 'label' => 'Date de publication', + 'value' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'publishedOn']) + ]); ?> +
+
-
+
-

Options de publication

- 'Choix du nombre maximum de caractères pour chaque commentaire de l\'article, mise en forme html comprise.', - 'label' => 'Caractères par commentaire', - 'selected' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'commentMaxlength']) - ]); ?> - 'Auteur', - 'selected' => $this->getUser('id'), - 'disabled' => $this->getUser('group') !== self::GROUP_ADMIN ? true : false - ]); ?> - 'L\'article n\'est visible qu\'après la date de publication prévue.', - 'label' => 'Date de publication', - 'value' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'publishedOn']) +

Permissions

+ getUser('group') === self::GROUP_ADMIN ? $module::$articleRightsAdmin : $module::$articleRightsModerator , [ + 'label' => 'Droits d\'édition et de modification', + 'selected' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'editRights']) ]); ?>
-
+

Commentaires