Commit 7bca902a authored by Douwe Maan's avatar Douwe Maan

Fall back on ghost user when deploy key user is not set

parent 59d910f2
...@@ -27,6 +27,10 @@ class DeployKey < Key ...@@ -27,6 +27,10 @@ class DeployKey < Key
self.private? self.private?
end end
def user
super || User.ghost
end
def has_access_to?(project) def has_access_to?(project)
deploy_keys_project_for(project).present? deploy_keys_project_for(project).present?
end end
......
...@@ -99,8 +99,6 @@ module Gitlab ...@@ -99,8 +99,6 @@ module Gitlab
end end
def check_active_user! def check_active_user!
return if deploy_key?
if user && !user_access.allowed? if user && !user_access.allowed?
raise UnauthorizedError, ERROR_MESSAGES[:account_blocked] raise UnauthorizedError, ERROR_MESSAGES[:account_blocked]
end end
...@@ -219,7 +217,7 @@ module Gitlab ...@@ -219,7 +217,7 @@ module Gitlab
raise UnauthorizedError, ERROR_MESSAGES[:read_only] raise UnauthorizedError, ERROR_MESSAGES[:read_only]
end end
if deploy_key if deploy_key?
unless deploy_key.can_push_to?(project) unless deploy_key.can_push_to?(project)
raise UnauthorizedError, ERROR_MESSAGES[:deploy_key_upload] raise UnauthorizedError, ERROR_MESSAGES[:deploy_key_upload]
end end
...@@ -309,8 +307,10 @@ module Gitlab ...@@ -309,8 +307,10 @@ module Gitlab
case actor case actor
when User when User
actor actor
when DeployKey
nil
when Key when Key
actor.user unless actor.is_a?(DeployKey) actor.user
when :ci when :ci
nil nil
end end
......
...@@ -17,4 +17,25 @@ describe DeployKey, :mailer do ...@@ -17,4 +17,25 @@ describe DeployKey, :mailer do
should_not_email(user) should_not_email(user)
end end
end end
describe '#user' do
let(:deploy_key) { create(:deploy_key) }
let(:user) { create(:user) }
context 'when user is set' do
before do
deploy_key.user = user
end
it 'returns the user' do
expect(deploy_key.user).to be(user)
end
end
context 'when user is not set' do
it 'returns the ghost user' do
expect(deploy_key.user).to eq(User.ghost)
end
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment