Skip to content

Commit

Permalink
Merge pull request #16058 from opf/bug/50109-breadcrumb-and-menu-stru…
Browse files Browse the repository at this point in the history
…cture-is-inconsistent-for-user-administration

[50109] Breadcrumb and menu structure is inconsistent for user administration
  • Loading branch information
HDinger authored Jul 16, 2024
2 parents 7ec596d + 4686015 commit 9ce48ce
Show file tree
Hide file tree
Showing 51 changed files with 638 additions and 371 deletions.
6 changes: 1 addition & 5 deletions app/controllers/admin/settings/users_settings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,8 @@ def show
respond_to :html
end

def default_breadcrumb
t(:label_user_settings)
end

def show_local_breadcrumb
true
false
end

def settings_params
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/settings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def update_plugin
end

def show_local_breadcrumb
true
false
end

def default_breadcrumb
Expand Down
10 changes: 1 addition & 9 deletions app/controllers/groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,8 @@ def visible_group_members?
Group.in_project(Project.allowed_to(current_user, :view_members)).exists?
end

def default_breadcrumb
if action_name == "index" || !current_user.admin?
t("label_group_plural")
else
ActionController::Base.helpers.link_to(t("label_group_plural"), groups_path)
end
end

def show_local_breadcrumb
true
false
end

def respond_membership_altered(service_call)
Expand Down
11 changes: 1 addition & 10 deletions app/controllers/placeholder_users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,7 @@ def authorize_deletion
end
end

def default_breadcrumb
if action_name == "index"
t("label_placeholder_user_plural")
else
ActionController::Base.helpers.link_to(t("label_placeholder_user_plural"),
placeholder_users_path)
end
end

def show_local_breadcrumb
action_name != "show"
false
end
end
10 changes: 1 addition & 9 deletions app/controllers/roles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,8 @@ def roles_scope
Role.visible.ordered_by_builtin_and_position
end

def default_breadcrumb
if action_name == "index"
t("label_role_plural")
else
ActionController::Base.helpers.link_to(t("label_role_plural"), roles_path)
end
end

def show_local_breadcrumb
true
false
end

def new_params
Expand Down
10 changes: 1 addition & 9 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,16 +282,8 @@ def set_password?(params)

protected

def default_breadcrumb
if action_name == "index"
t("label_user_plural")
else
ActionController::Base.helpers.link_to(t("label_user_plural"), users_path)
end
end

def show_local_breadcrumb
can_manage_or_create_users? && action_name != "show"
false
end

def build_user_update_params
Expand Down
10 changes: 4 additions & 6 deletions app/helpers/tabs_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@

module TabsHelper
# Renders tabs and their content
def render_tabs(tabs, form = nil)
def render_tabs(tabs, form = nil, with_tab_nav: true)
if tabs.any?
selected = selected_tab(tabs)
render partial: "common/tabs", locals: { f: form, tabs:, selected_tab: selected }
render partial: "common/tabs", locals: { f: form, tabs:, selected_tab: selected, with_tab_nav: }
else
content_tag "p", I18n.t(:label_no_data), class: "nodata"
end
Expand All @@ -41,12 +41,10 @@ def selected_tab(tabs)
tabs.detect { |t| t[:name] == params[:tab] } || tabs.first
end

# Render tabs from the ui/extensible tabs manager
def render_extensible_tabs(key, params = {})
tabs = ::OpenProject::Ui::ExtensibleTabs.enabled_tabs(key, params.reverse_merge(current_user:)).map do |tab|
def tabs_for_key(key, params = {})
::OpenProject::Ui::ExtensibleTabs.enabled_tabs(key, params.reverse_merge(current_user:)).map do |tab|
path = tab[:path].respond_to?(:call) ? instance_exec(params, &tab[:path]) : tab[:path]
tab.dup.merge(path:)
end
render_tabs(tabs)
end
end
40 changes: 25 additions & 15 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,41 +87,51 @@ def full_user_status(user, include_num_failed_logins = false)

# Create buttons to lock/unlock a user and reset failed logins
def build_change_user_status_action(user)
result = "".html_safe
iterate_user_statusses(user) do |title, name|
result << ((yield title, name) + " ".html_safe)
end
result
end

def iterate_user_statusses(user)
status = user.status.to_sym
blocked = !!user.failed_too_many_recent_login_attempts?

result = "".html_safe
(STATUS_CHANGE_ACTIONS[[status, blocked]] || []).each do |title, name|
result << ((yield I18n.t(title, scope: :user), name) + " ".html_safe)
yield I18n.t(title, scope: :user), name
end
result
end

def change_user_status_icons
{
"unlock" => "unlocked",
"activate" => "unlocked",
"lock" => "locked"
"unlock" => "unlock",
"activate" => "unlock",
"lock" => "lock"
}
end

def change_user_status_buttons(user)
build_change_user_status_action(user) do |title, name|
button_tag(class: "button", name:, type: "submit", title:) do
concat op_icon("button--icon icon-#{change_user_status_icons[name]}")
concat content_tag(:span, title, class: "button--text")
render Primer::Beta::Button.new(name:, type: :submit, title:) do |button|
button.with_leading_visual_icon(icon: change_user_status_icons[name])
title
end
end
end

def change_user_status_links(user)
build_change_user_status_action(user) do |title, name|
link_to title,
change_status_user_path(user,
name.to_sym => "1",
back_url: request.fullpath),
method: :post,
class: "icon icon-#{change_user_status_icons[name]}"
render Primer::Beta::Button.new(tag: :a,
scheme: :link,
title:,
href: change_status_user_path(user,
name.to_sym => "1",
back_url: request.fullpath),
data: { method: :post }) do |button|
button.with_leading_visual_icon(icon: change_user_status_icons[name])
title
end
end
end

Expand Down
12 changes: 5 additions & 7 deletions app/views/admin/settings/show_plugin.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
See COPYRIGHT and LICENSE files for more details.
++#%>
<%= toolbar title: @plugin.name %>
<div id="settings">
<%= styled_form_tag({controller: '/admin/settings', action: 'update_plugin' }) do %>
<%= render partial: @partial, locals: {settings: @settings}%>
<%= styled_submit_tag t(:button_apply), class: '-primary' %>
<% end %>
</div>
<% html_title t(:label_administration), @plugin.name %>
<%= render partial: @partial, locals: {settings: @settings}%>
9 changes: 8 additions & 1 deletion app/views/admin/settings/users_settings/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
<% html_title t(:label_administration), t(:label_user_settings) -%>
<%= toolbar title: t(:label_user_settings) %>
<%=
render(Primer::OpenProject::PageHeader.new) do |header|
header.with_title { t(:label_user_settings) }
header.with_breadcrumbs([{ href: admin_index_path, text: t("label_administration") },
{ href: admin_settings_users_path, text: t(:label_user_and_permission) },
t(:label_user_settings)])
end
%>
<%= styled_form_tag(admin_settings_users_path, method: :patch, class: 'admin-settings--form') do %>

Expand Down
4 changes: 3 additions & 1 deletion app/views/common/_tabs.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
<% gon.contentTabs = { tabs: tabs.to_json.html_safe, selected: selected_tab.to_json.html_safe } %>
<content-tabs></content-tabs>
<% if with_tab_nav %>
<content-tabs></content-tabs>
<% end %>
<%= content_tag 'div',
render(partial: selected_tab[:partial], locals: { f: f, tab: selected_tab } ),
Expand Down
72 changes: 50 additions & 22 deletions app/views/groups/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,53 @@ See COPYRIGHT and LICENSE files for more details.
<% html_title t(:label_administration), "#{t(:label_edit)} #{Group.model_name.human} #{h @group.name}" %>
<% local_assigns[:additional_breadcrumb] = @group.name %>
<%= breadcrumb_toolbar @group.name do %>
<li class="toolbar-item">
<%= link_to show_group_path(@group), class: 'button' do %>
<%= op_icon('button--icon icon-user') %>
<span class="button--text"><%= t(:label_profile) %></span>
<% end %>
</li>
<% if current_user.admin? %>
<li class="toolbar-item">
<%= link_to group_path(@group),
data: { confirm: t(:text_are_you_sure) },
class: 'button -danger',
method: :delete do %>
<%= op_icon('button--icon icon-delete') %>
<span class="button--text"><%= t(:button_delete) %></span>
<% end %>
</li>
<% end %>
<% end %>
<%= render_tabs group_settings_tabs(@group) %>
<% tabs = group_settings_tabs(@group) %>
<%=
render(Primer::OpenProject::PageHeader.new) do |header|
header.with_title { @group.name }
header.with_breadcrumbs([{ href: admin_index_path, text: t("label_administration") },
{ href: admin_settings_users_path, text: t(:label_user_and_permission) },
{ href: groups_path, text: t(:label_group_plural) },
@group.name])

header.with_action_button(tag: :a,
mobile_icon: :person,
mobile_label: t(:label_profile),
size: :medium,
href: show_group_path(@group),
aria: { label: I18n.t(:label_profile) },
title: I18n.t(:label_profile)) do |button|
button.with_leading_visual_icon(icon: :person)
t(:label_profile)
end

if current_user.admin?
header.with_action_button(tag: :a,
scheme: :danger,
mobile_icon: :trash,
mobile_label: t(:button_delete),
size: :medium,
href: group_path(@group),
aria: { label: I18n.t(:button_delete) },
data: {
confirm: t(:text_are_you_sure),
method: :delete,
},
title: I18n.t(:button_delete)) do |button|
button.with_leading_visual_icon(icon: :trash)
t(:button_delete)
end
end

header.with_tab_nav(label: nil) do |tab_nav|
tabs.each do |tab|
tab_nav.with_tab(selected: selected_tab(tabs) == tab, href: tab[:path]) do |t|
t.with_text { I18n.t("js.#{tab[:label]}") }
end
end
end if tabs.present?
end
%>
<%= render_tabs tabs, with_tab_nav: false %>
34 changes: 23 additions & 11 deletions app/views/groups/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,29 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
<% html_title t(:label_administration), t("label_group_plural") %>
<%= toolbar title: t(:label_group_plural) do %>
<li class="toolbar-item">
<%= link_to new_group_path,
{ class: 'button -primary',
aria: {label: t(:label_group_new)},
title: t(:label_group_new)} do %>
<%= op_icon('button--icon icon-add') %>
<span class="button--text"><%= t('activerecord.models.group') %></span>
<% end %>
</li>
<% end %>
<%=
render(Primer::OpenProject::PageHeader.new) do |header|
header.with_title { t(:label_group_plural) }
header.with_breadcrumbs([{ href: admin_index_path, text: t("label_administration") },
{ href: admin_settings_users_path, text: t(:label_user_and_permission) },
t(:label_group_plural)])
end
%>
<%=
render(Primer::OpenProject::SubHeader.new) do |subheader|
subheader.with_action_button(scheme: :primary,
aria: { label: I18n.t(:label_group_new) },
title: I18n.t(:label_group_new),
tag: :a,
href: new_group_path) do |button|
button.with_leading_visual_icon(icon: :plus)
t('activerecord.models.group')
end
end
%>
<% if @groups.any? %>
<div class="generic-table--container">
<div class="generic-table--results-container">
Expand Down
14 changes: 12 additions & 2 deletions app/views/groups/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,18 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
<% html_title t(:label_administration), t("label_group_new") %>
<% local_assigns[:additional_breadcrumb] = t(:label_group_new) %>
<%= breadcrumb_toolbar t(:label_group_new) %>
<%=
render(Primer::OpenProject::PageHeader.new) do |header|
header.with_title { t(:label_group_new) }
header.with_breadcrumbs([{ href: admin_index_path, text: t("label_administration") },
{ href: admin_settings_users_path, text: t(:label_user_and_permission) },
{ href: groups_path, text: t(:label_group_plural) },
t(:label_group_new)])
end
%>
<%= labelled_tabular_form_for(@group) do |f| %>
<%= render partial: 'form', locals: { f: f } %>
Expand Down
Loading

0 comments on commit 9ce48ce

Please sign in to comment.