Commit 712dccd4 authored by Nick Thomas's avatar Nick Thomas

Merge branch 'fix-60425' into 'master'

Change DetectRepositoryLanguagesWorker to not receive user

Closes #60425

See merge request gitlab-org/gitlab-ce!28091
parents 89a4f78b 091b15b7
...@@ -465,7 +465,7 @@ class Repository ...@@ -465,7 +465,7 @@ class Repository
def after_import def after_import
expire_content_cache expire_content_cache
DetectRepositoryLanguagesWorker.perform_async(project.id, project.owner.id) DetectRepositoryLanguagesWorker.perform_async(project.id)
end end
# Runs code after a new commit has been pushed. # Runs code after a new commit has been pushed.
......
...@@ -48,7 +48,7 @@ module Git ...@@ -48,7 +48,7 @@ module Git
def enqueue_detect_repository_languages def enqueue_detect_repository_languages
return unless default_branch? return unless default_branch?
DetectRepositoryLanguagesWorker.perform_async(project.id, current_user.id) DetectRepositoryLanguagesWorker.perform_async(project.id)
end end
# Only stop environments if the ref is a branch that is being deleted # Only stop environments if the ref is a branch that is being deleted
......
...@@ -11,7 +11,7 @@ module Projects ...@@ -11,7 +11,7 @@ module Projects
def perform_language_detection def perform_language_detection
if persisted_repository_languages.blank? if persisted_repository_languages.blank?
::DetectRepositoryLanguagesWorker.perform_async(project.id, current_user.id) ::DetectRepositoryLanguagesWorker.perform_async(project.id)
else else
project.update_column(:detected_repository_languages, true) project.update_column(:detected_repository_languages, true)
end end
......
...@@ -12,13 +12,12 @@ class DetectRepositoryLanguagesWorker ...@@ -12,13 +12,12 @@ class DetectRepositoryLanguagesWorker
attr_reader :project attr_reader :project
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def perform(project_id, user_id) def perform(project_id, user_id = nil)
@project = Project.find_by(id: project_id) @project = Project.find_by(id: project_id)
user = User.find_by(id: user_id) return unless project
return unless project && user
try_obtain_lease do try_obtain_lease do
::Projects::DetectRepositoryLanguagesService.new(project, user).execute ::Projects::DetectRepositoryLanguagesService.new(project).execute
end end
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
......
---
title: "Fix 500 error when accessing charts with an anonymous user"
merge_request: 28091
author: Diego Silva
type: fixed
...@@ -28,6 +28,21 @@ describe Projects::GraphsController do ...@@ -28,6 +28,21 @@ describe Projects::GraphsController do
end end
describe 'charts' do describe 'charts' do
context 'with an anonymous user' do
let(:project) { create(:project, :repository, :public) }
before do
sign_out(user)
end
it 'renders charts with 200 status code' do
get(:charts, params: { namespace_id: project.namespace.path, project_id: project.path, id: 'master' })
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:charts)
end
end
context 'when languages were previously detected' do context 'when languages were previously detected' do
let(:project) { create(:project, :repository, detected_repository_languages: true) } let(:project) { create(:project, :repository, detected_repository_languages: true) }
let!(:repository_language) { create(:repository_language, project: project) } let!(:repository_language) { create(:repository_language, project: project) }
......
...@@ -5,7 +5,7 @@ require 'spec_helper' ...@@ -5,7 +5,7 @@ require 'spec_helper'
describe Projects::DetectRepositoryLanguagesService, :clean_gitlab_redis_shared_state do describe Projects::DetectRepositoryLanguagesService, :clean_gitlab_redis_shared_state do
set(:project) { create(:project, :repository) } set(:project) { create(:project, :repository) }
subject { described_class.new(project, project.owner) } subject { described_class.new(project) }
describe '#execute' do describe '#execute' do
context 'without previous detection' do context 'without previous detection' do
......
...@@ -10,7 +10,7 @@ describe Projects::RepositoryLanguagesService do ...@@ -10,7 +10,7 @@ describe Projects::RepositoryLanguagesService do
context 'when a project is without detected programming languages' do context 'when a project is without detected programming languages' do
it 'schedules a worker and returns the empty result' do it 'schedules a worker and returns the empty result' do
expect(::DetectRepositoryLanguagesWorker).to receive(:perform_async).with(project.id, project.owner.id) expect(::DetectRepositoryLanguagesWorker).to receive(:perform_async).with(project.id)
expect(service.execute).to eq([]) expect(service.execute).to eq([])
end end
end end
...@@ -19,7 +19,7 @@ describe Projects::RepositoryLanguagesService do ...@@ -19,7 +19,7 @@ describe Projects::RepositoryLanguagesService do
let!(:repository_language) { create(:repository_language, project: project) } let!(:repository_language) { create(:repository_language, project: project) }
it 'does not schedule a worker and returns the detected languages' do it 'does not schedule a worker and returns the detected languages' do
expect(::DetectRepositoryLanguagesWorker).not_to receive(:perform_async).with(project.id, project.owner.id) expect(::DetectRepositoryLanguagesWorker).not_to receive(:perform_async).with(project.id)
languages = service.execute languages = service.execute
......
...@@ -4,7 +4,6 @@ require 'spec_helper' ...@@ -4,7 +4,6 @@ require 'spec_helper'
describe DetectRepositoryLanguagesWorker do describe DetectRepositoryLanguagesWorker do
set(:project) { create(:project) } set(:project) { create(:project) }
let(:user) { project.owner }
subject { described_class.new } subject { described_class.new }
...@@ -14,19 +13,13 @@ describe DetectRepositoryLanguagesWorker do ...@@ -14,19 +13,13 @@ describe DetectRepositoryLanguagesWorker do
allow(::Projects::DetectRepositoryLanguagesService).to receive(:new).and_return(service) allow(::Projects::DetectRepositoryLanguagesService).to receive(:new).and_return(service)
expect(service).to receive(:execute) expect(service).to receive(:execute)
subject.perform(project.id, user.id) subject.perform(project.id)
end end
context 'when invalid ids are used' do context 'when invalid ids are used' do
it 'does not raise when the project could not be found' do it 'does not raise when the project could not be found' do
expect do expect do
subject.perform(-1, user.id) subject.perform(-1)
end.not_to raise_error
end
it 'does not raise when the user could not be found' do
expect do
subject.perform(project.id, -1)
end.not_to raise_error end.not_to raise_error
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