From 0a9f740ce87f7cf33734133426f0469d37d89b6b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timoth=C3=A9e=20Poussard?= <tpoussard@neogeo.fr>
Date: Thu, 7 Oct 2021 16:53:26 +0200
Subject: [PATCH] adapt status choices for contributor & fix check of feature
 creator

---
 src/views/feature/Feature_edit.vue | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/src/views/feature/Feature_edit.vue b/src/views/feature/Feature_edit.vue
index cefa6f35..f10670b1 100644
--- a/src/views/feature/Feature_edit.vue
+++ b/src/views/feature/Feature_edit.vue
@@ -386,21 +386,22 @@ export default {
       if (this.project) {
         const isModerate = this.project.moderation;
         const userStatus = this.USER_LEVEL_PROJECTS[this.project.slug];
-        //* si admin ou modérateur, statuts toujours disponible :  	Brouillon, Publié, Archivé
+        const isOwnFeature = this.feature //* prevent undefined feature
+          ? this.feature.creator === this.user.id
+          : false; //* si le contributeur est l'auteur du signalement
         if (
+          //* si admin ou modérateur, statuts toujours disponible :  	Brouillon, Publié, Archivé
           userStatus === "Modérateur" ||
           userStatus === "Administrateur projet"
         ) {
           return this.statusChoices.filter((el) => el.value !== "pending");
         } else if (userStatus === "Contributeur") {
+          //* cas particuliers du contributeur
           if (
-            this.currentRouteName === "editer-signalement" &&
-            this.project.creator === this.user.id
+            this.currentRouteName === "ajouter-signalement" ||
+            !isOwnFeature
           ) {
-            //* IF création de project
-            return this.statusChoices.filter((el) => el.value === "draft");
-          } else {
-            //* ELSE édition de projet
+            //* même cas à l'ajout d'une feature ou si feature n'a pas été créé par le contributeur
             return isModerate
               ? this.statusChoices.filter(
                   (el) => el.value === "draft" || el.value === "pending"
@@ -408,6 +409,15 @@ export default {
               : this.statusChoices.filter(
                   (el) => el.value === "draft" || el.value === "published"
                 );
+          } else {
+            //* à l'édition d'une feature et si le contributeur est l'auteur de la feature
+            return isModerate
+              ? this.statusChoices.filter(
+                  (el) => el.value !== "published" //* toutes sauf "Publié"
+                )
+              : this.statusChoices.filter(
+                  (el) => el.value !== "pending" //* toutes sauf "En cours de publication"
+                );
           }
         }
       }
@@ -529,6 +539,7 @@ export default {
       }); // * create an object with the counter in store
       this.attachmentDataKey += 1; // * increment counter for key in v-for
     },
+
     addAttachment(attachment) {
       console.log(attachment);
       this.$store.commit("feature/ADD_ATTACHMENT_FORM", {
@@ -541,6 +552,7 @@ export default {
       });
       this.attachmentDataKey += 1;
     },
+
     addExistingAttachementFormset(attachementFormset) {
       for (const attachment of attachementFormset) {
         this.addAttachment(attachment);
-- 
GitLab