From f3256e2accf34468f9a36f3bbc644ee3ae5dc07e Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Tue, 11 Jul 2023 19:14:02 +0200
Subject: [PATCH] Fix #1143

---
 .../admin/communication/websites_controller.rb         |  3 ++-
 app/models/ability.rb                                  |  7 +++++--
 app/views/admin/communication/websites/_form.html.erb  |  2 +-
 config/locales/communication/en.yml                    |  4 ++++
 config/locales/communication/fr.yml                    | 10 +++++++---
 5 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/app/controllers/admin/communication/websites_controller.rb b/app/controllers/admin/communication/websites_controller.rb
index 4c83bc938..e7859ee18 100644
--- a/app/controllers/admin/communication/websites_controller.rb
+++ b/app/controllers/admin/communication/websites_controller.rb
@@ -74,9 +74,10 @@ class Admin::Communication::WebsitesController < Admin::Communication::Websites:
 
   def website_params
     attribute_names = [
-      :name, :url, :repository, :access_token, :about_type, :about_id, :in_production,
+      :name, :url, :repository, :about_type, :about_id, :in_production,
       :git_provider, :git_endpoint, :git_branch, :plausible_url, :deployment_status_badge, language_ids: []
     ]
+    attribute_names << :access_token unless params[:communication_website][:access_token].blank?
     # For now, default language can't be changed, too many implications, especially around special pages.
     attribute_names << :default_language_id unless @website&.persisted?
     params.require(:communication_website).permit(*attribute_names)
diff --git a/app/models/ability.rb b/app/models/ability.rb
index 77af5a43a..3e883f997 100644
--- a/app/models/ability.rb
+++ b/app/models/ability.rb
@@ -138,12 +138,15 @@ class Ability
     can :create, Communication::Block
     can :manage, Communication::Block::Heading, university_id: @user.university_id
     can :create, Communication::Block::Heading
-    can [:read, :analytics], Communication::Website, university_id: @user.university_id
+    can :manage, Communication::Website, university_id: @user.university_id
+    # Est-ce bien raisonnable de laisser supprimer un site ?
+    # Le risque de faussse manip est grand.
+    cannot :destroy, Communication::Website, university_id: @user.university_id
     can :manage, Communication::Website::Category, university_id: @user.university_id
     can :manage, Communication::Website::Imported::Website, university_id: @user.university_id
     can :manage, Communication::Website::Imported::Page, university_id: @user.university_id
     can :manage, Communication::Website::Imported::Post, university_id: @user.university_id
-    can [:read, :update, :reorder], Communication::Website::Menu, university_id: @user.university_id
+    can :manage, Communication::Website::Menu, university_id: @user.university_id
     can :manage, Communication::Website::Menu::Item, university_id: @user.university_id
     can :manage, Communication::Website::Page, university_id: @user.university_id
     can :manage, Communication::Website::Post, university_id: @user.university_id
diff --git a/app/views/admin/communication/websites/_form.html.erb b/app/views/admin/communication/websites/_form.html.erb
index 53f3e1b6a..ce490b4b1 100644
--- a/app/views/admin/communication/websites/_form.html.erb
+++ b/app/views/admin/communication/websites/_form.html.erb
@@ -22,7 +22,7 @@
               <%= f.input :deployment_status_badge, as: :string %>
             </div>
             <div class="col-xl-6">
-              <%= f.input :access_token %>
+              <%= f.input :access_token, as: :password %>
               <%= f.input :repository %>
               <%= f.input :git_branch %>
             </div>
diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml
index 153ee23b1..9c426507b 100644
--- a/config/locales/communication/en.yml
+++ b/config/locales/communication/en.yml
@@ -140,6 +140,7 @@ en:
         in_production: Production
         languages: Languages
         name: Name
+        plausible_url: Plausible dashboard URL
         repository: Repository
         url: URL
       communication/website/category:
