Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
091b15b7
Commit
091b15b7
authored
May 04, 2019
by
Diego Silva
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change DetectRepositoryLanguagesWorker to not receive user
Fixes #60425
parent
389de5e1
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
31 additions
and
19 deletions
+31
-19
app/models/repository.rb
app/models/repository.rb
+1
-1
app/services/git/branch_push_service.rb
app/services/git/branch_push_service.rb
+1
-1
app/services/projects/repository_languages_service.rb
app/services/projects/repository_languages_service.rb
+1
-1
app/workers/detect_repository_languages_worker.rb
app/workers/detect_repository_languages_worker.rb
+3
-4
changelogs/unreleased/60425-fix-500-when-accessing-charts-with-anonymous-user.yml
...425-fix-500-when-accessing-charts-with-anonymous-user.yml
+5
-0
spec/controllers/projects/graphs_controller_spec.rb
spec/controllers/projects/graphs_controller_spec.rb
+15
-0
spec/services/projects/detect_repository_languages_service_spec.rb
...ices/projects/detect_repository_languages_service_spec.rb
+1
-1
spec/services/projects/repository_languages_service_spec.rb
spec/services/projects/repository_languages_service_spec.rb
+2
-2
spec/workers/detect_repository_languages_worker_spec.rb
spec/workers/detect_repository_languages_worker_spec.rb
+2
-9
No files found.
app/models/repository.rb
View file @
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.
...
...
app/services/git/branch_push_service.rb
View file @
091b15b7
...
@@ -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
...
...
app/services/projects/repository_languages_service.rb
View file @
091b15b7
...
@@ -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
...
...
app/workers/detect_repository_languages_worker.rb
View file @
091b15b7
...
@@ -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
...
...
changelogs/unreleased/60425-fix-500-when-accessing-charts-with-anonymous-user.yml
0 → 100644
View file @
091b15b7
---
title
:
"
Fix
500
error
when
accessing
charts
with
an
anonymous
user"
merge_request
:
28091
author
:
Diego Silva
type
:
fixed
spec/controllers/projects/graphs_controller_spec.rb
View file @
091b15b7
...
@@ -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
)
}
...
...
spec/services/projects/detect_repository_languages_service_spec.rb
View file @
091b15b7
...
@@ -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
...
...
spec/services/projects/repository_languages_service_spec.rb
View file @
091b15b7
...
@@ -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
...
...
spec/workers/detect_repository_languages_worker_spec.rb
View file @
091b15b7
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment