Skip to content

Commit

Permalink
Simplify how webui routes are defined for groups
Browse files Browse the repository at this point in the history
They are now all defined with resources and grouped together. Some route
helpers slightly changed and were replaced with the following GNU sed
commands:
  sed -i -e 's/group_show_path/group_path/g' src/api/**/*{.rb,.haml}
  sed -i -e 's/group_new_path/new_group_path/g' src/api/**/*{.rb,.haml}
  sed -i -e 's/group_create_path/groups_path/g' src/api/**/*{.rb,.haml}

I didn't find any `_url` version of the route helpers for those routes,
so nothing had to change for this.
  • Loading branch information
Dany Marcoux committed Apr 16, 2021
1 parent b38d311 commit f033661
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class BsRequestsController < WebuiController
private

def set_group
@user_or_group = Group.find_by_title!(params[:title])
@user_or_group = Group.find_by_title!(params[:group_title])
end

def request_method
Expand Down
6 changes: 3 additions & 3 deletions src/api/app/controllers/webui/groups/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def create
user = User.find_by(login: params[:user_login])
if user.nil?
flash[:error] = "User '#{params[:user_login]}' not found"
redirect_to group_show_path(@group)
redirect_to group_path(@group)
return
end

Expand All @@ -22,7 +22,7 @@ def create
flash[:error] = "Couldn't add user '#{user}' to group '#{@group}': #{group_user.errors.full_messages.to_sentence}"
end

redirect_to group_show_path(@group)
redirect_to group_path(@group)
end

def destroy
Expand All @@ -34,7 +34,7 @@ def destroy
flash[:error] = "Couldn't remove user '#{@user}' from group '#{@group}'"
end

redirect_to group_show_path(@group)
redirect_to group_path(@group)
end

def update
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/helpers/webui/group_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Webui::GroupHelper
def group_with_icon(group_title)
group = Group.find_by(title: group_title)
image_tag_for(group, size: 20) + ' ' + link_to(group_title, group_show_path(group))
image_tag_for(group, size: 20) + ' ' + link_to(group_title, group_path(group))
end
end
4 changes: 2 additions & 2 deletions src/api/app/helpers/webui/user_or_groups_roles_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def display_name(object)
end
end

def user_or_group_show_path(object)
object.is_a?(User) ? user_path(object) : group_show_path(object)
def user_or_group_path(object)
object.is_a?(User) ? user_path(object) : group_path(object)
end

def user_or_groups_roles_delete_path(project, type, object, package)
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/views/webui/groups/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
- @groups.each do |group|
%tr
%td
= link_to(group, group_show_path(title: group))
= link_to(group, group_path(title: group))
%td
= safe_join(group.users.map { |user| link_to(truncate(user.login, length: 20), user_path(user), title: user.login) }, ', ')

.pt-4
= link_to(group_new_path, title: 'Create Group') do
= link_to(new_group_path, title: 'Create Group') do
%i.fas.fa-plus-circle.text-primary
Create Group

Expand Down
2 changes: 1 addition & 1 deletion src/api/app/views/webui/groups/new.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
.card-body
%h3= @pagetitle
.col-lg-6.pl-0
= form_for(Group.new, url: group_create_path, method: :post) do |form|
= form_for(Group.new, url: groups_path, method: :post) do |form|
.form-group
= form.label(:title)
%abbr.text-danger{ title: 'required' } *
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/views/webui/search/_results_owner.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
.card.m-1.p-2.search-result
.row.no-gutters
.col-auto
= link_to(user_or_group_show_path(record)) do
= link_to(user_or_group_path(record)) do
= image_tag_for(record, size: 60, custom_class: 'align-self-center shadow-lg border border-secondary rounded border-2')
.col
.card-body.p-0.pl-2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
%tr
%td.align-middle
= image_tag_for(record, size: 20)
= link_to(display_name(record), user_or_group_show_path(record))
= link_to(display_name(record), user_or_group_path(record))
- roles.each do |role|
%td.align-middle
.custom-control.custom-checkbox
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/views/webui/staging/workflows/_infos.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
%dt Managers:
%dd
%ul.pl-2.list-unstyled
%li= link_to managers.title, group_show_path(managers)
%li= link_to managers.title, group_path(managers)

%dt Empty projects:
%dd= render 'empty_projects_list', projects: empty_projects, staging_workflow: staging_workflow

%dt= link_to('Backlog:', group_show_path(staging_workflow.managers_group, anchor: 'reviews-in'))
%dt= link_to('Backlog:', group_path(staging_workflow.managers_group, anchor: 'reviews-in'))
%dd= render 'requests_list', requests: unassigned_requests, more_requests: more_unassigned_requests

