diff --git a/app/controllers/admin/communication/website/posts_controller.rb b/app/controllers/admin/communication/website/posts_controller.rb index 1358b60c5cb0026e5fd56c979467d73cabf80fb4..d6a24c155105dfce8795d4b99ea52ce019affb8d 100644 --- a/app/controllers/admin/communication/website/posts_controller.rb +++ b/app/controllers/admin/communication/website/posts_controller.rb @@ -57,6 +57,6 @@ class Admin::Communication::Website::PostsController < Admin::Communication::Web def post_params params.require(:communication_website_post) - .permit(:university_id, :website_id, :title, :description, :text, :published, :published_at, :featured_image, :featured_image_delete, :featured_image_infos, :slug, category_ids: []) + .permit(:university_id, :website_id, :title, :description, :text, :published, :published_at, :featured_image, :featured_image_delete, :featured_image_infos, :slug, :author_id, category_ids: []) end end diff --git a/app/models/communication/website/post.rb b/app/models/communication/website/post.rb index 42fd81f8ca215fd88dbca5788c68ea89b29f1569..83961a465ddaee46e380a34d470cf3dba702a6c7 100644 --- a/app/models/communication/website/post.rb +++ b/app/models/communication/website/post.rb @@ -13,16 +13,19 @@ # title :string # created_at :datetime not null # updated_at :datetime not null +# author_id :uuid # communication_website_id :uuid not null # university_id :uuid not null # # Indexes # +# index_communication_website_posts_on_author_id (author_id) # index_communication_website_posts_on_communication_website_id (communication_website_id) # index_communication_website_posts_on_university_id (university_id) # # Foreign Keys # +# fk_rails_... (author_id => communication_website_authors.id) # fk_rails_... (communication_website_id => communication_websites.id) # fk_rails_... (university_id => universities.id) # @@ -36,6 +39,9 @@ class Communication::Website::Post < ApplicationRecord belongs_to :university belongs_to :website, foreign_key: :communication_website_id + belongs_to :author, + class_name: 'Communication::Website::Author', + optional: true has_and_belongs_to_many :categories, class_name: 'Communication::Website::Category', join_table: 'communication_website_categories_posts', diff --git a/app/views/admin/communication/website/authors/show.html.erb b/app/views/admin/communication/website/authors/show.html.erb index c8e0111b591aac98f624a4d1b90d54ed150d455c..def927cf92627bab4c45c6ceb5fad50ea258a8e1 100644 --- a/app/views/admin/communication/website/authors/show.html.erb +++ b/app/views/admin/communication/website/authors/show.html.erb @@ -11,7 +11,7 @@ <p> <strong><%= Communication::Website::Author.human_attribute_name('biography') %></strong> </p> - <%= sanitize @author.biography %> + <%= @author.biography %> </div> </div> </div> diff --git a/app/views/admin/communication/website/posts/_form.html.erb b/app/views/admin/communication/website/posts/_form.html.erb index 46666ac9640ecfcbd65b3858b143b0e1b033c7b7..e221e8ec4d8b3cd32ce7d5d8bac0bc7160ae4faa 100644 --- a/app/views/admin/communication/website/posts/_form.html.erb +++ b/app/views/admin/communication/website/posts/_form.html.erb @@ -21,6 +21,7 @@ <%= f.input :slug, as: :string if post.persisted? %> <%= f.input :published %> <%= f.input :published_at, html5: true %> + <%= f.association :author, collection: @website.authors.ordered if @website.authors.any? %> <%= f.association :categories, as: :check_boxes if @website.categories.any? %> </div> </div> diff --git a/app/views/admin/communication/website/posts/show.html.erb b/app/views/admin/communication/website/posts/show.html.erb index 2a95763dd05bd20a4a513c76a79e0298a8f1e4c6..54c7a4d3ac5c0bf3a0c72f74b2c5060593cc10e5 100644 --- a/app/views/admin/communication/website/posts/show.html.erb +++ b/app/views/admin/communication/website/posts/show.html.erb @@ -25,6 +25,12 @@ </div> <table class="<%= table_classes %>"> <tbody> + <% if @post.author %> + <tr> + <td width="150"><%= Communication::Website::Post.human_attribute_name('author') %></td> + <td><%= link_to_if can?(:read, @post.author), @post.author, admin_communication_website_author_path(@post.author) %></td> + </tr> + <% end %> <tr> <td width="150"><%= Communication::Website::Post.human_attribute_name('slug') %></td> <td><%= @post.slug %></td> diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index 0febf9dec2b4cb9874bff11319b20a3859c6e219..7123f10954e1b58edc40f5da46a980c5ae5ce5ea 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -26,8 +26,8 @@ fr: one: Site Web other: Sites Web communication/website/author: - one: Auteur - other: Auteurs + one: Auteur·rice + other: Auteur·rice·s communication/website/category: one: Catégorie other: Catégories diff --git a/config/locales/fr.yml b/config/locales/fr.yml index b34e7ed94917978403c2992c53e18273f70f1a20..fb5fca43c2ad00c3d20d1d406f2a30ff38606f7b 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -34,8 +34,8 @@ fr: one: Université other: Universités user: - one: Utilisateur - other: Utilisateurs + one: Utilisateur·rice + other: Utilisateur·rice·s admin: attachment_not_available: Impossible d'accéder à l'élément dashboard: Tableau de bord diff --git a/db/migrate/20211028100510_add_author_to_communication_website_post.rb b/db/migrate/20211028100510_add_author_to_communication_website_post.rb new file mode 100644 index 0000000000000000000000000000000000000000..085d9d2a65a58281380f63325aece5342cba0e7b --- /dev/null +++ b/db/migrate/20211028100510_add_author_to_communication_website_post.rb @@ -0,0 +1,6 @@ +class AddAuthorToCommunicationWebsitePost < ActiveRecord::Migration[6.1] + def change + add_reference :communication_website_posts, :author, foreign_key: { to_table: :communication_website_authors }, type: :uuid + + end +end diff --git a/db/schema.rb b/db/schema.rb index 880bc77579e3acbb8e1e5539191cb648f309bc01..cce82cf826694bdebd305f8f5de3e2200925c781 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_10_28_090402) do +ActiveRecord::Schema.define(version: 2021_10_28_100510) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -239,6 +239,8 @@ ActiveRecord::Schema.define(version: 2021_10_28_090402) do t.text "slug" t.text "path" t.text "github_path" + t.uuid "author_id" + t.index ["author_id"], name: "index_communication_website_posts_on_author_id" t.index ["communication_website_id"], name: "index_communication_website_posts_on_communication_website_id" t.index ["university_id"], name: "index_communication_website_posts_on_university_id" end @@ -464,6 +466,7 @@ ActiveRecord::Schema.define(version: 2021_10_28_090402) do add_foreign_key "communication_website_pages", "communication_website_pages", column: "parent_id" add_foreign_key "communication_website_pages", "communication_websites" add_foreign_key "communication_website_pages", "universities" + add_foreign_key "communication_website_posts", "communication_website_authors", column: "author_id" add_foreign_key "communication_website_posts", "communication_websites" add_foreign_key "communication_website_posts", "universities" add_foreign_key "communication_websites", "universities"