diff --git a/app/controllers/admin/communication/website/home_controller.rb b/app/controllers/admin/communication/website/home_controller.rb index 26b752790ca8fb27aff4830d8230ab16882bf110..323e9ba3ccf96dbb7eb0b651bf385632109d3371 100644 --- a/app/controllers/admin/communication/website/home_controller.rb +++ b/app/controllers/admin/communication/website/home_controller.rb @@ -1,5 +1,5 @@ class Admin::Communication::Website::HomeController < Admin::Communication::Website::ApplicationController - before_action :get_home + before_action :get_home, :ensure_abilities def edit breadcrumb @@ -23,6 +23,10 @@ class Admin::Communication::Website::HomeController < Admin::Communication::Webs @home = @website.home end + def ensure_abilities + authorize! :update, @home + end + def home_params params.require(:communication_website_home) .permit( diff --git a/app/controllers/admin/communication/website/structure_controller.rb b/app/controllers/admin/communication/website/structure_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..7b8c08c5915e685b8a931f47ca95969b9966b27a --- /dev/null +++ b/app/controllers/admin/communication/website/structure_controller.rb @@ -0,0 +1,45 @@ +class Admin::Communication::Website::StructureController < Admin::Communication::Website::ApplicationController + before_action :get_structure, :ensure_abilities + + def edit + breadcrumb + add_breadcrumb Communication::Website::Structure.model_name.human + render 'admin/communication/website/structures/edit' + end + + def update + if @structure.update_and_sync(structure_params) + redirect_to admin_communication_website_path(@website), notice: t('admin.successfully_updated_html', model: Communication::Website::Structure.model_name.human) + else + breadcrumb + add_breadcrumb Communication::Website::Structure.model_name.human + render :edit, status: :unprocessable_entity + end + end + + protected + + def get_structure + @structure = @website.structure + end + + def ensure_abilities + authorize! :update, @structure + end + + def structure_params + params.require(:communication_website_structure) + .permit( + :home_title, + :communication_posts_title, :communication_posts_description, :communication_posts_path, + :education_programs_title, :education_programs_description, :education_programs_path, + :research_articles_title, :research_articles_description, :research_articles_path, + :research_volumes_title, :research_volumes_description, :research_volumes_path, + :persons_title, :persons_description, :persons_path, + :administrators_title, :administrators_description, :administrators_path, + :authors_title, :authors_description, :authors_path, + :researchers_title, :researchers_description, :researchers_path, + :teachers_title, :teachers_description, :teachers_path + ) + end +end diff --git a/app/models/ability.rb b/app/models/ability.rb index 8a78c4723c97f63533fe477353bf038073b324a7..d1338c05ae6d003e437ca7ba0b8e3f565e2ea342 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -60,6 +60,7 @@ class Ability can :manage, Communication::Website::Post, university_id: @user.university_id can :manage, Communication::Website::Category, university_id: @user.university_id can :manage, Communication::Website::Home, university_id: @user.university_id + can :manage, Communication::Website::Structure, university_id: @user.university_id can [:read, :update, :reorder], Communication::Website::Menu, university_id: @user.university_id can :manage, Communication::Website::Menu::Item, university_id: @user.university_id can :manage, Communication::Website::Imported::Website, university_id: @user.university_id diff --git a/app/models/communication/website.rb b/app/models/communication/website.rb index d583ecedbd4a216b8653318347c9cd3dc4490104..81b72df4736f1162bb308b04e48d94982c68049a 100644 --- a/app/models/communication/website.rb +++ b/app/models/communication/website.rb @@ -38,6 +38,7 @@ class Communication::Website < ApplicationRecord include WithHome include WithImport include WithMenuItems + include WithStructure belongs_to :university diff --git a/app/models/communication/website/structure.rb b/app/models/communication/website/structure.rb new file mode 100644 index 0000000000000000000000000000000000000000..a9dd624751878d7754455bbdccfc39f40b7937ba --- /dev/null +++ b/app/models/communication/website/structure.rb @@ -0,0 +1,76 @@ +# == Schema Information +# +# Table name: communication_website_structures +# +# id :uuid not null, primary key +# administrators_description :text default("Liste des membres de l'équipe administrative") +# administrators_path :string default("equipe-administrative") +# administrators_title :string default("Équipe administrative") +# authors_description :text default("Liste des membres de l'équipe éditoriale") +# authors_path :string default("equipe-editoriale") +# authors_title :string default("Équipe éditoriale") +# communication_posts_description :text default("Liste des actualités") +# communication_posts_path :string default("actualites") +# communication_posts_title :string default("Actualités") +# education_programs_description :text default("Liste des formations proposées") +# education_programs_path :string default("offre-de-formation") +# education_programs_title :string default("L'offre de formation") +# home_title :string default("Accueil") +# persons_description :text default("Liste des membres de l'équipe") +# persons_path :string default("equipe") +# persons_title :string default("Équipe") +# research_articles_description :text default("Liste des articles") +# research_articles_path :string default("articles") +# research_articles_title :string default("Articles") +# research_volumes_description :text default("Liste des volumes") +# research_volumes_path :string default("volumes") +# research_volumes_title :string default("Volumes") +# researchers_description :text default("Liste des membres de l'équipe de recherche") +# researchers_path :string default("equipe-de-recherche") +# researchers_title :string default("Équipe de recherche") +# teachers_description :text default("Liste des membres de l'équipe pédagogique") +# teachers_path :string default("equipe-pedagogique") +# teachers_title :string default("Équipe pédagogique") +# created_at :datetime not null +# updated_at :datetime not null +# communication_website_id :uuid not null +# university_id :uuid not null +# +# Indexes +# +# idx_comm_website_structures_on_communication_website_id (communication_website_id) +# index_communication_website_structures_on_university_id (university_id) +# +# Foreign Keys +# +# fk_rails_... (communication_website_id => communication_websites.id) +# fk_rails_... (university_id => universities.id) +# +class Communication::Website::Structure < ApplicationRecord + include WithGit + + belongs_to :university + belongs_to :website, foreign_key: :communication_website_id + + validates :home_title, + :administrators_title, :administrators_path, + :authors_title, :authors_path, + :communication_posts_title, :communication_posts_path, + :education_programs_title, :education_programs_path, + :persons_title, :persons_path, + :research_articles_title, :research_articles_path, + :research_volumes_title, :research_volumes_path, + :researchers_title, :researchers_path, + :teachers_title, :teachers_path, + presence: true + + def to_s + website.to_s + end + + # def git_path(website) + # 'content/_index.html' + # end + + +end diff --git a/app/models/communication/website/with_structure.rb b/app/models/communication/website/with_structure.rb new file mode 100644 index 0000000000000000000000000000000000000000..0cf849296ff80e6921cc6772ceba68eb3196e5d1 --- /dev/null +++ b/app/models/communication/website/with_structure.rb @@ -0,0 +1,18 @@ +module Communication::Website::WithStructure + extend ActiveSupport::Concern + + included do + has_one :structure, + class_name: 'Communication::Website::Structure', + foreign_key: :communication_website_id, + dependent: :destroy + + after_create :create_structure + end + + protected + + def create_structure + build_structure(university_id: university_id).save + end +end diff --git a/app/views/admin/communication/website/structures/edit.html.erb b/app/views/admin/communication/website/structures/edit.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..5fed9a9af93e1d6f25ee7b43ddae8d6b14a99a2c --- /dev/null +++ b/app/views/admin/communication/website/structures/edit.html.erb @@ -0,0 +1,95 @@ +<% content_for :title, t('activerecord.models.communication/website/structure.one') %> + +<%= render 'admin/communication/websites/sidebar' do %> + <%= simple_form_for @structure, url: admin_communication_website_structure_path(website_id: @website.id) do |f| %> + <div class="row"> + <div class="col-md-6"> + <div class="card flex-fill w-100"> + <div class="card-body"> + <%= f.input :home_title %> + <hr class="my-5"> + <%= f.input :communication_posts_title %> + <%= f.input :communication_posts_description %> + <%= f.input :communication_posts_path, + input_html: { + class: 'js-slug-input', + data: { source: '#communication_website_structure_communication_posts_title' } + } %> + <hr class="my-5"> + <%= f.input :education_programs_title %> + <%= f.input :education_programs_description %> + <%= f.input :education_programs_path, + input_html: { + class: 'js-slug-input', + data: { source: '#communication_website_structure_education_programs_title' } + } %> + <hr class="my-5"> + <%= f.input :research_articles_title %> + <%= f.input :research_articles_description %> + <%= f.input :research_articles_path, + input_html: { + class: 'js-slug-input', + data: { source: '#communication_website_structure_research_articles_title' } + } %> + <hr class="my-5"> + <%= f.input :research_volumes_title %> + <%= f.input :research_volumes_description %> + <%= f.input :research_volumes_path, + input_html: { + class: 'js-slug-input', + data: { source: '#communication_website_structure_research_volumes_title' } + } %> + </div> + </div> + </div> + <div class="col-md-6"> + <div class="card flex-fill w-100"> + <div class="card-body"> + <%= f.input :persons_title %> + <%= f.input :persons_description %> + <%= f.input :persons_path, + input_html: { + class: 'js-slug-input', + data: { source: '#communication_website_structure_persons_title' } + } %> + <hr class="my-5"> + <%= f.input :administrators_title %> + <%= f.input :administrators_description %> + <%= f.input :administrators_path, + input_html: { + class: 'js-slug-input', + data: { source: '#communication_website_structure_administrators_title' } + } %> + <hr class="my-5"> + <%= f.input :authors_title %> + <%= f.input :authors_description %> + <%= f.input :authors_path, + input_html: { + class: 'js-slug-input', + data: { source: '#communication_website_structure_authors_title' } + } %> + <hr class="my-5"> + <%= f.input :researchers_title %> + <%= f.input :researchers_description %> + <%= f.input :researchers_path, + input_html: { + class: 'js-slug-input', + data: { source: '#communication_website_structure_researchers_title' } + } %> + <hr class="my-5"> + <%= f.input :teachers_title %> + <%= f.input :teachers_description %> + <%= f.input :teachers_path, + input_html: { + class: 'js-slug-input', + data: { source: '#communication_website_structure_teachers_title' } + } %> + </div> + </div> + </div> + </div> + <% content_for :action_bar_right do %> + <%= submit f %> + <% end %> + <% end %> +<% end %> diff --git a/app/views/admin/communication/websites/_sidebar.html.erb b/app/views/admin/communication/websites/_sidebar.html.erb index 95a85b6bb1d5b160361fa7f1ef90d3c750353528..e2c09d29dcd7cd1712cc2d8d9256362a4f02ba9a 100644 --- a/app/views/admin/communication/websites/_sidebar.html.erb +++ b/app/views/admin/communication/websites/_sidebar.html.erb @@ -39,6 +39,11 @@ path: admin_communication_website_menus_path(website_id: @website), ability: can?(:read, Communication::Website::Category) }, + { + title: Communication::Website::Structure.model_name.human, + path: admin_communication_website_structure_path(website_id: @website), + ability: can?(:update, Communication::Website::Structure) + }, ].each do |object| next unless object[:ability] active = object[:path].in? request.path diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml index bdcd0d124b2678689ad726953890d4c1c4570941..37c60bb4e08ae543f225dc58b5617a4fc6244fd6 100644 --- a/config/locales/communication/en.yml +++ b/config/locales/communication/en.yml @@ -31,6 +31,8 @@ en: one: Post other: Posts all: All posts + communication/website/structure: + one: Structure attributes: communication/website: about: About @@ -101,6 +103,35 @@ en: text: Text title: Title website: Website + communication/website/structure: + administrators_description: Administrative team - description + administrators_path: Administrative team - url + administrators_title: Administrative team - title + authors_description: Editorial team - description + authors_path: Editorial team - url + authors_title: Editorial team - title + communication_posts_description: News - description + communication_posts_path: News - url + communication_posts_title: News - title + education_programs_description: Programs - description + education_programs_path: Programs - url + education_programs_title: Programs - title + home_title: Home - title + persons_description: Team - description + persons_path: Team - url + persons_title: Team - title + research_articles_description: Research articles - description + research_articles_path: Research articles - url + research_articles_title: Research articles - title + research_volumes_description: Research volumes - description + research_volumes_path: Research volumes - url + research_volumes_title: Research volumes - title + researchers_description: Research team - description + researchers_path: Research team - url + researchers_title: Research team - title + teachers_description: Teachers - description + teachers_path: Teachers - url + teachers_title: Teachers - title communication: authors: one: Author diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index 51336acc4b63e79ec0d2dd50036fc0dd428e9344..cdd30f8c7c65685aed34984a1806198aeac833e2 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -12,7 +12,7 @@ fr: other: Catégories all: Toutes les catégories communication/website/home: - one: Homepage + one: Page d'accueil communication/website/imported/website: one: Site importé other: Sites importés @@ -31,6 +31,8 @@ fr: one: Actualité other: Actualités all: Toutes les actualités + communication/website/structure: + one: Structure attributes: communication/website: about: Sujet du site @@ -101,6 +103,35 @@ fr: text: Texte title: Titre website: Site Web + communication/website/structure: + administrators_description: Équipe administrative - description + administrators_path: Équipe administrative - url + administrators_title: Équipe administrative - titre + authors_description: Équipe éditoriale - description + authors_path: Équipe éditoriale - url + authors_title: Équipe éditoriale - titre + communication_posts_description: Actualités - description + communication_posts_path: Actualités - url + communication_posts_title: Actualités - titre + education_programs_description: Offre de formation - description + education_programs_path: Offre de formation - url + education_programs_title: Offre de formation - titre + home_title: Accueil - titre + persons_description: Équipe - description + persons_path: Équipe - url + persons_title: Équipe - titre + research_articles_description: Articles de recherche - description + research_articles_path: Articles de recherche - url + research_articles_title: Articles de recherche - titre + research_volumes_description: Volumes de recherche - description + research_volumes_path: Volumes de recherche - url + research_volumes_title: Volumes de recherche - titre + researchers_description: Équipe de recherche - description + researchers_path: Équipe de recherche - url + researchers_title: Équipe de recherche - titre + teachers_description: Équipe pédagogique - description + teachers_path: Équipe pédagogique - url + teachers_title: Équipe pédagogique - titre communication: authors: one: Auteur·rice diff --git a/config/routes/admin/communication.rb b/config/routes/admin/communication.rb index ec6dc3e695537e74990146796a5f2891dc0bf66e..1bb626b6e6eebdd5e06392543a8fff59cc061307 100644 --- a/config/routes/admin/communication.rb +++ b/config/routes/admin/communication.rb @@ -43,5 +43,7 @@ namespace :communication do end end end + get 'structure' => 'website/structure#edit' + patch 'structure' => 'website/structure#update' end end diff --git a/db/migrate/20220207134307_create_communication_website_structure.rb b/db/migrate/20220207134307_create_communication_website_structure.rb new file mode 100644 index 0000000000000000000000000000000000000000..ff20756947d665d46cdd1ebe6a5121e19d68e3e0 --- /dev/null +++ b/db/migrate/20220207134307_create_communication_website_structure.rb @@ -0,0 +1,51 @@ +class CreateCommunicationWebsiteStructure < ActiveRecord::Migration[6.1] + def change + create_table :communication_website_structures, id: :uuid do |t| + t.references :university, null: false, foreign_key: true, type: :uuid + t.references :communication_website, + null: false, + foreign_key: { to_table: :communication_websites }, + type: :uuid, + index: { name: 'idx_comm_website_structures_on_communication_website_id' } + + + t.string "persons_title", default: "Équipe" + t.text "persons_description", default: "Liste des membres de l'équipe" + t.string "persons_path", default: "equipe" + + t.string "authors_title", default: "Équipe éditoriale" + t.text "authors_description", default: "Liste des membres de l'équipe éditoriale" + t.string "authors_path", default: "equipe-editoriale" + + t.string "researchers_title", default: "Équipe de recherche" + t.text "researchers_description", default: "Liste des membres de l'équipe de recherche" + t.string "researchers_path", default: "equipe-de-recherche" + + t.string "administrators_title", default: "Équipe administrative" + t.text "administrators_description", default: "Liste des membres de l'équipe administrative" + t.string "administrators_path", default: "equipe-administrative" + + t.string "teachers_title", default: "Équipe pédagogique" + t.text "teachers_description", default: "Liste des membres de l'équipe pédagogique" + t.string "teachers_path", default: "equipe-pedagogique" + + t.string "communication_posts_title", default: "Actualités" + t.text "communication_posts_description", default: "Liste des actualités" + t.string "communication_posts_path", default: "actualites" + + t.string "education_programs_title", default: "L'offre de formation" + t.text "education_programs_description", default: "Liste des formations proposées" + t.string "education_programs_path", default: "offre-de-formation" + + t.string "research_volumes_title", default: "Volumes" + t.text "research_volumes_description", default: "Liste des volumes" + t.string "research_volumes_path", default: "volumes" + + t.string "research_articles_title", default: "Articles" + t.text "research_articles_description", default: "Liste des articles" + t.string "research_articles_path", default: "articles" + + t.timestamps + end + end +end diff --git a/db/migrate/20220207152152_add_home_title_to_communication_website_structure.rb b/db/migrate/20220207152152_add_home_title_to_communication_website_structure.rb new file mode 100644 index 0000000000000000000000000000000000000000..caeb3152c42262e6bbd012a37ab70583ed087327 --- /dev/null +++ b/db/migrate/20220207152152_add_home_title_to_communication_website_structure.rb @@ -0,0 +1,5 @@ +class AddHomeTitleToCommunicationWebsiteStructure < ActiveRecord::Migration[6.1] + def change + add_column :communication_website_structures, :home_title, :string, default: 'Accueil' + end +end diff --git a/db/schema.rb b/db/schema.rb index 6fa4a6e619daf0b0e010e9a61b6ffdab27f367f8..3491f21e87f8873670f070ec5d60c38ef2d5ee72 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: 2022_02_07_093702) do +ActiveRecord::Schema.define(version: 2022_02_07_152152) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -315,6 +315,43 @@ ActiveRecord::Schema.define(version: 2022_02_07_093702) do t.index ["university_id"], name: "index_communication_website_posts_on_university_id" end + create_table "communication_website_structures", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.uuid "university_id", null: false + t.uuid "communication_website_id", null: false + t.string "persons_title", default: "Équipe" + t.text "persons_description", default: "Liste des membres de l'équipe" + t.string "persons_path", default: "equipe" + t.string "authors_title", default: "Équipe éditoriale" + t.text "authors_description", default: "Liste des membres de l'équipe éditoriale" + t.string "authors_path", default: "equipe-editoriale" + t.string "researchers_title", default: "Équipe de recherche" + t.text "researchers_description", default: "Liste des membres de l'équipe de recherche" + t.string "researchers_path", default: "equipe-de-recherche" + t.string "administrators_title", default: "Équipe administrative" + t.text "administrators_description", default: "Liste des membres de l'équipe administrative" + t.string "administrators_path", default: "equipe-administrative" + t.string "teachers_title", default: "Équipe pédagogique" + t.text "teachers_description", default: "Liste des membres de l'équipe pédagogique" + t.string "teachers_path", default: "equipe-pedagogique" + t.string "communication_posts_title", default: "Actualités" + t.text "communication_posts_description", default: "Liste des actualités" + t.string "communication_posts_path", default: "actualites" + t.string "education_programs_title", default: "L'offre de formation" + t.text "education_programs_description", default: "Liste des formations proposées" + t.string "education_programs_path", default: "offre-de-formation" + t.string "research_volumes_title", default: "Volumes" + t.text "research_volumes_description", default: "Liste des volumes" + t.string "research_volumes_path", default: "volumes" + t.string "research_articles_title", default: "Articles" + t.text "research_articles_description", default: "Liste des articles" + t.string "research_articles_path", default: "articles" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.string "home_title", default: "Accueil" + t.index ["communication_website_id"], name: "idx_comm_website_structures_on_communication_website_id" + t.index ["university_id"], name: "index_communication_website_structures_on_university_id" + end + create_table "communication_websites", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.string "name" @@ -655,6 +692,8 @@ ActiveRecord::Schema.define(version: 2022_02_07_093702) do add_foreign_key "communication_website_posts", "communication_websites" add_foreign_key "communication_website_posts", "universities" add_foreign_key "communication_website_posts", "university_people", column: "author_id" + add_foreign_key "communication_website_structures", "communication_websites" + add_foreign_key "communication_website_structures", "universities" add_foreign_key "communication_websites", "universities" add_foreign_key "education_programs", "education_programs", column: "parent_id" add_foreign_key "education_programs", "universities" diff --git a/lib/tasks/app.rake b/lib/tasks/app.rake index 7882b1afab2410acebdea1bb686e865848ba5751..baf1c9b674bc4e613c414b1034b988fb92c7843a 100644 --- a/lib/tasks/app.rake +++ b/lib/tasks/app.rake @@ -40,6 +40,9 @@ namespace :app do imported_post.post&.update_column :published_at, imported_post.published_at end end + + # Website structures + Communication::Website.all.each { |w| w.build_structure(university_id: w.university_id).save } end namespace :db do