changeset 5348:45b03e8ca47e extented-report

Toggles in user overview and in details section as well established This commit introduces toggles to change the state for administrative users to be able to receive the DQL Report. For quick access there is the possibility to change via overview. If you want to edit this in the details or if you change the role of the user to a non administrative, there is the possibility to change the flag in a fast way. When the user looses administrative privilege the option is not available and the according flag is set to "false". Aside: Changed user.go to resolve inconsitencies in frontend where the key "reports" was missing due to "omitempty" in marshalling the go objects.
author Thomas Junk <thomas.junk@intevation.de>
date Mon, 21 Jun 2021 16:41:39 +0200
parents 1fc454da7ee8
children a352a695b69c
files client/src/components/usermanagement/Userdetail.vue client/src/components/usermanagement/Usermanagement.vue pkg/models/user.go
diffstat 3 files changed, 85 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/client/src/components/usermanagement/Userdetail.vue	Sun Jun 20 14:11:13 2021 +0200
+++ b/client/src/components/usermanagement/Userdetail.vue	Mon Jun 21 16:41:39 2021 +0200
@@ -109,6 +109,21 @@
               :passworderrors="errors.passwordre"
             />
           </div>
+          <div class="form-group row" v-if="DQLDownloadAllowed()">
+            <label for="user">
+              <translate>Recipient for DQL Report </translate>
+            </label>
+            <toggle-button
+              :value="currentUser.reports"
+              v-model="currentUser.reports"
+              class="pt-1 w-100"
+              :sync="true"
+              :speed="100"
+              v-tooltip="receivesReportLabel"
+              :width="40"
+              :height="20"
+            />
+          </div>
         </div>
         <div>
           <button
@@ -238,6 +253,9 @@
     }
   },
   computed: {
+    receivesReportLabel() {
+      return this.$gettext("User receives Data Quality Report");
+    },
     cardHeader() {
       if (this.currentUser.isNew) return this.$gettext("Add User");
       return this.currentUser.user;
@@ -260,6 +278,12 @@
     }
   },
   methods: {
+    DQLDownloadAllowed() {
+      return (
+        this.currentUser.role === "waterway_admin" ||
+        this.currentUser.role === "sys_admin"
+      );
+    },
     passwordChanged(value) {
       this.password = value;
       this.validatePassword();
@@ -317,6 +341,9 @@
       if (!this.isFormValid) return;
       if (this.password) this.currentUser.password = this.password;
       this.submitted = true;
+      if (this.currentUser.role === "waterway_user") {
+        this.currentUser.reports = false;
+      }
       this.$store
         .dispatch("usermanagement/saveCurrentUser", {
           path: this.user.user,
--- a/client/src/components/usermanagement/Usermanagement.vue	Sun Jun 20 14:11:13 2021 +0200
+++ b/client/src/components/usermanagement/Usermanagement.vue	Mon Jun 21 16:41:39 2021 +0200
@@ -10,7 +10,8 @@
               { id: 'role', title: `${roleForColumLabel}`, class: 'col-1' },
               { id: 'user', title: `${usernameLabel}`, class: 'col-4' },
               { id: 'country', title: `${countryLabel}`, class: 'col-2' },
-              { id: 'email', title: `${emailLabel}`, class: 'col-3' }
+              { id: 'email', title: `${emailLabel}`, class: 'col-3' },
+              { id: 'reportreceiver', title: `${reportsLabel}`, class: 'col-1' }
             ]"
           />
           <UITableBody
@@ -41,6 +42,20 @@
               <div class="table-cell col-3" @click="selectUser(user.user)">
                 {{ user.email }}
               </div>
+              <div class="table-cell center col-1">
+                <toggle-button
+                  v-if="DQLDownloadAllowed(user)"
+                  :value="user.reports"
+                  v-model="user.reports"
+                  class="pt-1"
+                  :sync="true"
+                  :speed="100"
+                  @change="toggleReport(user)"
+                  v-tooltip="receivesReportLabel"
+                  :width="40"
+                  :height="20"
+                />
+              </div>
               <div class="table-cell col text-right justify-content-end">
                 <button
                   @click="sendTestMail(user.user)"
@@ -133,6 +148,7 @@
 import { displayError, displayInfo } from "@/lib/errors";
 import { HTTP } from "@/lib/http";
 import { sortTable } from "@/lib/mixins";
+import Vue from "vue";
 
 export default {
   name: "userview",
@@ -147,15 +163,18 @@
     Spacer: () => import("@/components/Spacer")
   },
   computed: {
-    ...mapGetters("usermanagement", [
-      "isUserDetailsVisible",
-      "users",
-      "currentUser"
-    ]),
+    ...mapGetters("usermanagement", ["isUserDetailsVisible", "users"]),
     ...mapState("application", ["showSidebar"]),
+    ...mapState("usermanagement", ["currentUser"]),
     usersLabel() {
       return this.$gettext("Users");
     },
+    reportsLabel() {
+      return this.$gettext("DQL Report");
+    },
+    receivesReportLabel() {
+      return this.$gettext("User receives Data Quality Report");
+    },
     sendMailLabel() {
       return this.$gettext("Send testmail");
     },
@@ -197,6 +216,38 @@
     }
   },
   methods: {
+    DQLDownloadAllowed(user) {
+      return user.role === "waterway_admin" || user.role === "sys_admin";
+    },
+    toggleReport(user) {
+      HTTP.patch(
+        `/users/${user.user}`,
+        {
+          reports: user.reports
+        },
+        {
+          headers: {
+            "X-Gemma-Auth": localStorage.getItem("token"),
+            "Content-type": "text/xml; charset=UTF-8"
+          }
+        }
+      )
+        .then(() => {
+          Vue.set(this.currentUser, "reports", user.reports);
+        })
+        .catch(error => {
+          let message = "Backend not reachable";
+          if (error.response) {
+            const { status, data } = error.response;
+            message = `${status}: ${data.message || data}`;
+          }
+          displayError({
+            title: this.$gettext("Backend Error"),
+            message: message
+          });
+          user.reports = !user.reports;
+        });
+    },
     sendTestMail(user) {
       HTTP.get("/testmail/" + encodeURIComponent(user), {
         headers: {
--- a/pkg/models/user.go	Sun Jun 20 14:11:13 2021 +0200
+++ b/pkg/models/user.go	Mon Jun 21 16:41:39 2021 +0200
@@ -46,7 +46,7 @@
 		Password string       `json:"password,omitempty"`
 		Email    Email        `json:"email"`
 		Country  Country      `json:"country"`
-		Reports  bool         `json:"reports,omitempty"`
+		Reports  bool         `json:"reports"`
 		Extent   *BoundingBox `json:"extent"`
 	}