diff --git a/app/controllers/server/application_controller.rb b/app/controllers/server/application_controller.rb index 15ed3b9a9354c93889e6ee07cd0c0feef2ad220f..9ae2ed234f5b6b1b0b1237ffa0b6fcb45830011d 100644 --- a/app/controllers/server/application_controller.rb +++ b/app/controllers/server/application_controller.rb @@ -12,7 +12,7 @@ class Server::ApplicationController < ApplicationController end def breadcrumb - add_breadcrumb t('admin.dashboard'), :server_root_path + add_breadcrumb t('server_admin.dashboard'), :server_root_path end def ensure_user_if_server_admin diff --git a/app/controllers/server/websites_controller.rb b/app/controllers/server/websites_controller.rb index 1269d7b89965744f3b7d9b5cf98c87d9774507e4..61eedc5f944557aa503f10827f6309b0545ac2d3 100644 --- a/app/controllers/server/websites_controller.rb +++ b/app/controllers/server/websites_controller.rb @@ -1,5 +1,5 @@ class Server::WebsitesController < Server::ApplicationController - before_action :load_website, only: [:sync_theme_version, :update_theme] + before_action :load_website, except: :index has_scope :for_theme_version has_scope :for_production @@ -10,7 +10,6 @@ class Server::WebsitesController < Server::ApplicationController def index @websites = apply_scopes(Communication::Website.all).ordered breadcrumb - add_breadcrumb Communication::Website.model_name.human(count: 2), server_websites_path end def sync_theme_version @@ -21,8 +20,24 @@ class Server::WebsitesController < Server::ApplicationController @website.update_theme_version end + def show + breadcrumb + add_breadcrumb @website + end + + def update + university_id = params.dig(:communication_website, :university_id) + @website.move_to_university(university_id) if university_id + redirect_to server_website_path(@website), notice: t('admin.successfully_updated_html', model: @website.to_s) + end + protected + def breadcrumb + super + add_breadcrumb Communication::Website.model_name.human(count: 2), server_websites_path + end + def load_website @website = Communication::Website.find params[:id] end diff --git a/app/models/communication/website.rb b/app/models/communication/website.rb index 0886d3dfcc57f6cdc360b6c147ce63507a18a4dc..48f24a2fb4e3eae7d12110bc8cbd300dbfa4c10b 100644 --- a/app/models/communication/website.rb +++ b/app/models/communication/website.rb @@ -145,6 +145,14 @@ class Communication::Website < ApplicationRecord end handle_asynchronously :sync_with_git, queue: 'default' + def move_to_university(new_university_id) + return if self.university_id == new_university_id + update_column :university_id, new_university_id + recursive_dependencies_syncable_following_direct.each do |dependency| + reconnect_dependency dependency, new_university_id + end + end + protected def sanitize_fields @@ -155,4 +163,27 @@ class Communication::Website < ApplicationRecord self.repository = Osuny::Sanitizer.sanitize(self.repository, 'string') self.url = Osuny::Sanitizer.sanitize(self.url, 'string') end + + def reconnect_dependency(dependency, new_university_id) + # puts + # puts "reconnect dependency #{dependency} - #{dependency.class}" + unless dependency.respond_to?(:university_id) + # puts "no university" + return + end + # puts " respond to university_id" + # vérifier par les connexions qu'un objet indirect n'est pas utilisé dans un autre website + if dependency.respond_to?(:connections) && dependency.connections.where.not(website: self).any? + # puts "other connection found, not moving" + return + end + # puts " no other connection" + # il faut si l'objet est une person déconnecter le user éventuellement associé. + if dependency.is_a? University::Person + # puts "person, disconnecting from user" + dependency.update_column :user_id, nil + end + # puts "connecting to #{new_university_id}" + dependency.update_column :university_id, new_university_id + end end diff --git a/app/views/server/dashboard/index.html.erb b/app/views/server/dashboard/index.html.erb index 0415ed36739a0384b40640773df349fc3969c1ae..d112c6976d705d97df8334fee7f4d239e61564c9 100644 --- a/app/views/server/dashboard/index.html.erb +++ b/app/views/server/dashboard/index.html.erb @@ -1,4 +1,4 @@ -<% content_for :title, t('hello', name: current_user.first_name) %> +<% content_for :title, t('server_admin.dashboard') %> <div class="row"> <% @parts.each do |part| %> diff --git a/app/views/server/websites/_list.html.erb b/app/views/server/websites/_list.html.erb index 348d4f4648266f317bdf849dd32d6363a38df66a..0c60c5694cf32eca98209aad247f14ff8facca8c 100644 --- a/app/views/server/websites/_list.html.erb +++ b/app/views/server/websites/_list.html.erb @@ -14,7 +14,7 @@ <% websites.ordered.each do |website| %> <tr id="website-<%= website.id %>"> <td> - <%= website.name %> + <%= link_to website.name, server_website_path(website) %> <% if website.in_production %> <span class="badge bg-success">Prod</span> <% end %> diff --git a/app/views/server/websites/edit.html.erb b/app/views/server/websites/edit.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..612786613c469d27b4e649aeaf09b022fd4bbd33 --- /dev/null +++ b/app/views/server/websites/edit.html.erb @@ -0,0 +1,11 @@ +<% content_for :title, @website %> +<%= simple_form_for @website, url: server_website_path(@website) do |f| %> + <%= f.error_notification %> + <%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %> + + <%= f.association :university, include_blank: false %> + + <% content_for :action_bar_right do %> + <%= submit f %> + <% end %> +<% end %> \ No newline at end of file diff --git a/app/views/server/websites/show.html.erb b/app/views/server/websites/show.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..c24a62d332f6466581eb8316d105bb753b9887bb --- /dev/null +++ b/app/views/server/websites/show.html.erb @@ -0,0 +1,18 @@ +<% content_for :title, @website %> + +<p> + Université : + <%= link_to @website.university, server_university_path(@website.university) %> +</p> + +<%= @website.pages.count %> pages<br> +<%= @website.posts.count %> actualités<br> +<%= @website.events.count %> événements<br> +<%= @website.connections.count %> connexions + (<%= link_to 'détail', admin_communication_website_connections_url(@website, host: @website.university.url), target: :_blank %>)<br> +<%= @website.recursive_dependencies.count %> dépendances + (<%= link_to 'détail', admin_communication_website_dependencies_url(@website, host: @website.university.url), target: :_blank %>)<br> + +<% content_for :action_bar_right do %> + <%= link_to t('edit'), edit_server_website_path(@website), class: button_classes %> +<% end %> diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml index ab0028d1a18374fba115e4c16ac77d76b81b5cec..d0cc74745b3d27fb57f90b2648b981d79790b410 100644 --- a/config/locales/communication/en.yml +++ b/config/locales/communication/en.yml @@ -163,6 +163,7 @@ en: social_x: "X, ex-Twitter (private)" social_youtube: "Youtube (private, belongs to Google)" url: URL + university: University communication/website/agenda/event: dates: Dates featured_image: Featured image @@ -417,6 +418,7 @@ en: 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 + university: Please note that changing university will disconnect people and organisations that are used on other sites, and will disconnect people from users. 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 4a2a0fd4bfd8315d3d195d015831c93d7b74dec9..ef4cc1f3d7c45092984a0d0f1584b4865433e871 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -162,6 +162,7 @@ fr: social_vimeo: "Vimeo (privatif)" social_x: "X, ex-Twitter (privatif)" social_youtube: "Youtube (privatif, appartient à Google)" + university: Université url: URL communication/website/agenda/event: dates: Dates @@ -417,6 +418,7 @@ fr: 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 + university: Attention, le changement d'université va déconnecter les personnes et organisations qui sont utilisées dans d'autres sites, et déconnecter les personnes des utilisateurs ou utilisatrices. 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. diff --git a/config/locales/en.yml b/config/locales/en.yml index 95e5cba299e941df87be563e3bdcb26c767859f0..31e2c4cac44c1d5501ba4b893da02c834dbc74b3 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -315,6 +315,7 @@ en: search: Search select_language: Select language server_admin: + dashboard: Server administration emergency_messages: all_universities: All all_roles: All diff --git a/config/locales/fr.yml b/config/locales/fr.yml index a9947df5cd5334f2bd65395da96ec553cb0c4e61..304eeb6bad444599f70be388756f7fc3b8179454 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -315,6 +315,7 @@ fr: search: Rechercher select_language: Sélectionnez une langue server_admin: + dashboard: Administration du serveur emergency_messages: all_universities: Toutes all_roles: Tous diff --git a/config/routes/server.rb b/config/routes/server.rb index af417e0c0892810bb70e1b1594b20f9ecc1c5b1b..a5c8ee6adfd9b07fad58a245262daa916a4add7c 100644 --- a/config/routes/server.rb +++ b/config/routes/server.rb @@ -1,7 +1,7 @@ namespace :server do resources :universities resources :languages - resources :websites, only: :index do + resources :websites do member do post :sync_theme_version post :update_theme