From c0f6c9333c38512ceefd58057ece618ad34bff36 Mon Sep 17 00:00:00 2001
From: Inga Kirschnick <inga.kirschnick@uni-bielefeld.de>
Date: Mon, 21 Nov 2022 16:35:11 +0100
Subject: [PATCH] update contribute share button

---
 .../js/RessourceLists/SpacyNLPPipelineModelList.js | 14 ++++++++++----
 .../TesseractOCRPipelineModelList.js               | 13 ++++++++++++-
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/app/static/js/RessourceLists/SpacyNLPPipelineModelList.js b/app/static/js/RessourceLists/SpacyNLPPipelineModelList.js
index 08535b46..78693c91 100644
--- a/app/static/js/RessourceLists/SpacyNLPPipelineModelList.js
+++ b/app/static/js/RessourceLists/SpacyNLPPipelineModelList.js
@@ -31,7 +31,7 @@ class SpaCyNLPPipelineModelList extends RessourceList {
         <td><b><span class="title"></span> <span class="version"></span></b><br><i><span class="description"></span></i></td>
         <td><a class="publisher-url"><span class="publisher"></span></a> (<span class="publishing-year"></span>)<br><a class="publishing-url"><span class="publishing-url-2"></span></a></td>
         <td>
-          <div class="switch action-switch center-align" data-action="share-request" data-user-role=>
+          <div class="switch action-switch center-align" data-action="share-request">
             <span class="share"></span>
             <label>
               <input type="checkbox" class="shared">
@@ -86,8 +86,8 @@ class SpaCyNLPPipelineModelList extends RessourceList {
 
   init(user) {
     this._init(user.spacy_nlp_pipeline_models);
-    for (let switchElement of this.listjs.list.querySelectorAll('.shared')) {
-      if (user.role.name !== 'Administrator' || user.role.name !== 'Contributor') {
+    if (user.role.name !== ('Administrator' || 'Contributor')) {
+      for (let switchElement of this.listjs.list.querySelectorAll('.shared')) {
         switchElement.setAttribute('disabled', '');
       }
     }
@@ -101,7 +101,13 @@ class SpaCyNLPPipelineModelList extends RessourceList {
   }
 
   onClick(event) {
-    if (event.target.closest('.action-switch')) {return;}
+    if (event.target.closest('.action-switch')) {
+      let userRole = app.data.users[this.userId].role.name;
+      if (userRole !== ('Administrator' || 'Contributor')) {
+        app.flash('You need the "Contributor" or "Administrator" role to perform this action.', 'error');
+      }
+      return;
+    }
     let actionButtonElement = event.target.closest('.action-button');
     let action = actionButtonElement === null ? 'view' : actionButtonElement.dataset.action;
     let spaCyNLPPipelineModelElement = event.target.closest('tr');
diff --git a/app/static/js/RessourceLists/TesseractOCRPipelineModelList.js b/app/static/js/RessourceLists/TesseractOCRPipelineModelList.js
index 33e7f432..22c4bc37 100644
--- a/app/static/js/RessourceLists/TesseractOCRPipelineModelList.js
+++ b/app/static/js/RessourceLists/TesseractOCRPipelineModelList.js
@@ -86,6 +86,11 @@ class TesseractOCRPipelineModelList extends RessourceList {
 
   init (user) {
     this._init(user.tesseract_ocr_pipeline_models);
+    if (user.role.name !== ('Administrator' || 'Contributor')) {
+      for (let switchElement of this.listjs.list.querySelectorAll('.shared')) {
+        switchElement.setAttribute('disabled', '');
+      }
+    }
   }
 
   _init(ressources) {
@@ -96,7 +101,13 @@ class TesseractOCRPipelineModelList extends RessourceList {
   }
 
   onClick(event) {
-    if (event.target.closest('.action-switch')) {return;}
+    if (event.target.closest('.action-switch')) {
+      let userRole = app.data.users[this.userId].role.name;
+      if (userRole !== ('Administrator' || 'Contributor')) {
+        app.flash('You need the "Contributor" or "Administrator" role to perform this action.', 'error');
+      }
+      return;
+    }
     let actionButtonElement = event.target.closest('.action-button');
     let action = actionButtonElement === null ? 'view' : actionButtonElement.dataset.action;
     let tesseractOCRPipelineModelElement = event.target.closest('tr');
-- 
GitLab