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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
dcd002a1
Commit
dcd002a1
authored
May 26, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add username parameter to gravatar URL
parent
bd259d6b
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
41 additions
and
12 deletions
+41
-12
app/models/user.rb
app/models/user.rb
+1
-1
app/services/gravatar_service.rb
app/services/gravatar_service.rb
+13
-8
changelogs/unreleased/dm-gravatar-username.yml
changelogs/unreleased/dm-gravatar-username.yml
+4
-0
config/gitlab.yml.example
config/gitlab.yml.example
+1
-1
doc/customization/libravatar.md
doc/customization/libravatar.md
+2
-2
spec/services/gravatar_service_spec.rb
spec/services/gravatar_service_spec.rb
+20
-0
No files found.
app/models/user.rb
View file @
dcd002a1
...
...
@@ -794,7 +794,7 @@ class User < ActiveRecord::Base
def
avatar_url
(
size:
nil
,
scale:
2
,
**
args
)
# We use avatar_path instead of overriding avatar_url because of carrierwave.
# See https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/11001/diffs#note_28659864
avatar_path
(
args
)
||
GravatarService
.
new
.
execute
(
email
,
size
,
scale
)
avatar_path
(
args
)
||
GravatarService
.
new
.
execute
(
email
,
size
,
scale
,
username:
username
)
end
def
all_emails
...
...
app/services/gravatar_service.rb
View file @
dcd002a1
class
GravatarService
include
Gitlab
::
CurrentSettings
def
execute
(
email
,
size
=
nil
,
scale
=
2
)
if
current_application_settings
.
gravatar_enabled?
&&
email
.
present?
size
=
40
if
size
.
nil?
||
size
<=
0
def
execute
(
email
,
size
=
nil
,
scale
=
2
,
username:
nil
)
return
unless
current_application_settings
.
gravatar_enabled?
sprintf
gravatar_url
,
hash:
Digest
::
MD5
.
hexdigest
(
email
.
strip
.
downcase
),
size:
size
*
scale
,
email:
email
.
strip
end
identifier
=
email
.
presence
||
username
.
presence
return
unless
identifier
hash
=
Digest
::
MD5
.
hexdigest
(
identifier
.
strip
.
downcase
)
size
=
40
unless
size
&&
size
>
0
sprintf
gravatar_url
,
hash:
hash
,
size:
size
*
scale
,
email:
ERB
::
Util
.
url_encode
(
email
&
.
strip
||
''
),
username:
ERB
::
Util
.
url_encode
(
username
&
.
strip
||
''
)
end
def
gitlab_config
...
...
changelogs/unreleased/dm-gravatar-username.yml
0 → 100644
View file @
dcd002a1
---
title
:
Add username parameter to gravatar URL
merge_request
:
author
:
config/gitlab.yml.example
View file @
dcd002a1
...
...
@@ -169,7 +169,7 @@ production: &base
## Gravatar
## For Libravatar see: http://doc.gitlab.com/ce/customization/libravatar.html
gravatar:
# gravatar urls: possible placeholders: %{hash} %{size} %{email}
# gravatar urls: possible placeholders: %{hash} %{size} %{email}
%{username}
# plain_url: "http://..." # default: http://www.gravatar.com/avatar/%{hash}?s=%{size}&d=identicon
# ssl_url: "https://..." # default: https://secure.gravatar.com/avatar/%{hash}?s=%{size}&d=identicon
...
...
doc/customization/libravatar.md
View file @
dcd002a1
...
...
@@ -16,7 +16,7 @@ the configuration options as follows:
```
yml
gravatar
:
enabled
:
true
# gravatar URLs: possible placeholders: %{hash} %{size} %{email}
# gravatar URLs: possible placeholders: %{hash} %{size} %{email}
%{username}
plain_url
:
"
http://cdn.libravatar.org/avatar/%{hash}?s=%{size}&d=identicon"
```
...
...
@@ -25,7 +25,7 @@ the configuration options as follows:
```
yml
gravatar
:
enabled
:
true
# gravatar URLs: possible placeholders: %{hash} %{size} %{email}
# gravatar URLs: possible placeholders: %{hash} %{size} %{email}
%{username}
ssl_url
:
"
https://seccdn.libravatar.org/avatar/%{hash}?s=%{size}&d=identicon"
```
...
...
spec/services/gravatar_service_spec.rb
0 → 100644
View file @
dcd002a1
require
'spec_helper'
describe
GravatarService
,
service:
true
do
describe
'#execute'
do
let
(
:url
)
{
'http://example.com/avatar?hash=%{hash}&size=%{size}&email=%{email}&username=%{username}'
}
before
do
allow
(
Gitlab
.
config
.
gravatar
).
to
receive
(
:plain_url
).
and_return
(
url
)
end
it
'replaces the placeholders'
do
avatar_url
=
described_class
.
new
.
execute
(
'user@example.com'
,
100
,
2
,
username:
'user'
)
expect
(
avatar_url
).
to
include
(
"hash=
#{
Digest
::
MD5
.
hexdigest
(
'user@example.com'
)
}
"
)
expect
(
avatar_url
).
to
include
(
"size=200"
)
expect
(
avatar_url
).
to
include
(
"email=user%40example.com"
)
expect
(
avatar_url
).
to
include
(
"username=user"
)
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