diff --git a/app/models/ability.rb b/app/models/ability.rb index 488d9fb67168192e6ba9ce02ce0ab7bc6714b453..a89951285f9a4c09f9ec4b8b35867ffd39aca83b 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -34,6 +34,9 @@ class Ability can :read, Communication::Website, university_id: @user.university_id can :manage, Communication::Website::Page, university_id: @user.university_id can :manage, Communication::Website::Post, university_id: @user.university_id + can :manage, Communication::Website::Category, 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 can :manage, Communication::Website::Imported::Page, university_id: @user.university_id can :manage, Communication::Website::Imported::Post, university_id: @user.university_id diff --git a/app/models/communication/website.rb b/app/models/communication/website.rb index e809d9aeaef99120931cc867471b04fd461cea35..6292e2dc63d223b707b5a26022c7342590f2511a 100644 --- a/app/models/communication/website.rb +++ b/app/models/communication/website.rb @@ -73,6 +73,14 @@ class Communication::Website < ApplicationRecord !imported_website.nil? end + def list_of_pages + all_pages = [] + pages.where.not(id: id).root.ordered.each do |page| + all_pages.concat(page.self_and_children(0)) + end + all_pages + end + def to_s "#{name}" end diff --git a/app/models/communication/website/menu/item.rb b/app/models/communication/website/menu/item.rb index c5cbb1993e917e94d77d381bc0de7fdbec4556c2..d5e7beaf1a84e115cea5adf8d6c6b4b6fb10bdec 100644 --- a/app/models/communication/website/menu/item.rb +++ b/app/models/communication/website/menu/item.rb @@ -44,7 +44,7 @@ class Communication::Website::Menu::Item < ApplicationRecord foreign_key: :parent_id, dependent: :destroy - enum kind: { url: 0, page: 1, blank: 2 }, _prefix: :kind + enum kind: { blank: 0, url: 10, page: 20 }, _prefix: :kind validates :title, presence: true diff --git a/app/models/communication/website/page.rb b/app/models/communication/website/page.rb index e2b54c01669be38d13841b96ff47af6e301e01b8..3225309b36e67ab1a7e1344d2cedec67a76839d0 100644 --- a/app/models/communication/website/page.rb +++ b/app/models/communication/website/page.rb @@ -74,12 +74,7 @@ class Communication::Website::Page < ApplicationRecord end def list_of_other_pages - pages = [] - website.pages.where.not(id: id).root.ordered.each do |page| - pages.concat(page.self_and_children(0)) - end - pages.reject! { |p| p[:id] == id } - pages + website.list_of_pages.reject! { |p| p[:id] == id } end def to_s diff --git a/app/views/admin/communication/website/categories/_list.html.erb b/app/views/admin/communication/website/categories/_list.html.erb index 6b0f36e715a7d3d4196e24c86203887c3bcc68ef..af55dc0c97b4a5dc40501970d89356d37fe70685 100644 --- a/app/views/admin/communication/website/categories/_list.html.erb +++ b/app/views/admin/communication/website/categories/_list.html.erb @@ -13,12 +13,12 @@ <div class="btn-group" role="group"> <%= link_to t('edit'), edit_admin_communication_website_category_path(website_id: category.website.id, id: category.id), - class: button_classes %> + class: button_classes if can?(:update, category) %> <%= link_to t('delete'), admin_communication_website_category_path(website_id: category.website.id, id: category.id), method: :delete, data: { confirm: t('please-confirm') }, - class: button_classes_danger %> + class: button_classes_danger if can?(:destroy, category) %> </div> </td> </tr> diff --git a/app/views/admin/communication/website/menu/items/_form.html.erb b/app/views/admin/communication/website/menu/items/_form.html.erb index e9e97c9f2bca092061a3656e69d1a5c40b88b6ee..07bc0ba37bf007e1ac9b8a04c349847dff78506c 100644 --- a/app/views/admin/communication/website/menu/items/_form.html.erb +++ b/app/views/admin/communication/website/menu/items/_form.html.erb @@ -17,7 +17,7 @@ </div> <div class="kind-page"> <%= f.input :about_type, as: :hidden, input_html: { value: 'Communication::Website::Page' } %> - <%= f.association :about, collection: @website.pages.ordered %> + <%= f.association :about, collection: @website.list_of_pages, label_method: ->(p) { sanitize p[:label] }, value_method: ->(p) { p[:id] } %> </div> </div> </div> diff --git a/app/views/admin/communication/website/menu/items/_list.html.erb b/app/views/admin/communication/website/menu/items/_list.html.erb index 2748726749d71901d6af3f09385a5f0d879ba357..1eb95329f96db3feaa33a28ee1d27b9c5cfaab6d 100644 --- a/app/views/admin/communication/website/menu/items/_list.html.erb +++ b/app/views/admin/communication/website/menu/items/_list.html.erb @@ -1,5 +1,5 @@ <% item ||= nil %> -<ul class="list-unstyled treeview treeview--sortable js-treeview js-treeview-sortable js-treeview-sortable-container" +<ul class="list-unstyled treeview js-treeview <%= 'treeview--sortable js-treeview-sortable js-treeview-sortable-container' if can?(:reorder, item) %>" data-id="<%= item&.id %>" data-sort-url="<%= reorder_admin_communication_website_menu_items_path(@menu) %>"> <%= render 'admin/communication/website/menu/items/treebranch', items: items %> diff --git a/app/views/admin/communication/website/menu/items/_treebranch.html.erb b/app/views/admin/communication/website/menu/items/_treebranch.html.erb index f224ceb44229ab1d08d7214d7687e748387bdcd8..2423ee9bd7afa3e9effd4bd506252c34964fe406 100644 --- a/app/views/admin/communication/website/menu/items/_treebranch.html.erb +++ b/app/views/admin/communication/website/menu/items/_treebranch.html.erb @@ -13,8 +13,9 @@ <i class="close_btn--without_children far fa-folder-open"></i> </span> <% end %> - <%= link_to item, admin_communication_website_menu_item_path(website_id: item.website.id, menu_id: item.menu.id, id: item.id) %> + <%= link_to_if can?(:read, item), item, admin_communication_website_menu_item_path(website_id: item.website.id, menu_id: item.menu.id, id: item.id) %> <span class="move_btn py-2 ps-2"><i class="fas fa-sort"></i></span> + <%= link_to t('edit'), edit_admin_communication_website_menu_item_path(website_id: item.website.id, menu_id: item.menu.id, id: item.id), class: "#{button_classes} ms-auto" if can?(:edit, item) %> </div> <ul class="list-unstyled treeview__children js-treeview-children js-treeview-sortable-container ms-4" data-id="<%= item.id %>"> <li class="treeview__empty"> diff --git a/app/views/admin/communication/website/menu/items/show.html.erb b/app/views/admin/communication/website/menu/items/show.html.erb index 36ec9d431c2ca6ecbf806cf9481e24428dd54abb..e8a5cd2217f0e0fd701a7cd4b081979ab8cc95f1 100644 --- a/app/views/admin/communication/website/menu/items/show.html.erb +++ b/app/views/admin/communication/website/menu/items/show.html.erb @@ -1,10 +1,23 @@ <% content_for :title, @item %> <div class="row"> - <div class="col-md-6"> + <div class="col-md-8"> <div class="card flex-fill w-100"> <div class="card-header"> - <h5 class="card-title mb-0"><%= t('metadata') %></h5> + <h2 class="card-title mb-2 h5"> + <%= "#{Communication::Website::Menu::Item.human_attribute_name('children')} (#{@children.size})" %> + </h2> + <%= render 'admin/communication/website/menu/items/list', items: @children, item: @item if @children.any? %> + <%= link_to t('create'), + new_admin_communication_website_menu_item_path(website_id: @website, menu_id: @menu.id, parent_id: @item.id), + class: button_classes if can?(:create, Communication::Website::Menu::Item) %> + </div> + </div> + </div> + <div class="col-md-4"> + <div class="card flex-fill w-100"> + <div class="card-header"> + <h2 class="card-title mb-0 h5"><%= t('metadata') %></h2> </div> <table class="<%= table_classes %>"> <tbody> @@ -15,9 +28,9 @@ <% if @item.kind_url? %> <tr> <td width="150"><%= Communication::Website::Menu::Item.human_attribute_name('url') %></td> - <td><%= link_to @item.url, @item.url, target: :blank unless @item.url.blank? %></td> + <td><%= link_to @item.url, @item.url, target: '_blank' unless @item.url.blank? %></td> </tr> - <% else %> + <% elsif @item.kind_page? %> <tr> <td width="150"><%= Communication::Website::Menu::Item.human_attribute_name('about') %></td> <td><%= link_to_if can?(:read, @item.about), @item.about, [:admin, @item.about] %></td> @@ -29,13 +42,6 @@ </div> </div> -<h2><%= "#{Communication::Website::Menu::Item.model_name.human(count: 2)} (#{@children.size})" %></h2> -<%= link_to t('create'), - new_admin_communication_website_menu_item_path(website_id: @website, menu_id: @menu.id, parent_id: @item.id), - class: button_classes %> - -<%= render 'admin/communication/website/menu/items/list', items: @children, item: @item if @children.any? %> - <% content_for :action_bar_right do %> <%= link_to t('edit'), edit_admin_communication_website_menu_item_path(@item, website_id: @website, menu_id: @menu.id), diff --git a/app/views/admin/communication/website/menus/_form.html.erb b/app/views/admin/communication/website/menus/_form.html.erb index 8ed7f7e9ed57a8ba2c6d5a478a94ee2d6df2867a..d8e33611a93ff28c4e78edaeefaeb294032766d2 100644 --- a/app/views/admin/communication/website/menus/_form.html.erb +++ b/app/views/admin/communication/website/menus/_form.html.erb @@ -16,7 +16,7 @@ <h5 class="card-title mb-0"><%= t('metadata') %></h5> </div> <div class="card-body"> - <%= f.input :identifier %> + <%= f.input :identifier if can?(:create, menu) %> </div> </div> </div> diff --git a/app/views/admin/communication/website/menus/_list.html.erb b/app/views/admin/communication/website/menus/_list.html.erb index da777e73a25523ec3a06306e721856c8d1be2e8d..139c6472abf20be83aac482da35a38995ba2bb0c 100644 --- a/app/views/admin/communication/website/menus/_list.html.erb +++ b/app/views/admin/communication/website/menus/_list.html.erb @@ -13,12 +13,12 @@ <div class="btn-group" role="group"> <%= link_to t('edit'), edit_admin_communication_website_menu_path(website_id: menu.website.id, id: menu.id), - class: button_classes %> + class: button_classes if can?(:update, menu) %> <%= link_to t('delete'), admin_communication_website_menu_path(website_id: menu.website.id, id: menu.id), method: :delete, data: { confirm: t('please-confirm') }, - class: button_classes_danger %> + class: button_classes_danger if can?(:destroy, menu) %> </div> </td> </tr> diff --git a/app/views/admin/communication/website/menus/show.html.erb b/app/views/admin/communication/website/menus/show.html.erb index 19afc03b12860f48748e253eab0dd2fb9a1c5de7..e933c13f543c1a9819b915fd50249c6a1072b654 100644 --- a/app/views/admin/communication/website/menus/show.html.erb +++ b/app/views/admin/communication/website/menus/show.html.erb @@ -1,10 +1,23 @@ <% content_for :title, @menu %> <div class="row"> - <div class="col-md-6"> + <div class="col-md-8"> <div class="card flex-fill w-100"> <div class="card-header"> - <h5 class="card-title mb-0"><%= t('metadata') %></h5> + <h2 class="card-title mb-2 h5"> + <%= "#{Communication::Website::Menu::Item.model_name.human(count: 2)} (#{@items.size})" %> + </h2> + <%= render 'admin/communication/website/menu/items/list', items: @root_items if @items.any? %> + <%= link_to t('create'), + new_admin_communication_website_menu_item_path(website_id: @website, menu_id: @menu.id), + class: button_classes if can?(:create, Communication::Website::Menu::Item) %> + </div> + </div> + </div> + <div class="col-md-4"> + <div class="card flex-fill w-100"> + <div class="card-header"> + <h2 class="card-title mb-0 h5"><%= t('metadata') %></h2> </div> <table class="<%= table_classes %>"> <tbody> @@ -18,13 +31,6 @@ </div> </div> -<h2><%= "#{Communication::Website::Menu::Item.model_name.human(count: 2)} (#{@items.size})" %></h2> -<%= link_to t('create'), - new_admin_communication_website_menu_item_path(website_id: @website, menu_id: @menu.id), - class: button_classes %> - -<%= render 'admin/communication/website/menu/items/list', items: @root_items if @items.any? %> - <% content_for :action_bar_right do %> <%= edit_link @menu %> <% end %> diff --git a/app/views/admin/communication/website/pages/_list.html.erb b/app/views/admin/communication/website/pages/_list.html.erb index 066342f1b48d52bacdfd94a2a3e1b59578baa372..1a4f7097251b8416781593e22c213634afef1555 100644 --- a/app/views/admin/communication/website/pages/_list.html.erb +++ b/app/views/admin/communication/website/pages/_list.html.erb @@ -13,12 +13,12 @@ <div class="btn-group" role="group"> <%= link_to t('edit'), edit_admin_communication_website_page_path(website_id: page.website.id, id: page.id), - class: button_classes %> + class: button_classes if can?(:update, page) %> <%= link_to t('delete'), admin_communication_website_page_path(website_id: page.website.id, id: page.id), method: :delete, data: { confirm: t('please-confirm') }, - class: button_classes_danger %> + class: button_classes_danger if can?(:destroy, page) %> </div> </td> </tr> diff --git a/app/views/admin/communication/website/posts/_list.html.erb b/app/views/admin/communication/website/posts/_list.html.erb index 3e7c9ce6706e76a37ed872e502fb5bcc57b2c49f..47bd51ed30d6976a2ea9478532d83bf72e40dc2c 100644 --- a/app/views/admin/communication/website/posts/_list.html.erb +++ b/app/views/admin/communication/website/posts/_list.html.erb @@ -40,12 +40,12 @@ <div class="btn-group" role="group"> <%= link_to t('edit'), edit_admin_communication_website_post_path(website_id: post.website.id, id: post.id), - class: button_classes %> + class: button_classes if can?(:update, post) %> <%= link_to t('delete'), admin_communication_website_post_path(website_id: post.website.id, id: post.id), method: :delete, data: { confirm: t('please-confirm') }, - class: button_classes_danger %> + class: button_classes_danger if can?(:destroy, post) %> </div> </td> </tr> diff --git a/app/views/admin/communication/websites/show.html.erb b/app/views/admin/communication/websites/show.html.erb index 20a6e0316abd9a09aea35655a003ec265df61d72..061a6e3daff83dfbf6c8c03fdb16bf7e98fcde45 100644 --- a/app/views/admin/communication/websites/show.html.erb +++ b/app/views/admin/communication/websites/show.html.erb @@ -13,10 +13,9 @@ <div class="card mt-5"> <div class="card-header"> <div class="float-end"> - <%= link_to_if can?(:create, Communication::Website::Post), - t('create'), + <%= link_to t('create'), new_admin_communication_website_post_path(website_id: @website), - class: button_classes %> + class: button_classes if can?(:create, Communication::Website::Post) %> </div> <h2 class="card-title"> <%= link_to admin_communication_website_posts_path(website_id: @website) do %> @@ -36,7 +35,7 @@ <div class="float-end"> <%= link_to t('create'), new_admin_communication_website_page_path(website_id: @website), - class: button_classes %> + class: button_classes if can?(:create, Communication::Website::Page) %> </div> <h2 class="card-title"> <%= link_to admin_communication_website_pages_path(website_id: @website) do %> @@ -58,7 +57,7 @@ <div class="float-end"> <%= link_to t('create'), new_admin_communication_website_category_path(website_id: @website), - class: button_classes %> + class: button_classes if can?(:create, Communication::Website::Category) %> </div> <h2 class="card-title"> <%= link_to admin_communication_website_categories_path(website_id: @website) do %> @@ -79,7 +78,7 @@ <div class="float-end"> <%= link_to t('create'), new_admin_communication_website_menu_path(website_id: @website), - class: button_classes %> + class: button_classes if can?(:create, Communication::Website::Menu) %> </div> <h2 class="card-title"> <%= link_to admin_communication_website_menus_path(website_id: @website) do %> diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml index e4a1070ede02171e24f1fa329bfe686e43d5eae8..8e4ad0baa28fb133c64f7ea02385eb05dc5bbc71 100644 --- a/config/locales/communication/en.yml +++ b/config/locales/communication/en.yml @@ -78,6 +78,7 @@ en: title: Title communication/website/menu/item: about: Target + children: Children items kind: Kind parent: Parent item title: Title @@ -107,7 +108,7 @@ en: enums: communication/website/menu/item: kind: - blank: Blank + blank: Title page: Page url: URL simple_form: diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index d27bd0eb48fbb8780d1b936f12e10b832a281c95..197557fd7fc2f6df686fe39284eabe8cf8b80532 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -78,6 +78,7 @@ fr: title: Titre communication/website/menu/item: about: Cible + children: Sous-éléments kind: Type parent: Élément parent title: Titre @@ -107,7 +108,7 @@ fr: enums: communication/website/menu/item: kind: - blank: Vide + blank: Titre intermédiaire page: Page url: URL simple_form: