Skip to content
Snippets Groups Projects
Commit 010f31a1 authored by pabois's avatar pabois
Browse files

close #263

parent 705e7310
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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
......
......@@ -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',
......
......@@ -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">
......
......@@ -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 %>
......
......@@ -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 %>
......
......@@ -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
......
......@@ -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:
......
......@@ -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:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment