From 37425618bc5a15bb58ed6695d4932d309d452cb2 Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Mon, 23 Jun 2014 09:45:26 +0200 Subject: Add option for admin to remove users secondary emails. --- app/controllers/admin/users_controller.rb | 10 ++++++++++ app/views/admin/users/show.html.haml | 2 ++ config/routes.rb | 1 + 3 files changed, 13 insertions(+) diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 5ecdfbd807e..f0040bf5e87 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -100,6 +100,16 @@ class Admin::UsersController < Admin::ApplicationController end end + def remove_email + email = user.emails.find(params[:email_id]) + email.destroy + + respond_to do |format| + format.html { redirect_to :back, notice: "Successfully removed email." } + format.js { render nothing: true } + end + end + protected def user diff --git a/app/views/admin/users/show.html.haml b/app/views/admin/users/show.html.haml index a255c64fc27..0afae987a39 100644 --- a/app/views/admin/users/show.html.haml +++ b/app/views/admin/users/show.html.haml @@ -44,6 +44,8 @@ %li %span.light Secondary email: %strong= email.email + = link_to remove_email_admin_user_path(@user, email), data: { confirm: "Are you sure you want to remove #{email.email}?" }, method: :delete, class: "btn-tiny btn btn-remove pull-right", title: 'Remove secondary email' do + %i.icon-remove %li %span.light Can create groups: diff --git a/config/routes.rb b/config/routes.rb index 779cbad709c..5b854ed20b9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -68,6 +68,7 @@ Gitlab::Application.routes.draw do put :team_update put :block put :unblock + delete 'remove/:email_id', action: 'remove_email', as: 'remove_email' end end -- cgit v1.2.1 From d12c1e90f8f3e9454d2a52f40854dadcdb2d822b Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Mon, 23 Jun 2014 10:39:56 +0200 Subject: Test secondary user email removal. --- app/views/admin/users/show.html.haml | 2 +- features/admin/users.feature | 8 ++++++++ features/steps/admin/users.rb | 19 +++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/app/views/admin/users/show.html.haml b/app/views/admin/users/show.html.haml index 0afae987a39..3c30ccd78b3 100644 --- a/app/views/admin/users/show.html.haml +++ b/app/views/admin/users/show.html.haml @@ -44,7 +44,7 @@ %li %span.light Secondary email: %strong= email.email - = link_to remove_email_admin_user_path(@user, email), data: { confirm: "Are you sure you want to remove #{email.email}?" }, method: :delete, class: "btn-tiny btn btn-remove pull-right", title: 'Remove secondary email' do + = link_to remove_email_admin_user_path(@user, email), data: { confirm: "Are you sure you want to remove #{email.email}?" }, method: :delete, class: "btn-tiny btn btn-remove pull-right", title: 'Remove secondary email', id: "remove_email_#{email.id}" do %i.icon-remove %li diff --git a/features/admin/users.feature b/features/admin/users.feature index ce31aafd290..d8c1288e5f0 100644 --- a/features/admin/users.feature +++ b/features/admin/users.feature @@ -21,3 +21,11 @@ Feature: Admin Users And click edit on my user When I submit modified user Then I see user attributes changed + +@javascript + Scenario: Remove users secondary email + Given I visit admin users page + And I view the user with secondary email + And I see the secondary email + When I click remove secondary email + Then I should not see secondary email anymore diff --git a/features/steps/admin/users.rb b/features/steps/admin/users.rb index 659008dd875..253c4609e82 100644 --- a/features/steps/admin/users.rb +++ b/features/steps/admin/users.rb @@ -44,4 +44,23 @@ class AdminUsers < Spinach::FeatureSteps step 'click edit on my user' do find("#edit_user_#{current_user.id}").click end + + step 'I view the user with secondary email' do + @user_with_secondary_email = User.last + @user_with_secondary_email.emails.new(email: "secondary@example.com") + @user_with_secondary_email.save + visit "/admin/users/#{@user_with_secondary_email.username}" + end + + step 'I see the secondary email' do + page.should have_content "Secondary email: #{@user_with_secondary_email.emails.last.email}" + end + + step 'I click remove secondary email' do + find("#remove_email_#{@user_with_secondary_email.emails.last.id}").click + end + + step 'I should not see secondary email anymore' do + page.should_not have_content "Secondary email:" + end end -- cgit v1.2.1