diff --git a/app/controllers/admin/communication/websites_controller.rb b/app/controllers/admin/communication/websites_controller.rb index 4d931dc92ab87943f0689be935bc2f1c3a4803b5..cd77a57143929e40b4a99e477a2451577cae5599 100644 --- a/app/controllers/admin/communication/websites_controller.rb +++ b/app/controllers/admin/communication/websites_controller.rb @@ -17,6 +17,12 @@ class Admin::Communication::WebsitesController < Admin::Communication::Websites: add_breadcrumb t('communication.website.security') end + def production + @website.in_production = true + breadcrumb + add_breadcrumb t('communication.website.golive.title') + end + def show @all_pages = @website.pages.accessible_by(current_ability).for_language(current_website_language) @pages = @all_pages.recent diff --git a/app/models/communication/website/with_deuxfleurs.rb b/app/models/communication/website/with_deuxfleurs.rb index f1d37cc39b6d4927a400dbf079a91f36619a6e1a..5b590d295ce2b2f8f9302f26885d54032fc8da18 100644 --- a/app/models/communication/website/with_deuxfleurs.rb +++ b/app/models/communication/website/with_deuxfleurs.rb @@ -2,6 +2,7 @@ module Communication::Website::WithDeuxfleurs extend ActiveSupport::Concern included do + before_save :deuxfleurs_golive, if: :deuxfleurs_hosting after_save :deuxfleurs_setup, if: :deuxfleurs_hosting end @@ -26,6 +27,17 @@ module Communication::Website::WithDeuxfleurs end handle_asynchronously :deuxfleurs_setup + def deuxfleurs_golive + return unless in_production_changed? && in_production + # https://www.test.com -> www.test.com + new_identifier = URI(url).host + if deuxfleurs.rename_bucket(self.deuxfleurs_identifier, new_identifier) + self.deuxfleurs_identifier = new_identifier + else + errors.add :url + end + end + def deuxfleurs_create_bucket deuxfleurs_identifier = deuxfleurs.create_bucket(deuxfleurs_default_identifier) update_columns deuxfleurs_identifier: deuxfleurs_identifier, diff --git a/app/services/deuxfleurs.rb b/app/services/deuxfleurs.rb index d0594d413f439167f216f0fe9ea909a719678bc6..468bb77daf1b7980ddd98e572bee079ca2c88026 100644 --- a/app/services/deuxfleurs.rb +++ b/app/services/deuxfleurs.rb @@ -6,6 +6,12 @@ class Deuxfleurs data.dig('vhost', 'name') end + def rename_bucket(host, new_identifier) + params = "{ \"vhost\": \"#{new_identifier}\" }" + response = client.patch("website/#{host}", params) + response.status == 200 + end + def default_url_for(host) "https://#{host}.web.deuxfleurs.fr" end diff --git a/app/views/admin/communication/websites/production.html.erb b/app/views/admin/communication/websites/production.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..7968e6a332d7030a16427314b62afea035a88196 --- /dev/null +++ b/app/views/admin/communication/websites/production.html.erb @@ -0,0 +1,18 @@ +<% content_for :title, t('communication.website.golive.title') %> + +<%= simple_form_for [:admin, @website] do |f| %> + <%= f.error_notification %> + <%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %> + + <%= f.input :in_production, as: :hidden %> + + <div class="row"> + <div class="col-xl-6"> + <%= f.input :url %> + </div> + </div> + + <% content_for :action_bar_right do %> + <%= submit f %> + <% end %> +<% end %> \ No newline at end of file diff --git a/app/views/admin/communication/websites/show.html.erb b/app/views/admin/communication/websites/show.html.erb index 6b673312c89f6fd32bfbbc2bb578cb37a3303a50..61cca0d9256c8b2f7153b9ca4baade5651ea3c4c 100644 --- a/app/views/admin/communication/websites/show.html.erb +++ b/app/views/admin/communication/websites/show.html.erb @@ -27,4 +27,7 @@ <% content_for :action_bar_right do %> <%= edit_link @website %> + <%= link_to t('communication.website.golive.button'), + production_admin_communication_website_path(@website), + class: button_classes unless @website.in_production %> <% end %> diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml index d0cc74745b3d27fb57f90b2648b981d79790b410..dc7c0dde660666620fa193106fb45a4e2e78ec43 100644 --- a/config/locales/communication/en.yml +++ b/config/locales/communication/en.yml @@ -296,6 +296,9 @@ en: website: analytics: Analytics git: Git + golive: + title: Go live + button: Go live hosting: Hosting last_events: Last events last_pages: Last pages diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index ef4cc1f3d7c45092984a0d0f1584b4865433e871..373308841eeaced2e3e1fe8d641ef085f3a1ab44 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -296,6 +296,9 @@ fr: website: analytics: Analytics git: Git + golive: + title: Mise en production + button: Mettre en production hosting: Hébergement last_events: Derniers événements last_pages: Dernières pages diff --git a/config/routes/admin/communication.rb b/config/routes/admin/communication.rb index 8c851edbc704856e35599db897b260be412d0bee..44454fe9951d2dd4fd1e3eee32607d32fa5b1342 100644 --- a/config/routes/admin/communication.rb +++ b/config/routes/admin/communication.rb @@ -8,6 +8,7 @@ namespace :communication do get :analytics get :security get :static + get :production end get 'style' => 'websites/preview#style', as: :style get 'assets/*path' => 'websites/preview#assets'