From 7f4c63df96e5618b3a6043082e1fdcf6562362d2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= <sebastien.gaya@gmail.com>
Date: Sat, 20 Apr 2024 18:44:41 +0200
Subject: [PATCH] unlock for background jobs (#1830)

---
 app/controllers/server/websites_controller.rb |  7 ++++++-
 app/views/server/websites/show.html.erb       | 17 ++++++++++++-----
 config/locales/communication/en.yml           |  3 ++-
 config/locales/communication/fr.yml           |  3 ++-
 config/locales/server_admin/en.yml            |  6 ++++--
 config/locales/server_admin/fr.yml            |  6 ++++--
 config/routes/server.rb                       |  1 +
 7 files changed, 31 insertions(+), 12 deletions(-)

diff --git a/app/controllers/server/websites_controller.rb b/app/controllers/server/websites_controller.rb
index 8602ece51..c1df647ab 100644
--- a/app/controllers/server/websites_controller.rb
+++ b/app/controllers/server/websites_controller.rb
@@ -29,6 +29,11 @@ class Server::WebsitesController < Server::ApplicationController
     @website.update_theme_version
   end
 
+  def unlock_for_background_jobs
+    @website.unlock_for_background_jobs!
+    redirect_back(fallback_location: server_website_path(@website), notice: t('server_admin.websites.unlock_for_background_jobs_notice'))
+  end
+
   def show
     @layouts = @website.git_file_layouts.ordered
     breadcrumb
@@ -36,7 +41,7 @@ class Server::WebsitesController < Server::ApplicationController
 
   def analyse
     Git::OrphanAndLayoutAnalyzer.new(@website).launch
-    redirect_back fallback_location: server_website_path(@website), 
+    redirect_back fallback_location: server_website_path(@website),
                   notice: t('admin.communication.website.git_file.analysis.launched')
   end
 
diff --git a/app/views/server/websites/show.html.erb b/app/views/server/websites/show.html.erb
index dd8cd8597..3ef796266 100644
--- a/app/views/server/websites/show.html.erb
+++ b/app/views/server/websites/show.html.erb
@@ -46,7 +46,7 @@
   </div>
 </div>
 
-<% if  @website.git_files_analysed_at %>
+<% if @website.git_files_analysed_at %>
   <div class="table-responsive">
     <table class="<%= table_classes(with_actions: false) %>">
       <thead>
@@ -66,12 +66,19 @@
   <p>Analyse le <%= l @website.git_files_analysed_at %></p>
 <% end %>
 
+<% if @website.locked_at.present? %>
+  <div class="alert alert-warning">
+    <p><%= Communication::Website.human_attribute_name(:locked_at) %> : <%= l(@website.locked_at, format: :long) %></p>
+    <%= link_to t('server_admin.websites.unlock_for_background_jobs_btn'), unlock_for_background_jobs_server_website_path(@website), method: :post, class: "btn btn-primary" %>
+  </div>
+<% end %>
+
 <% content_for :action_bar_right do %>
-  <%= link_to 'Analyser', 
+  <%= link_to 'Analyser',
               analyse_server_website_path(@website),
-              method: :post, 
+              method: :post,
               class: button_classes %>
-  <%= link_to 'Changer d\'université', 
-              edit_server_website_path(@website), 
+  <%= link_to 'Changer d\'université',
+              edit_server_website_path(@website),
               class: button_classes %>
 <% end %>
diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml
index 3e7cca0a5..86900dfb9 100644
--- a/config/locales/communication/en.yml
+++ b/config/locales/communication/en.yml
@@ -103,6 +103,7 @@ en:
         in_production: Production
         in_showcase: In showcase
         languages: Languages
+        locked_at: Locked for background jobs at
         name: Name
         plausible_url: Plausible dashboard URL
         repository: Repository
@@ -314,7 +315,7 @@ en:
           label: Editorial
           description: Everything related to content
         git_file:
-          analysis: 
+          analysis:
             launch: Launch analysis
             launched: Analysis launched
             title: Git analysis
diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml
index 7333f57f9..bd6dc5a37 100644
--- a/config/locales/communication/fr.yml
+++ b/config/locales/communication/fr.yml
@@ -103,6 +103,7 @@ fr:
         in_production: Site en production
         in_showcase: Dans le showcase
         languages: Langues
+        locked_at: Verrouillé pour les background jobs à
         name: Nom
         plausible_url: Tableau de bord Plausible
         repository: Référentiel
@@ -314,7 +315,7 @@ fr:
           label: Éditorial
           description: Tout ce qui est lié au contenu
         git_file:
-          analysis: 
+          analysis:
             launch: Lancer une analyse
             launched: Analyse lancée
             title: Analyse Git
diff --git a/config/locales/server_admin/en.yml b/config/locales/server_admin/en.yml
index 8a004f786..aa1283e09 100644
--- a/config/locales/server_admin/en.yml
+++ b/config/locales/server_admin/en.yml
@@ -53,9 +53,9 @@ en:
       clean_and_rebuild_all_websites_notice: All themes will be updated. This can take a few minutes.
       connections_count: "%{count} connexions"
       details: detail
-      events_count: "%{count} events"      
+      events_count: "%{count} events"
       force_clean_and_rebuild: Force clean&rebuild of every websites
-      git_repo: 
+      git_repo:
         full: Git Repository
         short: Repository
         status: Status
@@ -70,6 +70,8 @@ en:
       sync_theme_version_notice: The theme's version of %{website} has been synced
       theme_version: Theme version
       university_html: "University: %{university}"
+      unlock_for_background_jobs_btn: Unlock for background jobs
+      unlock_for_background_jobs_notice: The website is unlocked for background jobs.
       update_all_themes: Sync all themes versions
       update_mode: Update mode
       updatable_theme_filter:
diff --git a/config/locales/server_admin/fr.yml b/config/locales/server_admin/fr.yml
index 706fe26c2..374655e52 100644
--- a/config/locales/server_admin/fr.yml
+++ b/config/locales/server_admin/fr.yml
@@ -53,9 +53,9 @@ fr:
       clean_and_rebuild_all_websites_notice: Tous les thèmes vont être mis à jour. Cela peut prendre quelques minutes.
       connections_count: "%{count} connexions"
       details: détail
-      events_count: "%{count} événements"      
+      events_count: "%{count} événements"
       force_clean_and_rebuild: Forcer le clean&rebuild de tous les sites
-      git_repo: 
+      git_repo:
         full: Référentiel Git
         short: Référentiel
         status: Statut
@@ -70,6 +70,8 @@ fr:
       sync_theme_version_notice: La version du thème de %{website} a été synchronisée
       theme_version: Version du thème
       university_html: "Université : %{university}"
+      unlock_for_background_jobs_btn: Déverrouiller pour les background jobs
+      unlock_for_background_jobs_notice: Le site est déverrouillé pour les background jobs.
       update_all_themes: Synchroniser toutes les versions de thème
       update_mode: Mode de mise à jour
       updatable_theme_filter:
diff --git a/config/routes/server.rb b/config/routes/server.rb
index 7429619b9..83c59eff5 100644
--- a/config/routes/server.rb
+++ b/config/routes/server.rb
@@ -9,6 +9,7 @@ namespace :server do
       post :sync_theme_version
       post :analyse
       post :update_theme
+      post :unlock_for_background_jobs
     end
   end
   resources :blocks, only: [:index, :show] do
-- 
GitLab