@@ -820,10 +821,13 @@ en:
         host: Sans le protocole
         sso_button_label: "Default: Sign in via SSO"
       communication_website:
+        access_token: Your Github or Gitlab confidential access token. Leave blank if you want it unchanged.
         deployment_status_badge: "Badge URL: <a href=\"https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/adding-a-workflow-status-badge\" target=\"_blank\">Github</a>, <a href=\"https://docs.gitlab.com/ee/user/project/badges.html\" target=\"_blank\">Gitlab</a>"
         git_branch: 'If blank, default branch will be used'
         git_endpoint: 'If blank, default will be used (https://github.com or https://gitlab.com/api/v4)'
         languages: 'If you select one language the website urls will not be prefixed. If you select more than one language the website will then be considered as multilingual, and therefore all urls will be prefixed with the language (/fr, /en)'
+        plausible_url: Dashboard link generated following the <a href="https://plausible.io/docs/shared-links" target="_blank">official Plausible documentation</a>.
+        repository: As organization/name, for example noesya/bordeauxmontaigne-iut
       communication_website_page:
         breadcrumb_title: If the field is empty, page title will be used in breadcrumbs.
         full_width: On large screens, a full width page uses all available space for the content. This is good for landing pages, or to make them spectacular. If the page is not full width, the content column will be smaller to make reading easier. The unused space might be used for a table of contents.
diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml
index 5a0e78892..9e980e691 100644
--- a/config/locales/communication/fr.yml
+++ b/config/locales/communication/fr.yml
@@ -130,17 +130,18 @@ fr:
         about_Research::Journal: Site de revue scientifique
         about_Research::Laboratory: Site de laboratoire
         about_type: Type de site
-        access_token: Access token
+        access_token: Jeton d'accès
         created_at: Création
         default_language: Langue par défaut
         deployment_status_badge: Badge de statut du déploiement
         git_branch: Branche
         git_endpoint: Point d'accès Git
-        git_provider: Provider Git
+        git_provider: Fournisseur Git
         in_production: Site en production
         languages: Langues
         name: Nom
-        repository: Repository
+        plausible_url: Tableau de bord Plausible
+        repository: Référentiel
         url: URL
       communication/website/category:
         children: Catégories enfants
@@ -820,10 +821,13 @@ fr:
         host: Sans le protocole
         sso_button_label: "Par défaut : Se connecter en SSO"
       communication_website:
+        access_token: Votre clé d'accès Github ou Gitlab confidentielle. Laisser le champ vide vide pour ne pas le modifier.
         deployment_status_badge: "URL du badge : <a href=\"https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/adding-a-workflow-status-badge\" target=\"_blank\">Github</a>, <a href=\"https://docs.gitlab.com/ee/user/project/badges.html\" target=\"_blank\">Gitlab</a>"
         git_branch: 'Laisser vide pour la branche par défaut'
         git_endpoint: 'Laisser vide pour les valeurs par défaut (https://github.com ou https://gitlab.com/api/v4)'
         languages: 'Si vous sélectionnez une seule langue les urls ne seront pas préfixées. Si vous en sélectionnez plusieurs le site sera considéré comme multilingue et donc toutes les urls seront préfixées avec la langue (/fr, /en)'
+        plausible_url: Lien de partage généré selon la <a href="https://plausible.io/docs/shared-links" target="_blank">documentation officielle Plausible</a>.
+        repository: Sous la forme organisation/nom, par exemple noesya/bordeauxmontaigne-iut
       communication_website_page:
         breadcrumb_title: Si ce champ est vide le titre de la page sera utilisé dans le fil d'Ariane.
         full_width: Sur de grands écrans, la page en pleine largeur utilisera tout l'espace disponible, ce qui est pertinent pour événementialiser une page. Si la page n'est pas en pleine largeur, l'espace dédié au contenu sera réduit pour faciliter la lecture, et l'espace libre pourra être utilisé pour une table des matières facilitant la navigation.
-- 
GitLab