-
Suggestion
-
Resolution: Fixed
-
We collect Bitbucket feedback from various sources, and we evaluate what we've collected when planning our product roadmap. To understand how this piece of feedback will be reviewed, see our Implementation of New Features Policy.
We have Internal Gravatar compatible server for Avatars. Will be nice if Stash allow to specify URL of Gravatar server.
[BSERV-3112] Change Gravatar server URL
Until 2.4.0 is released i implemented tiny plugin to enable this:
https://bitbucket.org/lelik/stash-custom-avatar-js
Kevin,
Stash actually supports that already. In 2.3.1 and previous, you can set:
avatar.gravatar.default=identicon
In 2.4, as documented in the configuration block above, the preferred setting is:
avatar.url.default=wavatar
avatar.gravatar.default will still work, though, until 3.0. The default is "mm", as shown above, but any of the normal Gravatar default sets can be used: "identicon", "wavatar", "retro", "blank", "monsterid", even "404".
Is there anyway to expose an option to not have the mystery man come back by default? I would like to be able to support identicon, monsterid, wavatar, or retro.
This will be included in the Stash 2.4 release.
The properties used are:
# The fallback URL for Gravatar avatars when a user does not have an acceptable avatar configured. This may be a URL # resource, or a Gravatar provided default set. # # This configuration setting is DEPRECATED. It will be removed in 3.0. Use "avatar.url.default" instead. avatar.gravatar.default=mm # Defines the fallback URL to be formatted into the "avatar.url.format.http" or "avatar.url.format.https" URL format # for use when a user does not have an acceptable avatar configured. This value may be a URL or, if using Gravatar, # it may be the identifier for one of Gravatar's default avatars. # # The default here falls back on the now-deprecated "avatar.gravatar.default" setting, which should ensure that value, # if set, continues to work until it is removed in 3.0. At that time, this default will become "mm" avatar.url.default=${avatar.gravatar.default} # Defines the default URL format for retrieving user avatars over HTTP. This default uses any G-rated avatar provided # by the Gravatar service [http://www.gravatar.com] # # The following format parameters are available: # %1$s -> The user's e-mail address, MD5 hashed, or "00000000000000000000000000000000" if the user has no e-mail # %2$d -> The requested avatar size # %3$s -> The fallback URL, URL-encoded, which may be defined using "avatar.url.default" # %4$s -> The user's e-mail address, not hashed, or an empty string if the user has no e-mail avatar.url.format.http=http://www.gravatar.com/avatar/%1$s.jpg?s=%2$d&d=%3$s # Defines the default URL format for retrieving user avatars over HTTPS. This default uses any G-rated avatar provided # by the Gravatar service [http://www.gravatar.com] # # The following format parameters are available: # %1$s -> The user's e-mail address, MD5 hashed, or "00000000000000000000000000000000" if the user has no e-mail # %2$d -> The requested avatar size # %3$s -> The fallback URL, URL-encoded, which may be defined using "avatar.url.default" # %4$s -> The user's e-mail address, not hashed, or an empty string if the user has no e-mail avatar.url.format.https=https://secure.gravatar.com/avatar/%1$s.jpg?s=%2$d&d=%3$s
Noted in the documentation is the fact that the e-mail address may be empty. There are codepaths through the system where the Person instance for which the avatar is being requested does not have an e-mail address. With the Gravatar service, such users receive the mystery man icon by default.
Agreed, removed username hack from pach.
diff --git a/stash-parent/platform/src/main/resources/stash-default.properties b/stash-parent/platform/src/main/resources/stash-default.properties index fd5b39f..76462fd 100644 --- a/stash-parent/platform/src/main/resources/stash-default.properties +++ b/stash-parent/platform/src/main/resources/stash-default.properties @@ -457,6 +457,13 @@ password.reset.validity.period=4320 # Avatars ######################################################################################################################## +# The url formats for Gravatar avatars. Variables are used: +# * %1$s - Person email hash +# * %2$d - Requested avatar size (it is square) +# * %3$s - Fallback URL (see ${avatar.gravatar.default} property) +# * %4$s - Person email as is +avatar.gravatar.http.url.format=http://www.gravatar.com/avatar/%1$s.jpg?s=%2$d&d=%3$s +avatar.gravatar.https.url.format=https://secure.gravatar.com/avatar/%1$s.jpg?s=%2$d&d=%3$s # The fallback url for Gravatar avatars when the user does not have an associated Gravatar url. This may be a URL # resource, or a Gravatar provided default set. avatar.gravatar.default=mm diff --git a/stash-parent/service-impl/src/main/java/com/atlassian/stash/internal/avatar/GravatarAvatarSource.java b/stash-parent/service-impl/src/main/java/com index f294a29..0964777 100644 --- a/stash-parent/service-impl/src/main/java/com/atlassian/stash/internal/avatar/GravatarAvatarSource.java +++ b/stash-parent/service-impl/src/main/java/com/atlassian/stash/internal/avatar/GravatarAvatarSource.java @@ -41,12 +41,18 @@ public class GravatarAvatarSource implements AvatarSource { private static final Logger log = LoggerFactory.getLogger(GravatarAvatarSource.class); private final MessageDigestPasswordEncoder md5; + private final String httpUrlFormat; + private final String httpsUrlFormat; private String defaultFallbackUrl; @Autowired public GravatarAvatarSource(@Qualifier("md5Encoder") MessageDigestPasswordEncoder md5, + @Value("${avatar.gravatar.http.url.format}") String httpUrlFormat, + @Value("${avatar.gravatar.https.url.format}") String httpsUrlFormat, @Value("${avatar.gravatar.default}") String defaultFallbackUrl) { this.md5 = md5; + this.httpUrlFormat = StringUtils.isBlank(httpUrlFormat) ? HTTP_GRAVATAR_URL_FORMAT : httpUrlFormat; + this.httpsUrlFormat = StringUtils.isBlank(httpsUrlFormat) ? HTTPS_GRAVATAR_URL_FORMAT : httpsUrlFormat; this.defaultFallbackUrl = defaultFallbackUrl; } @@ -93,8 +99,8 @@ public class GravatarAvatarSource implements AvatarSource { if (StringUtils.isNotBlank(emailAddress)) { hash = hash(emailAddress); } - String format = request.isSecure() ? HTTPS_GRAVATAR_URL_FORMAT : HTTP_GRAVATAR_URL_FORMAT; - return String.format(format, hash, request.getSize(), encodeUrl(defaultFallbackUrl)); + String format = request.isSecure() ? httpsUrlFormat : httpUrlFormat; + return String.format(format, hash, request.getSize(), encodeUrl(defaultFallbackUrl), emailAddress); } /**
The username side of this change cannot be done as shown in the patch. It is unacceptable to assume that the portion of a user's e-mail address before the @ is their username; I've worked in several different organizations where it wasn't and know that it's not uncommon. It may work in some organizations, but it definitely will not work for them all. The username would need to come from the user associated with the e-mail address.
The means the primary difficulty of exposing usernames for formatting is that the vast majority of URLs are generated for commit authors. Stash has no guarantees that a user exists in the system for the authors of commits. This is exacerbated when users are able to access the repository from multiple hosts. In Stash's own codebase there are many commits which are tied to e-mail addresses for which there is no user in Stash--the developers on the team frequently commit from home, and such commits often contain their personal e-mail addresses instead of their atlassian.com ones. There's also the performance overhead of looking up users by their e-mail address to try and get their user account so that it, in turn, can be used to provide their username.
We can expose:
- Hash
- Size
- Fallback URL
- E-mail address
In our case we have server for avatars in intranet like 'acme.com/avatar/$(login)/$(size)'. But it really look like a hack in Stash code...
I think we must implement Gravatar's API on our server, and then remove 'login' and 'pure email' from this patch.
Offtopic, building Stash from source make some wrong Stash instance. I rolled back to original distribution, cos Stash with my patches works bugly. Is it possible to build Stash on Mac OS and use then on Ubuntu?
Alexey,
I see that you're making 2 variables, username and user e-mail, available that are not necessary for Gravatar. I'm assuming that means your "Gravatar compatible server for Avatars" needs one or both of those? Or are they something you're exposing with the assumption they might be useful for someone else?
Date: Wed Apr 17 04:15:17 2013 +0400 Add ability to configure Gravatar URL https://jira.atlassian.com/browse/STASH-3112 diff --git a/stash-parent/platform/src/main/resources/stash-default.properties b/stash-parent/platform/src/main/resources/stash-default.properties index fd5b39f..59bd987 100644 --- a/stash-parent/platform/src/main/resources/stash-default.properties +++ b/stash-parent/platform/src/main/resources/stash-default.properties @@ -457,6 +457,14 @@ password.reset.validity.period=4320 # Avatars ######################################################################################################################## +# The url formats for Gravatar avatars. Variables are used: +# * %1$s - Person email hash +# * %2$d - Requested avatar size (it is square) +# * %3$s - Fallback URL (see ${avatar.gravatar.default} property) +# * %4$s - Person username (login) as is +# * %5$s - Person email as is +avatar.gravatar.http.url.format=http://www.gravatar.com/avatar/%1$s.jpg?s=%2$d&d=%3$s +avatar.gravatar.https.url.format=https://secure.gravatar.com/avatar/%1$s.jpg?s=%2$d&d=%3$s # The fallback url for Gravatar avatars when the user does not have an associated Gravatar url. This may be a URL # resource, or a Gravatar provided default set. avatar.gravatar.default=mm diff --git a/stash-parent/service-impl/src/main/java/com/atlassian/stash/internal/avatar/GravatarAvatarSource.java b/stash-parent/service-impl/src/main/java/com index f294a29..ba7460c 100644 --- a/stash-parent/service-impl/src/main/java/com/atlassian/stash/internal/avatar/GravatarAvatarSource.java +++ b/stash-parent/service-impl/src/main/java/com/atlassian/stash/internal/avatar/GravatarAvatarSource.java @@ -41,12 +41,18 @@ public class GravatarAvatarSource implements AvatarSource { private static final Logger log = LoggerFactory.getLogger(GravatarAvatarSource.class); private final MessageDigestPasswordEncoder md5; + private final String httpUrlFormat; + private final String httpsUrlFormat; private String defaultFallbackUrl; @Autowired public GravatarAvatarSource(@Qualifier("md5Encoder") MessageDigestPasswordEncoder md5, + @Value("${avatar.gravatar.http.url.format}") String httpUrlFormat, + @Value("${avatar.gravatar.https.url.format}") String httpsUrlFormat, @Value("${avatar.gravatar.default}") String defaultFallbackUrl) { this.md5 = md5; + this.httpUrlFormat = StringUtils.isBlank(httpUrlFormat) ? HTTP_GRAVATAR_URL_FORMAT : httpUrlFormat; + this.httpsUrlFormat = StringUtils.isBlank(httpsUrlFormat) ? HTTPS_GRAVATAR_URL_FORMAT : httpsUrlFormat; this.defaultFallbackUrl = defaultFallbackUrl; } @@ -93,8 +99,9 @@ public class GravatarAvatarSource implements AvatarSource { if (StringUtils.isNotBlank(emailAddress)) { hash = hash(emailAddress); } - String format = request.isSecure() ? HTTPS_GRAVATAR_URL_FORMAT : HTTP_GRAVATAR_URL_FORMAT; - return String.format(format, hash, request.getSize(), encodeUrl(defaultFallbackUrl)); + String format = request.isSecure() ? httpsUrlFormat : httpUrlFormat; + String login = StringUtils.substringBefore(emailAddress, "@"); + return String.format(format, hash, request.getSize(), encodeUrl(defaultFallbackUrl), login, emailAddress); } /**
Whooowhoo
Work wel, but only tiny problem with users with no emails (
STASH-3404)