diff --git a/app/controllers/admin/communication/websites_controller.rb b/app/controllers/admin/communication/websites_controller.rb index 78014db11ef7439bfbc281a3ede660ad138e1c68..1c4878bb3d7fddc4bfaf449040455ed8b0e0b831 100644 --- a/app/controllers/admin/communication/websites_controller.rb +++ b/app/controllers/admin/communication/websites_controller.rb @@ -69,6 +69,6 @@ class Admin::Communication::WebsitesController < Admin::Communication::Applicati protected def website_params - params.require(:communication_website).permit(:name, :domain, :repository, :access_token, :about_type, :about_id) + params.require(:communication_website).permit(:name, :url, :repository, :access_token, :about_type, :about_id) end end diff --git a/app/models/communication/website.rb b/app/models/communication/website.rb index 8f02e7ae6941dcbd33113ed6ef03a6e7e90825a2..6cc21d8164e3717e7e4cdd86a400d10c199faf4d 100644 --- a/app/models/communication/website.rb +++ b/app/models/communication/website.rb @@ -5,9 +5,9 @@ # id :uuid not null, primary key # about_type :string # access_token :string -# domain :string # name :string # repository :string +# url :string # created_at :datetime not null # updated_at :datetime not null # about_id :uuid @@ -67,10 +67,6 @@ class Communication::Website < ApplicationRecord "#{name}" end - def domain_url - @domain_url ||= "https://#{domain}" - end - def import! unless imported? self.imported_website = Communication::Website::Imported::Website.where(website: self, university: university) diff --git a/app/models/communication/website/imported/website.rb b/app/models/communication/website/imported/website.rb index fa9da9b80b4528c985072624e8da39ca26e0af62..06ccdf35c67358f42ff18d7ebc2cb0b255bf5420 100644 --- a/app/models/communication/website/imported/website.rb +++ b/app/models/communication/website/imported/website.rb @@ -49,13 +49,13 @@ class Communication::Website::Imported::Website < ApplicationRecord handle_asynchronously :run!, queue: 'default' def uploads_url - @uploads_url ||= "#{website.domain_url}/wp-content/uploads" + @uploads_url ||= "#{website.url}/wp-content/uploads" end protected def wordpress - @wordpress ||= Wordpress.new website.domain_url + @wordpress ||= Wordpress.new website.url end def sync_authors diff --git a/app/services/wordpress.rb b/app/services/wordpress.rb index 8a08973beb4a7a0fd337143a57db85a9b3e7b98a..c53639cd566597f46ad2149f61b25112cefdad97 100644 --- a/app/services/wordpress.rb +++ b/app/services/wordpress.rb @@ -1,5 +1,5 @@ class Wordpress - attr_reader :domain + attr_reader :url def self.clean_string(string) @@ -47,28 +47,28 @@ class Wordpress string end - def initialize(domain) - @domain = domain + def initialize(url) + @url = url end def authors - load "#{domain}/wp-json/wp/v2/users" + load "#{url}/wp-json/wp/v2/users" end def categories - load "#{domain}/wp-json/wp/v2/categories" + load "#{url}/wp-json/wp/v2/categories" end def posts - load "#{domain}/wp-json/wp/v2/posts" + load "#{url}/wp-json/wp/v2/posts" end def pages - load "#{domain}/wp-json/wp/v2/pages" + load "#{url}/wp-json/wp/v2/pages" end def media - load "#{domain}/wp-json/wp/v2/media" + load "#{url}/wp-json/wp/v2/media" end protected diff --git a/app/views/admin/communication/websites/_form.html.erb b/app/views/admin/communication/websites/_form.html.erb index ac221bc9d2d6a959c19940b995f5ca3db665a2ff..840edae94fa63fbbd369850f15f00bba3ef38d12 100644 --- a/app/views/admin/communication/websites/_form.html.erb +++ b/app/views/admin/communication/websites/_form.html.erb @@ -34,7 +34,7 @@ <h5 class="card-title mb-0"><%= t('metadata') %></h5> </div> <div class="card-body"> - <%= f.input :domain %> + <%= f.input :url %> <%= f.input :repository %> <%= f.input :access_token %> </div> diff --git a/app/views/admin/communication/websites/index.html.erb b/app/views/admin/communication/websites/index.html.erb index 98b938fdd40016e16cd48383b0e8dcb762c57b89..b4ebe5d3fca6bd2f4b51d1d6521c6ba2ad9c4dd0 100644 --- a/app/views/admin/communication/websites/index.html.erb +++ b/app/views/admin/communication/websites/index.html.erb @@ -4,7 +4,7 @@ <thead> <tr> <th><%= Communication::Website.human_attribute_name('name') %></th> - <th><%= Communication::Website.human_attribute_name('domain') %></th> + <th><%= Communication::Website.human_attribute_name('url') %></th> <th><%= Communication::Website.human_attribute_name('about_type') %></th> <th><%= Communication::Website.human_attribute_name('about') %></th> <th></th> @@ -14,7 +14,7 @@ <% @websites.each do |website| %> <tr> <td><%= link_to website, [:admin, website] %></td> - <td><%= link_to website.domain_url, website.domain_url, target: :_blank %></td> + <td><%= link_to website.url, website.url, target: :_blank %></td> <td><%= I18n.t("activerecord.attributes.communication/website.about_#{website.about_type}") %></td> <td><%= link_to website.about, [:admin, website.about] if website.about %></td> <td class="text-end"> diff --git a/app/views/admin/communication/websites/show.html.erb b/app/views/admin/communication/websites/show.html.erb index ccffbb28a0cafa2fba89e5b6e710cc4a1b53a872..ea7a61a1223ed178d51c7fae6a88c5ebeaa83f2b 100644 --- a/app/views/admin/communication/websites/show.html.erb +++ b/app/views/admin/communication/websites/show.html.erb @@ -1,8 +1,8 @@ <% content_for :title, @website %> <% content_for :title_right do %> - <% unless @website.domain.blank? %> - <%= link_to @website.domain_url, @website.domain_url, target: :_blank %><br> + <% unless @website.url.blank? %> + <%= link_to @website.url, @website.url, target: :_blank %><br> <% end %> <%= I18n.t("activerecord.attributes.communication/website.about_#{@website.about_type}") %> <% if @website.about %> diff --git a/app/views/admin/dashboard/index.html.erb b/app/views/admin/dashboard/index.html.erb index f693873e81a87e002272da8386b9c1fdb715f588..bfc04677d206700925559742c2e0515ee3048532 100644 --- a/app/views/admin/dashboard/index.html.erb +++ b/app/views/admin/dashboard/index.html.erb @@ -42,7 +42,7 @@ <div class="card-body"> <span class="float-end"><i class="fas fa-sitemap fa-2x"></i></span> <h4><%= website %></h4> - <p class="small"><%= website.domain %></p> + <p class="small"><%= website.url %></p> <%= link_to 'Voir', [:admin, website], class: button_classes('stretched-link') %> </div> </div> diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml index 4e14c61413a8069891d6870ed39bcccea1b45095..c7679dc4ad3ccdc92f81b72cb66cfd31fe85d439 100644 --- a/config/locales/communication/en.yml +++ b/config/locales/communication/en.yml @@ -58,8 +58,8 @@ en: about_Education::School: School website about_Research::Journal: Journal website about_type: About - domain: Domain name: Name + url: URL communication/website/author: biography: Biography first_name: First name diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index 27fd73436032021b039cb33d3682a4612e0a1814..3038dc200e487156dad427f14de5d4636edaf745 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -58,8 +58,8 @@ fr: about_Education::School: Site d'école about_Research::Journal: Site de revue scientifique about_type: Sujet du site - domain: Domaine name: Nom + url: URL communication/website/author: biography: Biographie first_name: Prénom diff --git a/db/migrate/20211123130833_rename_domain_to_url_in_communication_websites.rb b/db/migrate/20211123130833_rename_domain_to_url_in_communication_websites.rb new file mode 100644 index 0000000000000000000000000000000000000000..014bc485d92a4f061db579492c30b44008952716 --- /dev/null +++ b/db/migrate/20211123130833_rename_domain_to_url_in_communication_websites.rb @@ -0,0 +1,5 @@ +class RenameDomainToUrlInCommunicationWebsites < ActiveRecord::Migration[6.1] + def change + rename_column :communication_websites, :domain, :url + end +end diff --git a/db/schema.rb b/db/schema.rb index 32e1f8878cf696d424e29f2966ab6ecfe960ead2..aa243a249477a0eb30feeba79146e95c71189f0e 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.define(version: 2021_11_22_142007) do +ActiveRecord::Schema.define(version: 2021_11_23_130833) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -315,7 +315,7 @@ ActiveRecord::Schema.define(version: 2021_11_22_142007) do create_table "communication_websites", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.string "name" - t.string "domain" + t.string "url" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.string "access_token" diff --git a/lib/tasks/app.rake b/lib/tasks/app.rake index e00449085d6eee8c24f2ad8f6793753591c7e11d..9abe3b1f5bb345fa53b3157164e1a2eac65200ee 100644 --- a/lib/tasks/app.rake +++ b/lib/tasks/app.rake @@ -12,7 +12,11 @@ namespace :app do # Communication::Website::Page.find_each { |page| page.update(text: page.old_text) } Research::Researcher.find_each { |researcher| researcher.update(biography: researcher.old_biography) if researcher.biography.blank? } Research::Journal::Article.find_each { |article| article.update(text: article.old_text) if article.text.blank? } - Communication::Website.find_each { |website| website.build_home(university_id: website.university_id).save if website.home.nil? } + Communication::Website.find_each { |website| + website.build_home(university_id: website.university_id).save if website.home.nil? + website.update_column(:url, "https://#{website.url}") unless website.url.blank? || website.url.starts_with?('https://') + } + end namespace :db do