summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2016-11-22 16:26:34 +0000
committerSean McGivern <sean@mcgivern.me.uk>2016-11-22 16:26:34 +0000
commit45d69bf120604edf3ec955949cd66576a8fe0d23 (patch)
treedcc936eb35d091d60fd7f92145b5ac916d49ce93
parent7902395f1f97f5adcb89491b7ff18c05d99e8fe0 (diff)
parent8dd9a8b6e00cbd91f8455218397c8da716fc9b00 (diff)
downloadgitlab-ce-45d69bf120604edf3ec955949cd66576a8fe0d23.tar.gz
Merge branch '24576_cant_stop_impersonating' into 'master'
Allow admins to stop impersonating users without e-mail addresses Closes #24576 See merge request !7550
-rw-r--r--app/controllers/application_controller.rb2
-rw-r--r--changelogs/unreleased/24576_cant_stop_impersonating.yml4
-rw-r--r--spec/controllers/admin/impersonations_controller_spec.rb28
3 files changed, 26 insertions, 8 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 517ad4f03f3..2713c0f1dc8 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -224,7 +224,7 @@ class ApplicationController < ActionController::Base
end
def require_email
- if current_user && current_user.temp_oauth_email?
+ if current_user && current_user.temp_oauth_email? && session[:impersonator_id].nil?
redirect_to profile_path, notice: 'Please complete your profile with email address' and return
end
end
diff --git a/changelogs/unreleased/24576_cant_stop_impersonating.yml b/changelogs/unreleased/24576_cant_stop_impersonating.yml
new file mode 100644
index 00000000000..8fa6eeca756
--- /dev/null
+++ b/changelogs/unreleased/24576_cant_stop_impersonating.yml
@@ -0,0 +1,4 @@
+---
+title: Allow admins to stop impersonating users without e-mail addresses
+merge_request: 7550
+author: Oren Kanner
diff --git a/spec/controllers/admin/impersonations_controller_spec.rb b/spec/controllers/admin/impersonations_controller_spec.rb
index 8be662974a0..8f1f0ba89ff 100644
--- a/spec/controllers/admin/impersonations_controller_spec.rb
+++ b/spec/controllers/admin/impersonations_controller_spec.rb
@@ -76,18 +76,32 @@ describe Admin::ImpersonationsController do
end
context "when the impersonator is not blocked" do
- it "redirects to the impersonated user's page" do
- expect(Gitlab::AppLogger).to receive(:info).with("User #{impersonator.username} has stopped impersonating #{user.username}").and_call_original
+ shared_examples_for "successfully stops impersonating" do
+ it "redirects to the impersonated user's page" do
+ expect(Gitlab::AppLogger).to receive(:info).with("User #{impersonator.username} has stopped impersonating #{user.username}").and_call_original
- delete :destroy
+ delete :destroy
+
+ expect(response).to redirect_to(admin_user_path(user))
+ end
+
+ it "signs us in as the impersonator" do
+ delete :destroy
- expect(response).to redirect_to(admin_user_path(user))
+ expect(warden.user).to eq(impersonator)
+ end
end
- it "signs us in as the impersonator" do
- delete :destroy
+ # base case
+ it_behaves_like "successfully stops impersonating"
+
+ context "and the user has a temporary oauth e-mail address" do
+ before do
+ allow(user).to receive(:temp_oauth_email?).and_return(true)
+ allow(controller).to receive(:current_user).and_return(user)
+ end
- expect(warden.user).to eq(impersonator)
+ it_behaves_like "successfully stops impersonating"
end
end
end