%dt= link_to('Ready:', project_requests_path(staging_workflow.project, state: :new))
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/views/webui/user/_info.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
%ul
- groups.each do |group|
%li
= link_to(group_show_path(group)) do
= link_to(group_path(group)) do
#{group.title}
%span.badge.badge-primary.align-baseline
#{group.tasks} #{'task'.pluralize(group.tasks)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
%ul.list-group.list-group-flush
- groups.each do |group|
%li.list-group-item.d-flex.justify-content-between.align-items-center.p-2
= link_to(group.title, group_show_path(group))
= link_to(group.title, group_path(group))
%span.badge.badge-primary
#{group.tasks} #{'task'.pluralize(group.tasks)}

Expand Down
19 changes: 6 additions & 13 deletions src/api/config/routes/webui_routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -346,20 +346,13 @@

resource :session, only: [:new, :create, :destroy], controller: 'webui/session'

controller 'webui/groups/bs_requests' do
get 'groups/(:title)/requests' => :index, constraints: { title: %r{[^/]*} }, as: 'group_requests'
end

controller 'webui/groups' do
get 'groups' => :index
get 'group/show/:title' => :show, constraints: { title: %r{[^/]*} }, as: 'group_show'
get 'group/new' => :new
post 'group/create' => :create
get 'group/autocomplete' => :autocomplete, as: 'autocomplete_groups'
end
resources :groups, only: [:index, :show, :new, :create], param: :title, constraints: cons, controller: 'webui/groups' do
resources :user, only: [:create, :destroy, :update], param: :user_login, constraints: cons, controller: 'webui/groups/users'
resources :requests, only: [:index], controller: 'webui/groups/bs_requests'

resources :groups, only: [], param: :title, constraints: cons do
resources :user, only: [:create, :destroy, :update], constraints: cons, param: :user_login, controller: 'webui/groups/users'
collection do
get :autocomplete
end
end

resources :comments, constraints: cons, only: [:create, :destroy, :update], controller: 'webui/comments' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
let(:group) { create(:group) }
let!(:relationship_project_group) { create(:relationship_project_group, group: group, project: target_project) }
let!(:relationship_project_group2) { create(:relationship_project_group, group: group, project: target_project2) }
let(:base_params) { { title: group.title, format: :json, dataTableId: 'requests_in_table' } }
let(:base_params) { { group_title: group.title, format: :json, dataTableId: 'requests_in_table' } }
let(:context_params) { {} }
let(:params) { base_params.merge(context_params) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
end

it 'adds the user to the group' do
expect(response).to redirect_to(group_show_path(title: group.title))
expect(response).to redirect_to(group_path(title: group.title))
expect(flash[:success]).to eq("Added user '#{user}' to group '#{group}'")
expect(group.users.where(groups_users: { user_id: user })).to exist
end
Expand Down Expand Up @@ -76,7 +76,7 @@
end

it 'removes the user from the group' do
expect(response).to redirect_to(group_show_path(title: group.title))
expect(response).to redirect_to(group_path(title: group.title))
expect(flash[:success]).to eq("Removed user '#{user}' from group '#{group}'")
expect(group.users.where(groups_users: { user_id: user })).not_to exist
end
Expand Down
10 changes: 5 additions & 5 deletions src/api/spec/features/webui/groups_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
end

def group_in_datatable(page, group)
expect(page).to have_link(group.title, href: group_show_path(group))
expect(page).to have_link(group.title, href: group_path(group))
group.users.each { |user| expect(page).to have_link(user.login, href: user_path(user)) }
end

Expand All @@ -26,7 +26,7 @@ def group_in_datatable(page, group)
end

it 'visit group show page' do
visit group_show_path(group_1)
visit group_path(group_1)

# TODO: Remove this line if the dropdown is changed to a scrollable tab
find('.nav-link.dropdown-toggle').click if mobile?
Expand Down Expand Up @@ -55,7 +55,7 @@ def group_in_datatable(page, group)
end

it 'remove a member from a group' do
visit group_show_path(group_1)
visit group_path(group_1)

within(find('div.group-user', text: admin.login)) do
click_link('Remove member from group')
Expand All @@ -67,7 +67,7 @@ def group_in_datatable(page, group)
end

it 'give maintainer rights to a group member' do
visit group_show_path(group_1)
visit group_path(group_1)

within(find('div.group-user', text: admin.login)) do
check('Maintainer')
Expand All @@ -77,7 +77,7 @@ def group_in_datatable(page, group)
end

it 'add a group member' do
visit group_show_path(group_2)
visit group_path(group_2)

click_link('Add Member')

Expand Down

0 comments on commit f033661

Please sign in to comment.