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
741f333d
Commit
741f333d
authored
Apr 23, 2018
by
Micaël Bergeron
Committed by
John Northrup
Apr 23, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Resolve "Avatar URLs are wrong when using a CDN path and Object Storage"
parent
c0eabb84
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
4 deletions
+26
-4
app/models/concerns/avatarable.rb
app/models/concerns/avatarable.rb
+3
-2
app/uploaders/gitlab_uploader.rb
app/uploaders/gitlab_uploader.rb
+4
-0
changelogs/unreleased/44775-avatar-on-os-fails-with-cdn.yml
changelogs/unreleased/44775-avatar-on-os-fails-with-cdn.yml
+5
-0
spec/models/concerns/avatarable_spec.rb
spec/models/concerns/avatarable_spec.rb
+14
-2
No files found.
app/models/concerns/avatarable.rb
View file @
741f333d
...
...
@@ -31,12 +31,13 @@ module Avatarable
asset_host
=
ActionController
::
Base
.
asset_host
use_asset_host
=
asset_host
.
present?
use_authentication
=
respond_to?
(
:public?
)
&&
!
public
?
# Avatars for private and internal groups and projects require authentication to be viewed,
# which means they can only be served by Rails, on the regular GitLab host.
# If an asset host is configured, we need to return the fully qualified URL
# instead of only the avatar path, so that Rails doesn't prefix it with the asset host.
if
use_asset_host
&&
respond_to?
(
:public?
)
&&
!
public
?
if
use_asset_host
&&
use_authentication
use_asset_host
=
false
only_path
=
false
end
...
...
@@ -49,6 +50,6 @@ module Avatarable
url_base
<<
gitlab_config
.
relative_url_root
end
url_base
+
avatar
.
url
url_base
+
avatar
.
local_
url
end
end
app/uploaders/gitlab_uploader.rb
View file @
741f333d
...
...
@@ -65,6 +65,10 @@ class GitlabUploader < CarrierWave::Uploader::Base
!!
model
end
def
local_url
File
.
join
(
'/'
,
self
.
class
.
base_dir
,
dynamic_segment
,
filename
)
end
private
# Designed to be overridden by child uploaders that have a dynamic path
...
...
changelogs/unreleased/44775-avatar-on-os-fails-with-cdn.yml
0 → 100644
View file @
741f333d
---
title
:
Fixed wrong avatar URL when the avatar is on object storage.
merge_request
:
18092
author
:
type
:
fixed
spec/models/concerns/avatarable_spec.rb
View file @
741f333d
require
'spec_helper'
describe
Avatarable
do
set
(
:project
)
{
create
(
:project
,
avatar:
fixture_file_upload
(
File
.
join
(
Rails
.
root
,
'spec/fixtures/dk.png'
))
)
}
let
(
:project
)
{
create
(
:project
,
:with_avatar
)
}
let
(
:gitlab_host
)
{
"https://gitlab.example.com"
}
let
(
:relative_url_root
)
{
"/gitlab"
}
...
...
@@ -37,11 +37,23 @@ describe Avatarable do
project
.
visibility_level
=
visibility_level
end
let
(
:avatar_path
)
{
(
avatar_path_prefix
+
[
project
.
avatar
.
url
]).
join
}
let
(
:avatar_path
)
{
(
avatar_path_prefix
+
[
project
.
avatar
.
local_
url
]).
join
}
it
'returns the expected avatar path'
do
expect
(
project
.
avatar_path
(
only_path:
only_path
)).
to
eq
(
avatar_path
)
end
context
"when avatar is stored remotely"
do
before
do
stub_uploads_object_storage
(
AvatarUploader
)
project
.
avatar
.
migrate!
(
ObjectStorage
::
Store
::
REMOTE
)
end
it
'returns the expected avatar path'
do
expect
(
project
.
avatar_url
(
only_path:
only_path
)).
to
eq
(
avatar_path
)
end
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