diff --git a/app/controllers/admin/communication/website/posts_controller.rb b/app/controllers/admin/communication/website/posts_controller.rb index f9d074f007b6d1e127660e85fab7984400ee1115..2c515e621523a213fa4cf4cece6a196481fed6ec 100644 --- a/app/controllers/admin/communication/website/posts_controller.rb +++ b/app/controllers/admin/communication/website/posts_controller.rb @@ -12,6 +12,7 @@ class Admin::Communication::Website::PostsController < Admin::Communication::Web def new @post.website = @website + @post.author_id = current_user.person&.id breadcrumb end diff --git a/app/models/ability.rb b/app/models/ability.rb index 1aaad8c6c88e82b40d6cb44c6c9a345dadfe18a1..643651eb8a158dceea2e76a56f473c5fa8444739 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -30,6 +30,19 @@ class Ability can :read, Communication::Block, university_id: @user.university_id end + def contributor + managed_websites_ids = @user.websites_to_manage.pluck(:communication_website_id) + can :read, Communication::Website, university_id: @user.university_id, id: managed_websites_ids + can :manage, Communication::Website::Post, university_id: @user.university_id, communication_website_id: managed_websites_ids, author_id: @user.person&.id + cannot :publish, Communication::Website::Post + end + + def author + managed_websites_ids = @user.websites_to_manage.pluck(:communication_website_id) + can :read, Communication::Website, university_id: @user.university_id, id: managed_websites_ids + can :manage, Communication::Website::Post, university_id: @user.university_id, communication_website_id: managed_websites_ids, author_id: @user.person&.id + end + def teacher can :manage, University::Person, user_id: @user.id cannot :create, University::Person diff --git a/app/models/user/with_roles.rb b/app/models/user/with_roles.rb index d4c44a698838bf3c44b776ac95bb1e68663401e6..bd1ef525c6855098e33165289fe5546817a311dc 100644 --- a/app/models/user/with_roles.rb +++ b/app/models/user/with_roles.rb @@ -4,7 +4,7 @@ module User::WithRoles included do attr_accessor :modified_by - enum role: { visitor: 0, teacher: 10, program_manager: 12, website_manager: 15, admin: 20, server_admin: 30 } + enum role: { visitor: 0, contributor: 4, author: 5, teacher: 10, program_manager: 12, website_manager: 15, admin: 20, server_admin: 30 } has_and_belongs_to_many :programs_to_manage, class_name: 'Education::Program', @@ -22,7 +22,7 @@ module User::WithRoles before_validation :check_modifier_role def self.roles_with_access_to_global_menu - roles.keys - ["website_manager"] + roles.keys - ['contributor', 'author', 'website_manager'] end def managed_roles diff --git a/app/views/admin/communication/website/posts/_form.html.erb b/app/views/admin/communication/website/posts/_form.html.erb index 32ffdeb4543b4dca0ebb82ff8efb1092f74fcfc0..711e59170816faf4cf6451a67b2a07468456eb87 100644 --- a/app/views/admin/communication/website/posts/_form.html.erb +++ b/app/views/admin/communication/website/posts/_form.html.erb @@ -29,10 +29,16 @@ <% elsif @website.languages.any? %> <%= f.input :language_id, as: :hidden, input_html: { value: @website.languages.first.id }, wrapper: false %> <% end %> - <%= f.input :published %> - <%= f.input :published_at, html5: true %> + <% if can? :publish, post %> + <%= f.input :published %> + <%= f.input :published_at, html5: true %> + <% end %> <%= f.input :pinned %> - <%= f.association :author, collection: current_university.people.ordered %> + <% if current_user.author? || current_user.contributor? %> + <%= f.input :author_id, as: :hidden, input_html: { value: current_user.person&.id }, wrapper: false %> + <% else %> + <%= f.association :author, collection: current_university.people.ordered %> + <% end %> </div> </div> <div class="card flex-fill w-100"> diff --git a/app/views/admin/communication/websites/index.html.erb b/app/views/admin/communication/websites/index.html.erb index b4ebe5d3fca6bd2f4b51d1d6521c6ba2ad9c4dd0..a4b8e7879ad34aafd194cf122331daf8d6595a95 100644 --- a/app/views/admin/communication/websites/index.html.erb +++ b/app/views/admin/communication/websites/index.html.erb @@ -16,7 +16,7 @@ <td><%= link_to website, [:admin, website] %></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><%= link_to_if can?(:read, website.about), website.about, [:admin, website.about] if website.about %></td> <td class="text-end"> <div class="btn-group" role="group"> <%= edit_link website %> diff --git a/app/views/admin/communication/websites/show.html.erb b/app/views/admin/communication/websites/show.html.erb index 5057c724143e0766d113becb013237861bc4dbdc..89747b56bdd697807c6271e9d0733543232323a1 100644 --- a/app/views/admin/communication/websites/show.html.erb +++ b/app/views/admin/communication/websites/show.html.erb @@ -6,7 +6,7 @@ <% end %> <%= I18n.t("activerecord.attributes.communication/website.about_#{@website.about_type}") %> <% if @website.about %> - (<%= link_to @website.about, [:admin, @website.about] unless @website.about.nil? %>) + (<%= link_to_if can?(:read, @website.about), @website.about, [:admin, @website.about] unless @website.about.nil? %>) <% end %> <% end %> diff --git a/app/views/admin/users/_form.html.erb b/app/views/admin/users/_form.html.erb index 6a025d1642892f9c768bfd832951d3f08ad7a777..c2e732e90cea492564749b7fff0bedbecb807356 100644 --- a/app/views/admin/users/_form.html.erb +++ b/app/views/admin/users/_form.html.erb @@ -37,7 +37,7 @@ label_method: ->(p) { sanitize p[:label] }, value_method: ->(p) { p[:id] } %> </div> - <div data-show-for-roles="website_manager"> + <div data-show-for-roles="author,contributor,website_manager"> <%= f.association :websites_to_manage, as: :check_boxes, collection: current_university.communication_websites.ordered diff --git a/config/admin_navigation.rb b/config/admin_navigation.rb index b2d084377f0c423b281c766a43c531a1d87449ed..4fccef35596f4b3505cad976350d55b20d6c6fdd 100644 --- a/config/admin_navigation.rb +++ b/config/admin_navigation.rb @@ -34,7 +34,7 @@ SimpleNavigation::Configuration.run do |navigation| if can?(:read, Communication::Website) primary.item :communication, Communication.model_name.human, nil, { kind: :header } primary.item :communication_websites, Communication::Website.model_name.human(count: 2), admin_communication_websites_path, { icon: 'sitemap' } if can?(:read, Communication::Website) - primary.item :communication_extranets, Communication::Extranet.model_name.human(count: 2), admin_communication_extranets_path, { icon: 'project-diagram' } + primary.item :communication_extranets, Communication::Extranet.model_name.human(count: 2), admin_communication_extranets_path, { icon: 'project-diagram' } if can?(:read, Communication::Extranet) primary.item :communication_newsletters, 'Lettres d\'information', nil, { icon: 'envelope' } end diff --git a/config/locales/en.yml b/config/locales/en.yml index a07167520f99ab724299d056b8e36c63660e76e4..49586fa67c5b553e343b068df01bb7d30bb144ed 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -16,11 +16,14 @@ en: role: Role roles: admin: Administrator + author: Author + contributor: Contributor program_manager: Program manager server_admin: Server admin teacher: Teacher visitor: Visitor website_manager: Website manager + websites_to_manage: Websites managed errors: models: user: diff --git a/config/locales/fr.yml b/config/locales/fr.yml index cfb4f9c6e825a5e1a49203a8d982ad65e2e16602..2963ff7588bcd53d3ef6666f8267e72bb08564de 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -16,11 +16,14 @@ fr: role: Rôle roles: admin: Administrateur + author: Auteur + contributor: Contributeur program_manager: Responsable de formation server_admin: Administrateur du serveur teacher: Enseignant·e visitor: Visiteur website_manager: Responsable de site web + websites_to_manage: Sites gérés errors: models: user: