From 1436423a490fe9f4c1ee1ccb8ecaa6240eed2906 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Thu, 2 Aug 2018 11:17:00 -0700 Subject: [PATCH] Fix failing 500 errors when deploy tokens are used to clone A DeployToken responds to `:username`, but it returns the username for the token, not a User object. Don't attempt to log user activity in this case. Closes gitlab-org/gitlab-ee#7080 --- app/services/users/activity_service.rb | 1 + spec/services/users/activity_service_spec.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/app/services/users/activity_service.rb b/app/services/users/activity_service.rb index 822df6c646a..db03ba8756f 100644 --- a/app/services/users/activity_service.rb +++ b/app/services/users/activity_service.rb @@ -11,6 +11,7 @@ module Users author.user end + @user = nil unless @user.is_a?(User) @activity = activity end diff --git a/spec/services/users/activity_service_spec.rb b/spec/services/users/activity_service_spec.rb index f20849e6924..719b4adf212 100644 --- a/spec/services/users/activity_service_spec.rb +++ b/spec/services/users/activity_service_spec.rb @@ -28,6 +28,18 @@ describe Users::ActivityService do end end + context 'when a bad object is passed' do + let(:fake_object) { double(username: 'hello') } + + it 'does not record activity' do + service = described_class.new(fake_object, 'pull') + + expect(service).not_to receive(:record_activity) + + service.execute + end + end + context 'when last activity is today' do let(:last_activity_on) { Date.today }