diff --git a/app/controllers/admin/education/program/role/people_controller.rb b/app/controllers/admin/education/program/role/people_controller.rb index 6202bf3e80f4bf070433fb13bcb5163d4688596b..bf9002f61b718b77f33eaf9f5d43a5b370e26624 100644 --- a/app/controllers/admin/education/program/role/people_controller.rb +++ b/app/controllers/admin/education/program/role/people_controller.rb @@ -2,7 +2,9 @@ class Admin::Education::Program::Role::PeopleController < Admin::Education::Prog load_and_authorize_resource :role, class: Education::Program::Role, through: :program load_and_authorize_resource class: Education::Program::Role::Person, through: :role - include Admin::Reorderable + before_action :get_available_people, except: :destroy + + include Admin::Reorderable def new breadcrumb @@ -24,6 +26,11 @@ class Admin::Education::Program::Role::PeopleController < Admin::Education::Prog protected + def get_available_people + used_person_ids = @role.people.where.not(id: @person.id).pluck(:person_id) + @available_people = current_university.people.where.not(id: used_person_ids).accessible_by(current_ability).ordered + end + def breadcrumb super add_breadcrumb Education::Program::Role.model_name.human(count: 2) diff --git a/app/controllers/admin/education/program/teachers_controller.rb b/app/controllers/admin/education/program/teachers_controller.rb index ab3cb3f3eed5e2f491c51c673fd6cfd39c902940..52d7085d53b763e28311db97fbfe040db9a152cc 100644 --- a/app/controllers/admin/education/program/teachers_controller.rb +++ b/app/controllers/admin/education/program/teachers_controller.rb @@ -1,6 +1,8 @@ class Admin::Education::Program::TeachersController < Admin::Education::Program::ApplicationController load_and_authorize_resource class: Education::Program::Teacher, through: :program + before_action :get_teachers, except: :destroy + def new breadcrumb end @@ -36,6 +38,11 @@ class Admin::Education::Program::TeachersController < Admin::Education::Program: protected + def get_teachers + used_teacher_ids = @program.teachers.where.not(id: @teacher.id).pluck(:person_id) + @teachers = current_university.people.teachers.where.not(id: used_teacher_ids).accessible_by(current_ability).ordered + end + def breadcrumb super add_breadcrumb Education::Program::Teacher.model_name.human(count: 2) diff --git a/app/helpers/admin/application_helper.rb b/app/helpers/admin/application_helper.rb index 91f5526ed5ad01a928e9abddfc2dac25a2465ae8..b73956e656435e2ed339848b0bd4ed8372057ad5 100644 --- a/app/helpers/admin/application_helper.rb +++ b/app/helpers/admin/application_helper.rb @@ -60,9 +60,8 @@ module Admin::ApplicationHelper form: form.options.dig(:html, :id) end - def prepare_for_github(html, university) + def prepare_html_for_static(html, university) text = html.to_s - text = sanitize text, tags: %w(table figure figcaption strong em b i u p code pre tt samp kbd var sub sup dfn cite big small address hr br span h1 h2 h3 h4 h5 h6 ul ol li dl dt dd abbr acronym a img blockquote del ins), attributes: %w(rel href src srcset width height alt cite datetime title class name xml:lang abbr style target) @@ -72,6 +71,15 @@ module Admin::ApplicationHelper sanitize text end + def prepare_text_for_static(text) + # Beware, it works only at level one, with 2 spaces + indentation = ' ' + text = strip_tags text.to_s + text.gsub! "\r\n", "\n" # Remove useless \r + text.gsub! "\n", "\n#{indentation}" # Indent properly to avoid broken frontmatter + text.chomp + end + def collection_tree(list, except = nil) collection = [] list.root.ordered.each do |object| diff --git a/app/models/ability.rb b/app/models/ability.rb index 63cb0f45470d8967614809321d9e345e12ea2a3d..5829446e32b2bd938a56afeac09db7374d86f5c3 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -29,6 +29,18 @@ class Ability can :read, User, university_id: @user.university_id end + def teacher + can :manage, University::Person, user_id: @user.id + can :read, Education::Program, university_id: @user.university_id + can :manage, Education::Program::Teacher, person_id: @user.person&.id + can :read, Education::Program::Role, university_id: @user.university_id + can :manage, Education::Program::Role::Person, person_id: @user.person&.id + end + + def program_manager + + end + def admin can :read, Administration::Qualiopi::Criterion can :read, Administration::Qualiopi::Indicator @@ -44,6 +56,8 @@ class Ability can :manage, Communication::Website::Imported::Page, university_id: @user.university_id can :manage, Communication::Website::Imported::Post, university_id: @user.university_id can :manage, Education::Program, university_id: @user.university_id + can :manage, Education::Program::Role, university_id: @user.university_id + can :manage, Education::Program::Role::Person, university_id: @user.university_id can :manage, Research::Journal, university_id: @user.university_id can :manage, Research::Journal::Article, university_id: @user.university_id can :manage, Research::Journal::Volume, university_id: @user.university_id diff --git a/app/models/user/with_roles.rb b/app/models/user/with_roles.rb index 2853b84432441b8b2156e8447d0cf11dc03df2c6..84fb51a7d8304eb19685f7a6aebcbe78ab525e5c 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, admin: 20, server_admin: 30 } + enum role: { visitor: 0, teacher: 10, program_manager: 12, admin: 20, server_admin: 30 } scope :for_role, -> (role) { where(role: role) } diff --git a/app/views/admin/communication/website/categories/static.html.erb b/app/views/admin/communication/website/categories/static.html.erb index 9fe83ce6e974c099cfcef92959d5afff137c2aa0..88af1c3f3cf8adfd48978219c885024847cbb165 100644 --- a/app/views/admin/communication/website/categories/static.html.erb +++ b/app/views/admin/communication/website/categories/static.html.erb @@ -3,4 +3,4 @@ title: "<%= @category.name %>" slug: "<%= @category.slug %>" position: <%= @category.position %> --- -<%= prepare_for_github @category.description, @category.university %> +<%= prepare_html_for_static @category.description, @category.university %> diff --git a/app/views/admin/communication/website/homes/static.html.erb b/app/views/admin/communication/website/homes/static.html.erb index 61c67859ea9be2c07f951298a0e956f06e574009..40827fb2652597d30f61c2bd7e2e5d25ac228efa 100644 --- a/app/views/admin/communication/website/homes/static.html.erb +++ b/app/views/admin/communication/website/homes/static.html.erb @@ -7,6 +7,6 @@ image: "<%= @home.featured_image.blob.id %>" image_alt: "<%= @home.featured_image_alt %>" <% end %> description: > - <%= strip_tags(@home.text.to_s).chomp %> + <%= prepare_text_for_static @home.text %> --- -<%= prepare_for_github @home.text, @home.university %> +<%= prepare_html_for_static @home.text, @home.university %> diff --git a/app/views/admin/communication/website/pages/static.html.erb b/app/views/admin/communication/website/pages/static.html.erb index f228a27075a4a3c5d0a3a40d23e8d30f600d61eb..cc7f289eec0cf977cc1efa86c2ea189e895f4740 100644 --- a/app/views/admin/communication/website/pages/static.html.erb +++ b/app/views/admin/communication/website/pages/static.html.erb @@ -11,6 +11,6 @@ image_alt: "<%= @page.featured_image_alt %>" category: "<%= @page.related_category.path %>/" <% end %> description: > - <%= prepare_for_github @page.description, @page.university %> + <%= prepare_text_for_static @page.description %> --- -<%= prepare_for_github @page.text, @page.university %> +<%= prepare_html_for_static @page.text, @page.university %> diff --git a/app/views/admin/communication/website/posts/static.html.erb b/app/views/admin/communication/website/posts/static.html.erb index 7e1e119848cb879ee465597727c4097f04d42da2..0d88cc9d41f4186cc7308e1af952bedf8d58ec4a 100644 --- a/app/views/admin/communication/website/posts/static.html.erb +++ b/app/views/admin/communication/website/posts/static.html.erb @@ -20,6 +20,6 @@ image: "<%= @post.featured_image.blob.id %>" image_alt: "<%= @post.featured_image_alt %>" <% end %> description: > - <%= @post.description.chomp %> + <%= prepare_text_for_static @post.description %> --- -<%= prepare_for_github @post.text, @post.university %> +<%= prepare_html_for_static @post.text, @post.university %> diff --git a/app/views/admin/education/program/role/people/new.html.erb b/app/views/admin/education/program/role/people/new.html.erb index 402d1727d98c843d5b6807ec06bdd7d73a1f607b..d2a7ac69768b51844a88ea8619cf00ff449dd98e 100644 --- a/app/views/admin/education/program/role/people/new.html.erb +++ b/app/views/admin/education/program/role/people/new.html.erb @@ -8,8 +8,7 @@ <h5 class="card-title mb-0"><%= t('admin.infos') %></h5> </div> <div class="card-body"> - <% used_person_ids = @role.people.where.not(id: @person.id).pluck(:person_id) %> - <%= f.association :person, collection: current_university.people.where.not(id: used_person_ids).ordered %> + <%= f.association :person, collection: @available_people %> </div> </div> </div> diff --git a/app/views/admin/education/program/roles/_list.html.erb b/app/views/admin/education/program/roles/_list.html.erb index 0a152d39a6e3204e32b1a026dbf9830b714074aa..c4465b6573d625c4e5fee70a81ee2240a26b8f47 100644 --- a/app/views/admin/education/program/roles/_list.html.erb +++ b/app/views/admin/education/program/roles/_list.html.erb @@ -20,12 +20,12 @@ <div class="btn-group" role="group"> <%= link_to t('edit'), edit_admin_education_program_role_path(role, { program_id: @program.id }), - class: button_classes %> + class: button_classes if can?(:edit, role) %> <%= link_to t('delete'), admin_education_program_role_path(role, { program_id: @program.id }), method: :delete, data: { confirm: t('please_confirm') }, - class: button_classes_danger %> + class: button_classes_danger if can?(:destroy, role) %> </div> </td> </tr> diff --git a/app/views/admin/education/program/roles/show.html.erb b/app/views/admin/education/program/roles/show.html.erb index 051d0859a6b646ee517b4ced7cfab8b9568fae08..09d1438bae5ebeb50909afb7c2d79e657036ada7 100644 --- a/app/views/admin/education/program/roles/show.html.erb +++ b/app/views/admin/education/program/roles/show.html.erb @@ -18,8 +18,10 @@ <h2 class="card-title mb-0 h5"><%= Education::Program::Role.human_attribute_name('people') %></h2> </div> <div class="card-body"> - <p><%= link_to t('create'), new_admin_education_program_role_person_path(role_id: @role.id), class: 'btn btn-primary' %></p> <%= render 'admin/education/program/role/people/list', people: @role.people.includes(:person).ordered %> + <% if can? :create, Education::Program::Role::Person %> + <p><%= link_to t('create'), new_admin_education_program_role_person_path(role_id: @role.id), class: 'btn btn-primary' %></p> + <% end %> </div> </div> </div> diff --git a/app/views/admin/education/program/teachers/_form.html.erb b/app/views/admin/education/program/teachers/_form.html.erb index 503032b23e866226f69cd4455e81ada146777148..31950531cded62732c883007d24af5dd0f8a7685 100644 --- a/app/views/admin/education/program/teachers/_form.html.erb +++ b/app/views/admin/education/program/teachers/_form.html.erb @@ -6,8 +6,7 @@ <div class="card-body"> <div class="row"> <div class="col-md-6"> - <% used_teacher_ids = @program.teachers.where.not(id: teacher.id).pluck(:person_id) %> - <%= f.association :person, collection: current_university.people.teachers.where.not(id: used_teacher_ids).ordered %> + <%= f.association :person, collection: @teachers %> </div> <div class="col-md-6"> <%= f.input :description, as: :string %> diff --git a/app/views/admin/education/program/teachers/_list.html.erb b/app/views/admin/education/program/teachers/_list.html.erb index 5fb075887d0d93c3106f82133c7e966076b70fc1..cc7d9c17b4e0f0bd685a4fc0525771250f30610f 100644 --- a/app/views/admin/education/program/teachers/_list.html.erb +++ b/app/views/admin/education/program/teachers/_list.html.erb @@ -20,12 +20,12 @@ <div class="btn-group" role="group"> <%= link_to t('edit'), edit_admin_education_program_teacher_path(teacher, { program_id: @program.id }), - class: button_classes %> + class: button_classes if can? :update, teacher.person %> <%= link_to t('delete'), admin_education_program_teacher_path(teacher, { program_id: @program.id }), method: :delete, data: { confirm: t('please_confirm') }, - class: button_classes_danger %> + class: button_classes_danger if can? :update, teacher.person %> </div> </td> </tr> diff --git a/app/views/admin/education/programs/_list.html.erb b/app/views/admin/education/programs/_list.html.erb index 1694c7d619ccb23bfe2a7a014ca9389df7287e02..0aa706121699f7dc97becf241a58eebc82096b56 100644 --- a/app/views/admin/education/programs/_list.html.erb +++ b/app/views/admin/education/programs/_list.html.erb @@ -15,12 +15,12 @@ <div class="btn-group" role="group"> <%= link_to t('edit'), edit_admin_education_program_path(program), - class: button_classes %> + class: button_classes if can?(:update, program) %> <%= link_to t('delete'), admin_education_program_path(program), method: :delete, data: { confirm: program.children.any? ? t('please_confirm_with_children') : t('please_confirm') }, - class: button_classes_danger %> + class: button_classes_danger if can?(:destroy, program) %> </div> </td> </tr> diff --git a/app/views/admin/education/programs/show.html.erb b/app/views/admin/education/programs/show.html.erb index 1cd1e48366ec359e093e45b81427d2f86153ef34..4ebd03b90caa3aa1586b5ea5b0ac6d798ec67e58 100644 --- a/app/views/admin/education/programs/show.html.erb +++ b/app/views/admin/education/programs/show.html.erb @@ -123,7 +123,7 @@ <div class="col-md-6"> <h3 class="h5"><%= Education::Program.human_attribute_name('roles') %></h3> <%= render 'admin/education/program/roles/list', roles: @program.roles.ordered %> - <%= link_to t('create'), new_admin_education_program_role_path(program_id: @program.id), class: button_classes %> + <%= link_to t('create'), new_admin_education_program_role_path(program_id: @program.id), class: button_classes if can?(:create, Education::Program::Role) %> </div> <div class="col-md-6"> <h3 class="h5"><%= Education::Program.human_attribute_name('teachers') %></h3> diff --git a/app/views/admin/education/programs/static.html.erb b/app/views/admin/education/programs/static.html.erb index c8a1cdbf213ef8183c7948cfe4cee180bedbfc77..505c7a206bfa7aefb738391ca926a37e7660a1e7 100644 --- a/app/views/admin/education/programs/static.html.erb +++ b/app/views/admin/education/programs/static.html.erb @@ -3,7 +3,7 @@ title: > <%= @program.name %> url: /<%= @website.static_pathname_programs %><%= @program.path %>/ description: > - <%= prepare_for_github @program.description, @program.university %> + <%= prepare_text_for_static @program.description %> position: <%= @program.position %> <% if @program.best_featured_image.attached? %> image: "<%= @program.best_featured_image.blob.id %>" @@ -47,6 +47,6 @@ ects: <%= @program.ects %> :content ].each do |property| %> <%= property.to_s %>: > - <%= prepare_for_github @program.send("best_#{property}"), @program.university %> + <%= prepare_html_for_static @program.send("best_#{property}"), @program.university %> <% end %> --- diff --git a/app/views/admin/research/journal/articles/static.html.erb b/app/views/admin/research/journal/articles/static.html.erb index e47b329adf49067887a7c8b3edb3cba58ca56267..345de93af4b3f354d1151a2ecffd6dc3f4b87a58 100644 --- a/app/views/admin/research/journal/articles/static.html.erb +++ b/app/views/admin/research/journal/articles/static.html.erb @@ -1,7 +1,7 @@ --- title: "<%= @article.title %>" description: > - <%= @article.abstract %> + <%= prepare_text_for_static @article.abstract %> <% if @article.volume && @article.volume.path %> volumes: - "<%= @article.volume.path %>" diff --git a/app/views/admin/research/journals/static.html.erb b/app/views/admin/research/journals/static.html.erb index d44e4ec185a045bc91b290be335075f1fe508f73..8c6ebc60c9d5ea3aa98285b1162111573f4b8eeb 100644 --- a/app/views/admin/research/journals/static.html.erb +++ b/app/views/admin/research/journals/static.html.erb @@ -2,7 +2,7 @@ title: > <%= @journal.title %> description: > - <%= @journal.description %> + <%= prepare_text_for_static @journal.description %> issn: > <%= @journal.issn %> --- diff --git a/app/views/admin/university/people/_form.html.erb b/app/views/admin/university/people/_form.html.erb index 498d3415064421a7f3e8db884bcdc71e9390019d..9c0ae01d0ed5dfe3143d2baa7f05eb20e637dfcd 100644 --- a/app/views/admin/university/people/_form.html.erb +++ b/app/views/admin/university/people/_form.html.erb @@ -57,7 +57,7 @@ class: 'js-slug-input', data: { source: '#university_person_first_name, #university_person_last_name' } } %> - <%= f.association :user, collection: current_university.users.ordered %> + <%= f.association :user, collection: current_university.users.ordered if can?(:manage, User) %> </div> </div> <div class="card flex-fill w-100"> diff --git a/app/views/admin/university/people/_main_infos.html.erb b/app/views/admin/university/people/_main_infos.html.erb index bf82980bdcb3f4331af572bb2d1b47a0f2e24071..ac859c5eece68165f4c5c54a727d0b6b63fc7d20 100644 --- a/app/views/admin/university/people/_main_infos.html.erb +++ b/app/views/admin/university/people/_main_infos.html.erb @@ -43,7 +43,7 @@ <% if person.best_picture_inherits_from_user? %> <p> <span class="small text-muted"> - <%= t 'admin.inheritance.sentence_html', link: link_to(person.user, [:admin, person.user]) %> + <%= t 'admin.inheritance.sentence_html', link: link_to_if(can?(:read, person.user), person.user, [:admin, person.user]) %> </span> </p> <% end %> diff --git a/app/views/admin/university/people/static.html.erb b/app/views/admin/university/people/static.html.erb index a90dfeb621a774b90760b1c8ea2117b59118b96e..b50a047d6fc276bb22b78708c350c1e7b8fec720 100644 --- a/app/views/admin/university/people/static.html.erb +++ b/app/views/admin/university/people/static.html.erb @@ -23,4 +23,4 @@ roles: - administrator <% end %> --- -<%= prepare_for_github @person.biography, @person.university %> +<%= prepare_html_for_static @person.biography, @person.university %> diff --git a/app/views/admin/users/_form.html.erb b/app/views/admin/users/_form.html.erb index 317c715232946f7596a3ff9e27cb21d60377dfb6..15f7c0d6dcbab185cd9c2497597f2180e4fe6112 100644 --- a/app/views/admin/users/_form.html.erb +++ b/app/views/admin/users/_form.html.erb @@ -29,7 +29,7 @@ }, input_html: { autocomplete: "new-password" } %> <%= f.input :mobile_phone %> - <%= f.input :role, include_blank: false, collection: current_user.managed_roles %> + <%= f.input :role, include_blank: false, collection: current_user.managed_roles, label_method: lambda { |k| t("activerecord.attributes.user.roles.#{k[1]}")} %> </div> </div> </div> diff --git a/config/locales/en.yml b/config/locales/en.yml index aea1857ea0e32fc83b615261681bef125abddd19..c692b52c30b57506cce0168e7d49cf8a83b99efe 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -13,6 +13,12 @@ en: mobile_phone: Mobile phone picture: Profile picture role: Role + roles: + admin: Administrator + program_manager: Program manager + server_admin: Server admin + teacher: Teacher + visitor: Visitor errors: models: user: diff --git a/config/locales/fr.yml b/config/locales/fr.yml index ebbd8d67b579b7226fb5c6e3c0a70da68da989cd..768f6224d7e927bcbf8074ed9592f72993c6cc91 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -13,6 +13,12 @@ fr: mobile_phone: Téléphone portable picture: Photo de profil role: Rôle + roles: + admin: Administrateur + program_manager: Responsable de formation + server_admin: Administrateur du serveur + teacher: Enseignant·e + visitor: Visiteur errors: models: user: