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
self.private?
end
def user
super || User.ghost
end
def has_access_to?(project)
deploy_keys_project_for(project).present?
end
......
......@@ -99,8 +99,6 @@ module Gitlab
end
def check_active_user!
return if deploy_key?
if user && !user_access.allowed?
raise UnauthorizedError, ERROR_MESSAGES[:account_blocked]
end
......@@ -219,7 +217,7 @@ module Gitlab
raise UnauthorizedError, ERROR_MESSAGES[:read_only]
end
if deploy_key
if deploy_key?
unless deploy_key.can_push_to?(project)
raise UnauthorizedError, ERROR_MESSAGES[:deploy_key_upload]
end
......@@ -309,8 +307,10 @@ module Gitlab
case actor
when User
actor
when DeployKey
nil
when Key
actor.user unless actor.is_a?(DeployKey)
actor.user
when :ci
nil
end
......
......@@ -17,4 +17,25 @@ describe DeployKey, :mailer do
should_not_email(user)
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
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