From 3715a0f29b6758b3075abb6f28ee24c4eb8ed427 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Thu, 20 Aug 2015 21:33:00 -0700 Subject: [PATCH 1/2] Fix bug preventing invite by e-mail This was broken in 70f5291808 as a result of introducing the ability to filter by current user. Closes #2320 --- app/assets/javascripts/users_select.js.coffee | 2 ++ app/controllers/autocomplete_controller.rb | 10 ++++++++-- app/helpers/selects_helper.rb | 4 +++- app/views/shared/issuable/_context.html.haml | 2 +- app/views/shared/issuable/_filter.html.haml | 6 +++--- app/views/shared/issuable/_form.html.haml | 3 ++- features/admin/groups.feature | 6 ++++++ features/steps/admin/groups.rb | 15 +++++++++++++++ spec/controllers/autocomplete_controller_spec.rb | 2 +- 9 files changed, 41 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/users_select.js.coffee b/app/assets/javascripts/users_select.js.coffee index aeeed9ca3cc..9157562a5c5 100644 --- a/app/assets/javascripts/users_select.js.coffee +++ b/app/assets/javascripts/users_select.js.coffee @@ -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) diff --git a/app/controllers/autocomplete_controller.rb b/app/controllers/autocomplete_controller.rb index 5c3ca8e23c9..904d26a39f4 100644 --- a/app/controllers/autocomplete_controller.rb +++ b/app/controllers/autocomplete_controller.rb @@ -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 diff --git a/app/helpers/selects_helper.rb b/app/helpers/selects_helper.rb index 2b99a398049..12fce8db701 100644 --- a/app/helpers/selects_helper.rb +++ b/app/helpers/selects_helper.rb @@ -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 diff --git a/app/views/shared/issuable/_context.html.haml b/app/views/shared/issuable/_context.html.haml index 19e8c31975b..cba18c14568 100644 --- a/app/views/shared/issuable/_context.html.haml +++ b/app/views/shared/issuable/_context.html.haml @@ -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 diff --git a/app/views/shared/issuable/_filter.html.haml b/app/views/shared/issuable/_filter.html.haml index 0e8da8de723..8801f213fd1 100644 --- a/app/views/shared/issuable/_filter.html.haml +++ b/app/views/shared/issuable/_filter.html.haml @@ -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, 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] diff --git a/app/views/shared/issuable/_form.html.haml b/app/views/shared/issuable/_form.html.haml index 3489bf3f191..8a4ae6987fa 100644 --- a/app/views/shared/issuable/_form.html.haml +++ b/app/views/shared/issuable/_form.html.haml @@ -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, + current_user: true)   = link_to 'Assign to me', '#', class: 'btn assign-to-me-link' .form-group diff --git a/features/admin/groups.feature b/features/admin/groups.feature index aa365a6ea1a..973918086a3 100644 --- a/features/admin/groups.feature +++ b/features/admin/groups.feature @@ -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" diff --git a/features/steps/admin/groups.rb b/features/steps/admin/groups.rb index 83a3f48abe3..d27634858a2 100644 --- a/features/steps/admin/groups.rb +++ b/features/steps/admin/groups.rb @@ -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 diff --git a/spec/controllers/autocomplete_controller_spec.rb b/spec/controllers/autocomplete_controller_spec.rb index 3521d690259..aa8d6cb807f 100644 --- a/spec/controllers/autocomplete_controller_spec.rb +++ b/spec/controllers/autocomplete_controller_spec.rb @@ -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) } From 577df6b8ca4532545ac2cad11a693dc976160b36 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Fri, 21 Aug 2015 14:26:57 -0700 Subject: [PATCH 2/2] List the current user first in issuable dropdowns --- app/views/shared/issuable/_filter.html.haml | 2 +- app/views/shared/issuable/_form.html.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/shared/issuable/_filter.html.haml b/app/views/shared/issuable/_filter.html.haml index 8801f213fd1..bcaa48c7a12 100644 --- a/app/views/shared/issuable/_filter.html.haml +++ b/app/views/shared/issuable/_filter.html.haml @@ -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, current_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] diff --git a/app/views/shared/issuable/_form.html.haml b/app/views/shared/issuable/_form.html.haml index 8a4ae6987fa..61df138ad1e 100644 --- a/app/views/shared/issuable/_form.html.haml +++ b/app/views/shared/issuable/_form.html.haml @@ -48,7 +48,7 @@ = 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, - current_user: true) + first_user: true, current_user: true)   = link_to 'Assign to me', '#', class: 'btn assign-to-me-link' .form-group