Commit 0daa21ed authored by Douwe Maan's avatar Douwe Maan

Merge branch 'fix-email-autocomplete' into 'master'

Fix bug preventing invite by e-mail

This was broken in 70f52918 as a result of introducing the ability to filter by current user.

Closes #2320

See merge request !1181
parents 1cfc4af3 577df6b8
......@@ -6,6 +6,7 @@ class @UsersSelect
$('.ajax-users-select').each (i, select) =>
@projectId = $(select).data('project-id')
@groupId = $(select).data('group-id')
@showCurrentUser = $(select).data('current-user')
showNullUser = $(select).data('null-user')
showAnyUser = $(select).data('any-user')
showEmailUser = $(select).data('email-user')
......@@ -108,6 +109,7 @@ class @UsersSelect
active: true
project_id: @projectId
group_id: @groupId
current_user: @showCurrentUser
dataType: "json"
).done (users) ->
callback(users)
......
......@@ -33,8 +33,14 @@ class AutocompleteController < ApplicationController
@users = @users.search(params[:search]) if params[:search].present?
@users = @users.active
@users = @users.page(params[:page]).per(PER_PAGE)
# Always include current user if available to filter by "Me"
@users = User.find(@users.pluck(:id) + [current_user.id]).uniq if current_user
unless params[:search].present?
# Include current user if available to filter by "Me"
if params[:current_user] && current_user
@users = [*@users, current_user].uniq
end
end
render json: @users, only: [:name, :username, :id], methods: [:avatar_url]
end
......
......@@ -10,6 +10,7 @@ module SelectsHelper
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
project = opts[:project] || @project
html = {
......@@ -18,7 +19,8 @@ module SelectsHelper
'data-null-user' => null_user,
'data-any-user' => any_user,
'data-email-user' => email_user,
'data-first-user' => first_user
'data-first-user' => first_user,
'data-current-user' => current_user
}
unless opts[:scope] == :all
......
......@@ -9,7 +9,7 @@
none
.issuable-context-selectbox
- if can?(current_user, :"admin_#{issuable.to_ability_name}", @project)
= users_select_tag("#{issuable.class.table_name.singularize}[assignee_id]", placeholder: 'Select assignee', class: 'custom-form-control js-select2 js-assignee', selected: issuable.assignee_id, project: @target_project, null_user: true)
= users_select_tag("#{issuable.class.table_name.singularize}[assignee_id]", placeholder: 'Select assignee', class: 'custom-form-control js-select2 js-assignee', selected: issuable.assignee_id, project: @target_project, null_user: true, current_user: true)
%div.prepend-top-20.clearfix
.issuable-context-title
......
......@@ -36,11 +36,11 @@
.issues-other-filters
.filter-item.inline
= users_select_tag(:assignee_id, selected: params[:assignee_id],
placeholder: 'Assignee', class: 'trigger-submit', any_user: true, null_user: true, first_user: true)
placeholder: 'Assignee', class: 'trigger-submit', any_user: true, null_user: true, first_user: true, current_user: true)
.filter-item.inline
= users_select_tag(:author_id, selected: params[:author_id],
placeholder: 'Author', class: 'trigger-submit', any_user: true, first_user: true)
placeholder: 'Author', class: 'trigger-submit', any_user: true, first_user: true, current_user: true)
.filter-item.inline.milestone-filter
= select_tag('milestone_title', projects_milestones_options,
......@@ -60,7 +60,7 @@
.issues_bulk_update.hide
= form_tag bulk_update_namespace_project_issues_path(@project.namespace, @project), method: :post do
= select_tag('update[state_event]', options_for_select([['Open', 'reopen'], ['Closed', 'close']]), prompt: "Status", class: 'form-control')
= users_select_tag('update[assignee_id]', placeholder: 'Assignee', null_user: true)
= users_select_tag('update[assignee_id]', placeholder: 'Assignee', null_user: true, first_user: true, current_user: true)
= select_tag('update[milestone_id]', bulk_update_milestone_options, prompt: "Milestone")
= hidden_field_tag 'update[issues_ids]', []
= hidden_field_tag :state_event, params[:state_event]
......
......@@ -47,7 +47,8 @@
.col-sm-10
= users_select_tag("#{issuable.class.model_name.param_key}[assignee_id]",
placeholder: 'Select a user', class: 'custom-form-control', null_user: true,
selected: issuable.assignee_id, project: @target_project || @project)
selected: issuable.assignee_id, project: @target_project || @project,
first_user: true, current_user: true)
&nbsp;
= link_to 'Assign to me', '#', class: 'btn assign-to-me-link'
.form-group
......
......@@ -27,3 +27,9 @@ Feature: Admin Groups
When I visit admin group page
And I remove user "John Doe" from group
Then I should not see "John Doe" in team list
@javascript
Scenario: Invite user to a group by e-mail
When I visit admin group page
When I select user "johndoe@gitlab.com" from user list as "Reporter"
Then I should see "johndoe@gitlab.com" in team list in every project as "Reporter"
......@@ -44,6 +44,14 @@ class Spinach::Features::AdminGroups < Spinach::FeatureSteps
click_button "Add users to group"
end
When 'I select user "johndoe@gitlab.com" from user list as "Reporter"' do
select2('johndoe@gitlab.com', from: "#user_ids", multiple: true)
page.within "#new_project_member" do
select "Reporter", from: "access_level"
end
click_button "Add users to group"
end
step 'I should see "John Doe" in team list in every project as "Reporter"' do
page.within ".group-users-list" do
expect(page).to have_content "John Doe"
......@@ -51,6 +59,13 @@ class Spinach::Features::AdminGroups < Spinach::FeatureSteps
end
end
step 'I should see "johndoe@gitlab.com" in team list in every project as "Reporter"' do
page.within ".group-users-list" do
expect(page).to have_content "johndoe@gitlab.com (invited)"
expect(page).to have_content "Reporter"
end
end
step 'I should be all groups' do
Group.all.each do |group|
expect(page).to have_content group.name
......
......@@ -74,7 +74,7 @@ describe AutocompleteController do
describe 'GET #users with project ID' do
before do
get(:users, project_id: project.id)
get(:users, project_id: project.id, current_user: true)
end
it { expect(body).to be_kind_of(Array) }
......
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