Skip to content

Commit

Permalink
Merge pull request #15530 from opf/bug/51447-fix-different-headings-i…
Browse files Browse the repository at this point in the history
…n-permissions-report-and-role-form

[51447] Use same headings for permissions report and role forms
  • Loading branch information
cbliard committed May 13, 2024
2 parents 9b7db54 + 4572685 commit 97132f7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 27 deletions.
9 changes: 9 additions & 0 deletions app/helpers/roles_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,13 @@ def group_permissions_by_module(perms)
perms.group_by { |p| p.project_module.to_s }
.slice(*enabled_module_names)
end

def permission_header_for_project_module(mod)
if mod.blank?
Project.model_name.human
else
I18n.t("permission_header_for_project_module_#{mod}",
default: [:"project_module_#{mod}", mod.humanize])
end
end
end
8 changes: 4 additions & 4 deletions app/views/roles/_permissions.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ See COPYRIGHT and LICENSE files for more details.
<% permissions.each do |mod, mod_permissions| %>
<% global_prefix = show_global_role ? 'fieldset--global--' : 'fieldset--' %>
<% module_name = mod.blank? ? 'fieldset--global--' + Project.model_name.human.downcase.gsub(' ', '_') : global_prefix + l_or_humanize(mod, prefix: 'project_module_').downcase.gsub(' ', '_') %>
<% module_id = module_name.parameterize %>
<% module_id = module_name.parameterize %>
<fieldset class="form--fieldset -collapsible" id="<%= module_id %>">
<legend class="form--fieldset-legend">
<% if mod.blank? %>
<%= show_global_role ? t(:label_global) : Project.model_name.human %>
<% if show_global_role && mod.blank? %>
<%= t(:label_global) %>
<% else %>
<%= I18n.t("permission_header_for_project_module_#{mod}", default: l_or_humanize(mod, prefix: 'project_module_')) %>
<%= permission_header_for_project_module(mod) %>
<% end %>
</legend>
<div class="form--toolbar">
Expand Down
6 changes: 3 additions & 3 deletions app/views/roles/report.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ See COPYRIGHT and LICENSE files for more details.
<% group_permissions_by_module(@permissions).each do |mod, mod_permissions| %>
<% module_name = mod.blank? ? "form--" + I18n.t('attributes.project') : "form--" + l_or_humanize(mod, prefix: 'project_module_').gsub(' ','_') %>
<% escaped_name = module_name.parameterize %>
<fieldset class="form--fieldset -collapsible" id= "<%= escaped_name %>">
<legend class="form--fieldset-legend" >
<%= mod.blank? ? I18n.t('attributes.project') : l_or_humanize(mod, prefix: 'project_module_') %>
<fieldset class="form--fieldset -collapsible" id="<%= escaped_name %>">
<legend class="form--fieldset-legend">
<%= permission_header_for_project_module(mod) %>
</legend>
<div class="form--toolbar">
<span class="form--toolbar-item">
Expand Down
40 changes: 20 additions & 20 deletions modules/storages/spec/features/storages_module_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,19 @@

current_user { user }

shared_examples_for "content section has storages module" do |is_upcase = false|
shared_examples_for "content section has storages module" do
it 'must show "storages" in content section' do
within "#content" do
text = I18n.t(:project_module_storages)
expect(page).to have_text(is_upcase ? text.upcase : text)
expect(page).to have_text(text)
end
end
end

shared_examples_for "content section has storages permission header" do
it 'must show "Automatically managed project folders" in content section' do
within "#content" do
expect(page).to have_text(I18n.t(:permission_header_for_project_module_storages).upcase)
end
end
end
Expand All @@ -61,10 +69,10 @@
end
end

shared_examples_for "has storages module" do |sections: %i[content sidebar], is_upcase: false|
shared_examples_for "has storages module" do |sections: %i[content sidebar]|
before { visit(path) }

include_examples "content section has storages module", is_upcase if sections.include?(:content)
include_examples "content section has storages module" if sections.include?(:content)
include_examples "sidebar has storages module" if sections.include?(:sidebar)
end

Expand All @@ -90,29 +98,21 @@
end

context "when creating a new role" do
it 'must have appropriate storage permissions header in content section' do
visit new_role_path
before { visit new_role_path }

within "#content" do
expect(page).to have_text(I18n.t(:permission_header_for_project_module_storages).upcase)
end
end
include_examples "content section has storages permission header"
end

context "when editing a role" do
it 'must have appropriate storage permissions header in content section' do
visit edit_role_path(role)
before { visit edit_role_path(role) }

within "#content" do
expect(page).to have_text(I18n.t(:permission_header_for_project_module_storages).upcase)
end
end
include_examples "content section has storages permission header"
end

context "when showing the role permissions report" do
it_behaves_like "has storages module", sections: [:content], is_upcase: true do
let(:path) { report_roles_path(role) }
end
context "when showing the permissions report" do
before { visit report_roles_path }

include_examples "content section has storages permission header"
end
end

Expand Down

0 comments on commit 97132f7

Please sign in to comment.