Commit ac7f3e6a authored by Robert Speicher's avatar Robert Speicher

Merge branch 'allow-skipping-users-in-autocomplete' into 'master'

Allow skipping users in autocomplete

Ref: https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/560

See merge request !5471
parents ccb5daee dc4de2d8
...@@ -189,6 +189,7 @@ ...@@ -189,6 +189,7 @@
_this.groupId = $(select).data('group-id'); _this.groupId = $(select).data('group-id');
_this.showCurrentUser = $(select).data('current-user'); _this.showCurrentUser = $(select).data('current-user');
_this.authorId = $(select).data('author-id'); _this.authorId = $(select).data('author-id');
_this.skipUsers = $(select).data('skip-users');
showNullUser = $(select).data('null-user'); showNullUser = $(select).data('null-user');
showAnyUser = $(select).data('any-user'); showAnyUser = $(select).data('any-user');
showEmailUser = $(select).data('email-user'); showEmailUser = $(select).data('email-user');
...@@ -320,7 +321,8 @@ ...@@ -320,7 +321,8 @@
project_id: this.projectId, project_id: this.projectId,
group_id: this.groupId, group_id: this.groupId,
current_user: this.showCurrentUser, current_user: this.showCurrentUser,
author_id: this.authorId author_id: this.authorId,
skip_users: this.skipUsers
}, },
dataType: "json" dataType: "json"
}).done(function(users) { }).done(function(users) {
......
...@@ -5,6 +5,7 @@ class AutocompleteController < ApplicationController ...@@ -5,6 +5,7 @@ class AutocompleteController < ApplicationController
def users def users
@users ||= User.none @users ||= User.none
@users = @users.search(params[:search]) if params[:search].present? @users = @users.search(params[:search]) if params[:search].present?
@users = @users.where.not(id: params[:skip_users]) if params[:skip_users].present?
@users = @users.active @users = @users.active
@users = @users.reorder(:name) @users = @users.reorder(:name)
@users = @users.page(params[:page]) @users = @users.page(params[:page])
......
...@@ -5,21 +5,9 @@ module SelectsHelper ...@@ -5,21 +5,9 @@ module SelectsHelper
css_class << "skip_ldap " if opts[:skip_ldap] css_class << "skip_ldap " if opts[:skip_ldap]
css_class << (opts[:class] || '') css_class << (opts[:class] || '')
value = opts[:selected] || '' value = opts[:selected] || ''
first_user = opts[:first_user] && current_user ? current_user.username : false
html = { html = {
class: css_class, class: css_class,
data: { data: users_select_data_attributes(opts)
placeholder: opts[:placeholder] || 'Search for a user',
null_user: opts[:null_user] || false,
any_user: opts[:any_user] || false,
email_user: opts[:email_user] || false,
first_user: first_user,
current_user: opts[:current_user] || false,
"push-code-to-protected-branches" => opts[:push_code_to_protected_branches],
author_id: opts[:author_id] || ''
}
} }
unless opts[:scope] == :all unless opts[:scope] == :all
...@@ -68,4 +56,20 @@ module SelectsHelper ...@@ -68,4 +56,20 @@ module SelectsHelper
hidden_field_tag(id, value, class: css_class) hidden_field_tag(id, value, class: css_class)
end end
private
def users_select_data_attributes(opts)
{
placeholder: opts[:placeholder] || 'Search for a user',
null_user: opts[:null_user] || false,
any_user: opts[:any_user] || false,
email_user: opts[:email_user] || false,
first_user: opts[:first_user] && current_user ? current_user.username : false,
current_user: opts[:current_user] || false,
"push-code-to-protected-branches" => opts[:push_code_to_protected_branches],
author_id: opts[:author_id] || '',
skip_users: opts[:skip_users] ? opts[:skip_users].map(&:id) : nil,
}
end
end end
...@@ -163,4 +163,17 @@ describe AutocompleteController do ...@@ -163,4 +163,17 @@ describe AutocompleteController do
expect(body.collect { |u| u['id'] }).not_to include(99999) expect(body.collect { |u| u['id'] }).not_to include(99999)
end end
end end
context 'skip_users parameter included' do
before { sign_in(user) }
it 'skips the user IDs passed' do
get(:users, skip_users: [user, user2].map(&:id))
other_user_ids = [non_member, project.owner, project.creator].map(&:id)
response_user_ids = JSON.parse(response.body).map { |user| user['id'] }
expect(response_user_ids).to contain_exactly(*other_user_ids)
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