Commit 2b41db92 authored by Phil Hughes's avatar Phil Hughes

Search project groups

parent 73c4da17
...@@ -10,23 +10,30 @@ class Projects::ProjectMembersController < Projects::ApplicationController ...@@ -10,23 +10,30 @@ class Projects::ProjectMembersController < Projects::ApplicationController
project_members = @project.project_members project_members = @project.project_members
project_members = project_members.non_invite unless can?(current_user, :admin_project, @project) project_members = project_members.non_invite unless can?(current_user, :admin_project, @project)
if params[:search].present?
users = @project.users.search(params[:search]).to_a
project_members = project_members.where(user_id: users)
end
members_ids = project_members.pluck(:id)
group = @project.group group = @project.group
if group if group
group_members = group.group_members group_members = group.group_members
group_members = group_members.non_invite unless can?(current_user, :admin_project, @project) group_members = group_members.non_invite unless can?(current_user, :admin_project, @project)
end
if params[:search].present? if params[:search].present?
groups_id = @groups.pluck(:group_id)
groups = Group.where(id: groups_id).search(params[:search]).to_a
@groups = @project.project_group_links.where(group_id: groups)
users = @project.users.search(params[:search]).to_a
project_members = project_members.where(user_id: users)
if group_members
users = group.users.search(params[:search]).to_a users = group.users.search(params[:search]).to_a
group_members = group_members.where(user_id: users) group_members = group_members.where(user_id: users)
end end
end
members_ids = project_members.pluck(:id)
if group_members
members_ids << group_members.pluck(:id) members_ids << group_members.pluck(:id)
end end
...@@ -48,6 +55,17 @@ class Projects::ProjectMembersController < Projects::ApplicationController ...@@ -48,6 +55,17 @@ class Projects::ProjectMembersController < Projects::ApplicationController
current_user: current_user current_user: current_user
) )
group_ids = params[:group_ids].split(',')
groups = Group.where(id: group_ids)
groups.each do |group|
project.project_group_links.create(
group: group,
group_access: params[:access_level],
expires_at: params[:expires_at]
)
end
redirect_to namespace_project_project_members_path(@project.namespace, @project) redirect_to namespace_project_project_members_path(@project.namespace, @project)
end end
...@@ -101,6 +119,21 @@ class Projects::ProjectMembersController < Projects::ApplicationController ...@@ -101,6 +119,21 @@ class Projects::ProjectMembersController < Projects::ApplicationController
notice: notice) notice: notice)
end end
def options
users = User.all
users = users.search(params[:search]) if params[:search].present?
users = users.page(1)
groups = Group.all
groups = groups.search(params[:search]) if params[:search].present?
groups = groups.page(1)
render json: {
Groups: groups.as_json(only: [:id, :name], methods: [:avatar_url]),
Users: users.as_json(only: [:id, :name, :username], methods: [:avatar_url]),
}
end
protected protected
def member_params def member_params
......
...@@ -43,4 +43,24 @@ feature 'Projects > Members > Anonymous user sees members', feature: true, js: t ...@@ -43,4 +43,24 @@ feature 'Projects > Members > Anonymous user sees members', feature: true, js: t
expect(page).not_to have_selector('.group_member') expect(page).not_to have_selector('.group_member')
end end
context 'search' do
it 'finds no results' do
page.within '.member-search-form' do
fill_in 'search', with: 'testing 123'
find('.member-search-btn').click
end
expect(page).not_to have_selector('.group_member')
end
it 'finds results' do
page.within '.member-search-form' do
fill_in 'search', with: group.name
find('.member-search-btn').click
end
expect(page).to have_selector('.group_member', count: 1)
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment