Skip to content

Commit d19582b

Browse files
committed
do away with user-merge warnings when unnecessary
refs #CNVS-1959 remove session interaction, everything is now tracked with parameters. Also removed the "confirm_merge" action which does not appear to be used. Test Plan: 1) login as an admin 2) try to merge two users together 3) as long as the users being merged are not the same user, you should not get a warning about how the user cannot be merged with itself. (naturally, if you DID try to merge a user into itself, you absolutely should receive that warning) Change-Id: I98fdb925b3f6d14b4de98737f9af8b6093312847 Reviewed-on: https://gerrit.instructure.com/16692 Reviewed-by: Brian Palmer <brianp@instructure.com> Tested-by: Jenkins <jenkins@instructure.com> QA-Review: Clare Hetherington <clare@instructure.com>
1 parent 4581302 commit d19582b

7 files changed

Lines changed: 97 additions & 137 deletions

File tree

app/controllers/users_controller.rb

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ class UsersController < ApplicationController
8585
include LinkedIn
8686
include DeliciousDiigo
8787
include SearchHelper
88-
before_filter :require_user, :only => [:grades, :confirm_merge, :merge, :kaltura_session, :ignore_item, :ignore_stream_item, :close_notification, :mark_avatar_image, :user_dashboard, :toggle_dashboard, :masquerade, :external_tool]
88+
before_filter :require_user, :only => [:grades, :merge, :kaltura_session, :ignore_item, :ignore_stream_item, :close_notification, :mark_avatar_image, :user_dashboard, :toggle_dashboard, :masquerade, :external_tool]
8989
before_filter :require_registered_user, :only => [:delete_user_service, :create_user_service]
90-
before_filter :reject_student_view_student, :only => [:delete_user_service, :create_user_service, :confirm_merge, :merge, :user_dashboard, :masquerade]
90+
before_filter :reject_student_view_student, :only => [:delete_user_service, :create_user_service, :merge, :user_dashboard, :masquerade]
9191
before_filter :require_self_registration, :only => [:new, :create]
9292

9393
def grades
@@ -932,7 +932,7 @@ def media_download
932932
end
933933

934934
def merge
935-
@user_about_to_go_away = User.find_by_id(session[:merge_user_id]) if session[:merge_user_id].present?
935+
@user_about_to_go_away = User.find(params[:user_id])
936936

937937
if params[:new_user_id] && @true_user = User.find_by_id(params[:new_user_id])
938938
if @true_user.grants_right?(@current_user, session, :manage_logins) && @user_about_to_go_away.grants_right?(@current_user, session, :manage_logins)
@@ -947,11 +947,11 @@ def merge
947947
if @user_about_to_go_away && @user_that_will_still_be_around
948948
@user_about_to_go_away.move_to_user(@user_that_will_still_be_around)
949949
@user_that_will_still_be_around.touch
950-
session.delete(:merge_user_id)
951950
flash[:notice] = t('user_merge_success', "User merge succeeded! %{first_user} and %{second_user} are now one and the same.", :first_user => @user_that_will_still_be_around.name, :second_user => @user_about_to_go_away.name)
952951
else
953952
flash[:error] = t('user_merge_fail', "User merge failed. Please make sure you have proper permission and try again.")
954953
end
954+
955955
if @user_that_will_still_be_around == @current_user
956956
redirect_to user_profile_url(@current_user)
957957
elsif @user_that_will_still_be_around
@@ -963,47 +963,38 @@ def merge
963963

964964
def admin_merge
965965
@user = User.find(params[:user_id])
966-
pending_user_id = params[:pending_user_id] || session[:pending_user_id]
967-
pending_other_error = get_pending_user_and_error(pending_user_id, params[:pending_user_id])
966+
pending_other_error = get_pending_user_and_error(params[:pending_user_id])
968967
@other_user = User.find_by_id(params[:new_user_id]) if params[:new_user_id].present?
969968
if authorized_action(@user, @current_user, :manage_logins)
970969
flash[:error] = pending_other_error if pending_other_error.present?
970+
971971
if @user && (params[:clear] || !@pending_other_user)
972-
session[:pending_user_id] = @user.id
973972
@pending_other_user = nil
974973
end
975-
if @other_user && @other_user.grants_right?(@current_user, session, :manage_logins)
976-
session[:merge_user_id] = @user.id
977-
session.delete(:pending_user_id)
978-
else
974+
975+
unless @other_user && @other_user.grants_right?(@current_user, session, :manage_logins)
979976
@other_user = nil
980977
end
978+
981979
render :action => 'admin_merge'
982980
end
983981
end
984982

985-
def get_pending_user_and_error(pending_user_id, entered_user_id)
983+
def get_pending_user_and_error(pending_user_id)
986984
pending_other_error = nil
987-
@pending_other_user = api_find_all(User, [pending_user_id]).first if pending_user_id.present?
988-
@pending_other_user = nil unless @pending_other_user.try(:grants_right?, @current_user, session, :manage_logins)
989-
if @pending_other_user == @user
990-
@pending_other_user = nil
991-
pending_other_error = t('cant_self_merge', "You can't merge an account with itself.")
992-
elsif @pending_other_user.blank? && entered_user_id.present? && pending_other_error.blank?
993-
pending_other_error = t('user_not_found', "No active user with that ID was found.")
994-
end
995-
return pending_other_error
996-
end
997985

998-
def confirm_merge
999-
@user = User.find_by_id(session[:merge_user_id]) if session[:merge_user_id].present?
1000-
if @user && @user != @current_user
1001-
render :action => 'confirm_merge'
1002-
else
1003-
session[:merge_user_id] = @current_user.id
1004-
store_location(user_confirm_merge_url(@current_user.id))
1005-
render :action => 'merge'
986+
if pending_user_id.present?
987+
@pending_other_user = api_find_all(User, [pending_user_id]).first
988+
@pending_other_user = nil unless @pending_other_user.try(:grants_right?, @current_user, session, :manage_logins)
989+
if @pending_other_user == @user
990+
@pending_other_user = nil
991+
pending_other_error = t('cant_self_merge', "You can't merge an account with itself.")
992+
elsif @pending_other_user.blank? && pending_other_error.blank?
993+
pending_other_error = t('user_not_found', "No active user with that ID was found.")
994+
end
1006995
end
996+
997+
pending_other_error
1007998
end
1008999

10091000
def assignments_needing_grading

app/views/users/admin_merge.html.erb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@
6565
</span>
6666
<% else %>
6767
<p><%= t('merge_user_initial_instructions', "You've selected to merge the user, %{user_name} (%{user_email}) with another account.
68-
You can search for the user you'd like to merge with this user using the form below, or
69-
just navigate to that user's page and click \"Merge User\" again to merge someone else with this
70-
user.", :user_name => @user.name, :user_email => @user.email) %></p>
68+
You can search for the user you'd like to merge with this user using the form below.", :user_name => @user.name, :user_email => @user.email) %></p>
7169
<table>
7270
<tr>
7371
<td style="vertical-align: top; padding: 10px 30px 10px;">

app/views/users/confirm_merge.html.erb

Lines changed: 0 additions & 30 deletions
This file was deleted.

config/routes.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,6 @@ def add_zip_file_imports(context)
529529
user.assignments_needing_grading 'assignments_needing_grading', :controller => 'users', :action => 'assignments_needing_grading'
530530
user.assignments_needing_submitting 'assignments_needing_submitting', :controller => 'users', :action => 'assignments_needing_submitting'
531531
user.admin_merge 'admin_merge', :controller => 'users', :action => 'admin_merge', :conditions => {:method => :get}
532-
user.confirm_merge 'merge', :controller => 'users', :action => 'confirm_merge', :conditions => {:method => :get}
533532
user.merge 'merge', :controller => 'users', :action => 'merge', :conditions => {:method => :post}
534533
user.grades 'grades', :controller => 'users', :action => 'grades'
535534
user.resources :user_notes

spec/controllers/users_controller_spec.rb

Lines changed: 65 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -372,32 +372,49 @@
372372
end
373373

374374
context 'account admin creating users' do
375-
it "should create a pre_registered user (in the correct account)" do
376-
account = Account.create!
377-
user_with_pseudonym(:account => account)
378-
account.add_user(@user)
379-
user_session(@user, @pseudonym)
380-
post 'create', :format => 'json', :account_id => account.id, :pseudonym => { :unique_id => 'jacob@instructure.com', :sis_user_id => 'testsisid' }, :user => { :name => 'Jacob Fugal' }
381-
response.should be_success
382-
p = Pseudonym.find_by_unique_id('jacob@instructure.com')
383-
p.account_id.should == account.id
384-
p.should be_active
385-
p.sis_user_id.should == 'testsisid'
386-
p.user.should be_pre_registered
387-
end
388375

389-
it "should create users with non-email pseudonyms" do
390-
account = Account.create!
391-
user_with_pseudonym(:account => account)
392-
account.add_user(@user)
393-
user_session(@user, @pseudonym)
394-
post 'create', :format => 'json', :account_id => account.id, :pseudonym => { :unique_id => 'jacob', :sis_user_id => 'testsisid' }, :user => { :name => 'Jacob Fugal' }
395-
response.should be_success
396-
p = Pseudonym.find_by_unique_id('jacob')
397-
p.account_id.should == account.id
398-
p.should be_active
399-
p.sis_user_id.should == 'testsisid'
400-
p.user.should be_pre_registered
376+
describe 'successfully' do
377+
let!(:account) { Account.create! }
378+
379+
before do
380+
user_with_pseudonym(:account => account)
381+
account.add_user(@user)
382+
user_session(@user, @pseudonym)
383+
end
384+
385+
it "should create a pre_registered user (in the correct account)" do
386+
post 'create', :format => 'json', :account_id => account.id, :pseudonym => { :unique_id => 'jacob@instructure.com', :sis_user_id => 'testsisid' }, :user => { :name => 'Jacob Fugal' }
387+
response.should be_success
388+
p = Pseudonym.find_by_unique_id('jacob@instructure.com')
389+
p.account_id.should == account.id
390+
p.should be_active
391+
p.sis_user_id.should == 'testsisid'
392+
p.user.should be_pre_registered
393+
end
394+
395+
it "should create users with non-email pseudonyms" do
396+
post 'create', :format => 'json', :account_id => account.id, :pseudonym => { :unique_id => 'jacob', :sis_user_id => 'testsisid' }, :user => { :name => 'Jacob Fugal' }
397+
response.should be_success
398+
p = Pseudonym.find_by_unique_id('jacob')
399+
p.account_id.should == account.id
400+
p.should be_active
401+
p.sis_user_id.should == 'testsisid'
402+
p.user.should be_pre_registered
403+
end
404+
405+
406+
it "should not require acceptance of the terms or birthdate" do
407+
post 'create', :account_id => account.id, :pseudonym => { :unique_id => 'jacob@instructure.com' }, :user => { :name => 'Jacob Fugal' }
408+
response.should be_success
409+
end
410+
411+
it "should allow setting a password" do
412+
post 'create', :account_id => account.id, :pseudonym => { :unique_id => 'jacob@instructure.com', :password => 'asdfasdf', :password_confirmation => 'asdfasdf' }, :user => { :name => 'Jacob Fugal' }
413+
u = User.find_by_name 'Jacob Fugal'
414+
u.should be_present
415+
u.pseudonym.should_not be_password_auto_generated
416+
end
417+
401418
end
402419

403420
it "should not allow an admin to set the sis id when creating a user if they don't have privileges to manage sis" do
@@ -447,36 +464,6 @@
447464
p = Pseudonym.find_by_unique_id('jacob@instructure.com')
448465
Message.find(:first, :conditions => { :communication_channel_id => p.user.email_channel.id, :notification_id => notification.id }).should be_nil
449466
end
450-
451-
it "should not require acceptance of the terms" do
452-
account = Account.create!
453-
user_with_pseudonym(:account => account)
454-
account.add_user(@user)
455-
user_session(@user, @pseudonym)
456-
post 'create', :account_id => account.id, :pseudonym => { :unique_id => 'jacob@instructure.com' }, :user => { :name => 'Jacob Fugal' }
457-
response.should be_success
458-
end
459-
460-
it "should not require the birthdate" do
461-
account = Account.create!
462-
user_with_pseudonym(:account => account)
463-
account.add_user(@user)
464-
user_session(@user, @pseudonym)
465-
post 'create', :account_id => account.id, :pseudonym => { :unique_id => 'jacob@instructure.com' }, :user => { :name => 'Jacob Fugal' }
466-
response.should be_success
467-
end
468-
469-
it "should allow setting a password" do
470-
account = Account.create!
471-
user_with_pseudonym(:account => account)
472-
account.add_user(@user)
473-
user_session(@user, @pseudonym)
474-
post 'create', :account_id => account.id, :pseudonym => { :unique_id => 'jacob@instructure.com', :password => 'lolwtf', :password_confirmation => 'lolwtf' }, :user => { :name => 'Jacob Fugal' }
475-
response.should be_success
476-
u = User.find_by_name 'Jacob Fugal'
477-
u.should be_present
478-
u.pseudonym.should_not be_password_auto_generated
479-
end
480467
end
481468
end
482469

@@ -643,11 +630,32 @@
643630
end
644631

645632
describe "GET 'admin_merge'" do
646-
it "should not allow you to view any user by id" do
633+
let(:account) { Account.create! }
634+
635+
before do
647636
account_admin_user
648637
user_session(@admin)
649-
user_with_pseudonym(:account => Account.create!)
638+
end
639+
640+
describe 'as site admin' do
641+
before { Account.site_admin.add_user(@admin) }
642+
643+
it 'warns about merging a user with itself' do
644+
user = User.create!
645+
get 'admin_merge', :user_id => user.id, :pending_user_id => user.id
646+
flash[:error].should == 'You can\'t merge an account with itself.'
647+
end
650648

649+
it 'does not issue warning if the users are different' do
650+
user = User.create!
651+
other_user = User.create!
652+
get 'admin_merge', :user_id => user.id, :pending_user_id => other_user.id
653+
flash[:error].should be_nil
654+
end
655+
end
656+
657+
it "should not allow you to view any user by id" do
658+
user_with_pseudonym(:account => account)
651659
get 'admin_merge', :user_id => @admin.id, :pending_user_id => @user.id
652660
response.should be_success
653661
assigns[:pending_other_user].should be_nil

spec/integration/users_controller_spec.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,21 +253,15 @@ def disable_avatars!
253253
response.should be_success
254254
assigns['pending_other_user'].should == @admin
255255
assigns['other_user'].should be_nil
256-
session[:pending_user_id].should be_nil
257-
session[:merge_user_id].should be_nil
258256

259257
get user_admin_merge_url(@user, :new_user_id => @admin.id)
260258
response.should be_success
261259
assigns['pending_other_user'].should be_nil
262260
assigns['other_user'].should == @admin
263-
session[:pending_user_id].should be_nil
264-
session[:merge_user_id].should == @user.id
265261

266262
post user_merge_url(@user, :new_user_id => @admin.id)
267263
response.should redirect_to(user_profile_url(@admin))
268264

269-
session[:pending_user_id].should be_nil
270-
session[:merge_user_id].should be_nil
271265
@user.reload.should be_deleted
272266
@admin.reload.should be_registered
273267
@admin.pseudonyms.count.should == 2

spec/selenium/users_spec.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@
7979
end
8080

8181
context "admin merge" do
82-
def setup_user_merge(users)
83-
2.times { |i| get "/users/#{users[i].id}/admin_merge" }
82+
def setup_user_merge(from_user, into_user)
83+
get "/users/#{from_user.id}/admin_merge"
84+
f('#manual_user_id').send_keys(into_user.id)
85+
expect_new_page_load { f('button[type="submit"]').click }
8486
end
8587

8688
def reload_users(users)
@@ -113,19 +115,17 @@ def validate_login_info(user_id)
113115
@users = [@student_1, @student_2]
114116
end
115117

116-
it "should merge user a with user b with navigate to another user function" do
117-
setup_user_merge(@users)
118+
it "should merge user a with user b" do
119+
setup_user_merge(@student_2, @student_1)
118120
submit_merge
119121
reload_users(@users)
120122
@student_1.workflow_state.should == 'registered'
121123
@student_2.workflow_state.should == 'deleted'
122124
validate_login_info(@student_1_id)
123125
end
124126

125-
it "should merge user b with user a with enter user id function" do
126-
get "/users/#{@student_1.id}/admin_merge"
127-
f('#manual_user_id').send_keys(@student_2.id)
128-
expect_new_page_load { f('button[type="submit"]').click }
127+
it "should merge user b with user a" do
128+
setup_user_merge(@student_1, @student_2)
129129
submit_merge
130130
reload_users(@users)
131131
@student_1.workflow_state.should == 'deleted'
@@ -134,7 +134,7 @@ def validate_login_info(user_id)
134134
end
135135

136136
it "should validate switching the users to merge" do
137-
setup_user_merge(@users)
137+
setup_user_merge(@student_2, @student_1)
138138
user_names = ff('.result td')
139139
user_names[0].should include_text(@student_2.name)
140140
user_names[1].should include_text(@student_1.name)
@@ -151,7 +151,7 @@ def validate_login_info(user_id)
151151
end
152152

153153
it "should cancel a merge and validate both users still exist" do
154-
setup_user_merge(@users)
154+
setup_user_merge(@student_2, @student_1)
155155
expect_new_page_load { f('#prepare_to_merge').click }
156156
expect_new_page_load { f('.button-secondary').click }
157157
f('#courses_menu_item').should be_displayed

0 commit comments

Comments
 (0)