From 4300b0fcdb644501c97e0aa495e9cd29ad982de2 Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Tue, 4 Jul 2023 13:36:41 +0200
Subject: [PATCH] Deployment status

---
 app/controllers/admin/communication/websites_controller.rb   | 2 +-
 app/views/admin/communication/websites/_form.html.erb        | 1 +
 app/views/admin/communication/websites/show.html.erb         | 1 +
 config/locales/communication/en.yml                          | 1 +
 config/locales/communication/fr.yml                          | 1 +
 .../20230704113222_add_status_to_communication_websites.rb   | 5 +++++
 db/schema.rb                                                 | 3 ++-
 7 files changed, 12 insertions(+), 2 deletions(-)
 create mode 100644 db/migrate/20230704113222_add_status_to_communication_websites.rb

diff --git a/app/controllers/admin/communication/websites_controller.rb b/app/controllers/admin/communication/websites_controller.rb
index 959e547d1..4c83bc938 100644
--- a/app/controllers/admin/communication/websites_controller.rb
+++ b/app/controllers/admin/communication/websites_controller.rb
@@ -75,7 +75,7 @@ class Admin::Communication::WebsitesController < Admin::Communication::Websites:
   def website_params
     attribute_names = [
       :name, :url, :repository, :access_token, :about_type, :about_id, :in_production,
-      :git_provider, :git_endpoint, :git_branch, :plausible_url, language_ids: []
+      :git_provider, :git_endpoint, :git_branch, :plausible_url, :deployment_status_badge, language_ids: []
     ]
     # For now, default language can't be changed, too many implications, especially around special pages.
     attribute_names << :default_language_id unless @website&.persisted?
diff --git a/app/views/admin/communication/websites/_form.html.erb b/app/views/admin/communication/websites/_form.html.erb
index 5433758d3..53f3e1b6a 100644
--- a/app/views/admin/communication/websites/_form.html.erb
+++ b/app/views/admin/communication/websites/_form.html.erb
@@ -19,6 +19,7 @@
             <div class="col-xl-6">
               <%= f.input :git_provider, include_blank: false %>
               <%= f.input :git_endpoint %>
+              <%= f.input :deployment_status_badge, as: :string %>
             </div>
             <div class="col-xl-6">
               <%= f.input :access_token %>
diff --git a/app/views/admin/communication/websites/show.html.erb b/app/views/admin/communication/websites/show.html.erb
index dcce07ed0..e7be9bca6 100644
--- a/app/views/admin/communication/websites/show.html.erb
+++ b/app/views/admin/communication/websites/show.html.erb
@@ -16,6 +16,7 @@
 <%= render 'admin/communication/websites/sidebar' do %>
   <%= render 'admin/communication/websites/show/posts' if can? :read, Communication::Website::Post %>
   <%= render 'admin/communication/websites/show/pages' if can? :read, Communication::Website::Page %>
+  <%= image_tag @website.deployment_status_badge, alt: '' if @website.deployment_status_badge.present? %>
 <% end %>
 
 <% content_for :action_bar_left do %>
diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml
index d13fae666..707366c1f 100644
--- a/config/locales/communication/en.yml
+++ b/config/locales/communication/en.yml
@@ -133,6 +133,7 @@ en:
         access_token: Access token
         created_at: Creation
         default_language: Default language
+        deployment_status_badge: Deployment status badge
         git_branch: Git branch
         git_endpoint: Git endpoint
         git_provider: Git provider
diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml
index 441f6ccec..25668c9ee 100644
--- a/config/locales/communication/fr.yml
+++ b/config/locales/communication/fr.yml
@@ -133,6 +133,7 @@ fr:
         access_token: Access token
         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
diff --git a/db/migrate/20230704113222_add_status_to_communication_websites.rb b/db/migrate/20230704113222_add_status_to_communication_websites.rb
new file mode 100644
index 000000000..3c1902078
--- /dev/null
+++ b/db/migrate/20230704113222_add_status_to_communication_websites.rb
@@ -0,0 +1,5 @@
+class AddStatusToCommunicationWebsites < ActiveRecord::Migration[7.0]
+  def change
+    add_column :communication_websites, :deployment_status_badge, :text
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 53ef9884f..548674c3a 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema[7.0].define(version: 2023_07_03_142438) do
+ActiveRecord::Schema[7.0].define(version: 2023_07_04_113222) do
   # These are extensions that must be enabled in order to support this database
   enable_extension "pgcrypto"
   enable_extension "plpgsql"
@@ -519,6 +519,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_07_03_142438) do
     t.boolean "in_production", default: false
     t.uuid "default_language_id", null: false
     t.string "theme_version", default: "NA"
+    t.text "deployment_status_badge"
     t.index ["about_type", "about_id"], name: "index_communication_websites_on_about"
     t.index ["default_language_id"], name: "index_communication_websites_on_default_language_id"
     t.index ["university_id"], name: "index_communication_websites_on_university_id"
-- 
GitLab