Commit 091b15b7 authored by Diego Silva's avatar Diego Silva

Change DetectRepositoryLanguagesWorker to not receive user

Fixes #60425
parent 389de5e1
......@@ -465,7 +465,7 @@ class Repository
def after_import
expire_content_cache
DetectRepositoryLanguagesWorker.perform_async(project.id, project.owner.id)
DetectRepositoryLanguagesWorker.perform_async(project.id)
end
# Runs code after a new commit has been pushed.
......
......@@ -48,7 +48,7 @@ module Git
def enqueue_detect_repository_languages
return unless default_branch?
DetectRepositoryLanguagesWorker.perform_async(project.id, current_user.id)
DetectRepositoryLanguagesWorker.perform_async(project.id)
end
# Only stop environments if the ref is a branch that is being deleted
......
......@@ -11,7 +11,7 @@ module Projects
def perform_language_detection
if persisted_repository_languages.blank?
::DetectRepositoryLanguagesWorker.perform_async(project.id, current_user.id)
::DetectRepositoryLanguagesWorker.perform_async(project.id)
else
project.update_column(:detected_repository_languages, true)
end
......
......@@ -12,13 +12,12 @@ class DetectRepositoryLanguagesWorker
attr_reader :project
# rubocop: disable CodeReuse/ActiveRecord
def perform(project_id, user_id)
def perform(project_id, user_id = nil)
@project = Project.find_by(id: project_id)
user = User.find_by(id: user_id)
return unless project && user
return unless project
try_obtain_lease do
::Projects::DetectRepositoryLanguagesService.new(project, user).execute
::Projects::DetectRepositoryLanguagesService.new(project).execute
end
end
# 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
end
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
let(:project) { create(:project, :repository, detected_repository_languages: true) }
let!(:repository_language) { create(:repository_language, project: project) }
......
......@@ -5,7 +5,7 @@ require 'spec_helper'
describe Projects::DetectRepositoryLanguagesService, :clean_gitlab_redis_shared_state do
set(:project) { create(:project, :repository) }
subject { described_class.new(project, project.owner) }
subject { described_class.new(project) }
describe '#execute' do
context 'without previous detection' do
......
......@@ -10,7 +10,7 @@ describe Projects::RepositoryLanguagesService do
context 'when a project is without detected programming languages' 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([])
end
end
......@@ -19,7 +19,7 @@ describe Projects::RepositoryLanguagesService do
let!(:repository_language) { create(:repository_language, project: project) }
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
......
......@@ -4,7 +4,6 @@ require 'spec_helper'
describe DetectRepositoryLanguagesWorker do
set(:project) { create(:project) }
let(:user) { project.owner }
subject { described_class.new }
......@@ -14,19 +13,13 @@ describe DetectRepositoryLanguagesWorker do
allow(::Projects::DetectRepositoryLanguagesService).to receive(:new).and_return(service)
expect(service).to receive(:execute)
subject.perform(project.id, user.id)
subject.perform(project.id)
end
context 'when invalid ids are used' do
it 'does not raise when the project could not be found' do
expect do
subject.perform(-1, user.id)
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)
subject.perform(-1)
end.not_to raise_error
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