public class AvatarServiceImpl extends Object implements AvatarService
Modifier and Type | Class and Description |
---|---|
class |
AvatarServiceImpl.GravatarUrlStrategy
Build avatar URLs that point to Gravatar avatars.
|
Constructor and Description |
---|
AvatarServiceImpl(UserManager userManager,
AvatarManager avatarManager,
UserPropertyManager userPropertyManager,
VelocityRequestContextFactory velocityRequestContextFactory,
ApplicationProperties applicationProperties,
GravatarSettings gravatarSettings,
EncodingConfiguration encodingConfiguration)
Injectable constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
canSetCustomUserAvatar(ApplicationUser remoteUser,
ApplicationUser user)
Returns a boolean indicating whether the calling user can edit the custom user avatar for the user with the given
username.
|
boolean |
canSetCustomUserAvatar(ApplicationUser remoteUser,
String username)
Returns a boolean indicating whether the calling user can edit the custom user avatar for the user with the given
username.
|
protected Long |
configuredAvatarIdFor(ApplicationUser user)
Returns the avatar id that is configured for the given User.
|
protected Avatar |
getAnonymousAvatar()
Returns the anonymous avatar, if configured.
|
Avatar |
getAvatar(ApplicationUser remoteUser,
ApplicationUser avatarUser)
Returns the Avatar for the given user, if configured.
|
Avatar |
getAvatar(ApplicationUser remoteUser,
String username)
Returns the Avatar for the given user, if configured.
|
URI |
getAvatarAbsoluteURL(ApplicationUser remoteUser,
ApplicationUser avatarUser,
Avatar.Size size)
This is the same as
AvatarService.getAvatarURL(ApplicationUser, String, Avatar.Size)
but returns an absolute URL. |
URI |
getAvatarAbsoluteURL(ApplicationUser remoteUser,
String username,
Avatar.Size size)
This is the same as
AvatarService.getAvatarURL(ApplicationUser, String, Avatar.Size)
but returns an absolute URL. |
Avatar |
getAvatarTagged(ApplicationUser remoteUser,
ApplicationUser avatarUser) |
URI |
getAvatarURL(ApplicationUser remoteUser,
ApplicationUser avatarUser)
Returns the URL for the avatar of the user having the given username for displaying on a page that should be
shown for the passed in remoteUser.
|
URI |
getAvatarURL(ApplicationUser remoteUser,
ApplicationUser avatarUser,
Avatar.Size size)
Returns the URL for the avatar of the user having the given username for displaying on a page that should be
shown for the passed in remoteUser.
|
URI |
getAvatarURL(ApplicationUser remoteUser,
String username)
Returns the URL for the avatar of the user having the given username for displaying on a page that should be
shown for the passed in remoteUser.
|
URI |
getAvatarURL(ApplicationUser remoteUser,
String username,
Avatar.Size size)
Returns the URL for the avatar of the user having the given username for displaying on a page that should be
shown for the passed in remoteUser.
|
URI |
getAvatarUrlNoPermCheck(ApplicationUser avatarUser,
Avatar.Size size)
This is the same as
#getAvatarURL(ApplicationUser, String, Size) but does no permission checking. |
URI |
getAvatarUrlNoPermCheck(ApplicationUser avatarUser,
Avatar avatar,
Avatar.Size size)
Builds a URI for a JIRA avatar with the requested size.
|
URI |
getAvatarUrlNoPermCheck(String username,
Avatar.Size size)
This is the same as
#getAvatarURL(ApplicationUser, String, Size) but does no permission checking. |
Optional<URI> |
getGravatarAvatarURL(ApplicationUser avatarUser,
Avatar.Size size)
If Gravatar is enabled returns Gravatar url for given user at given size.
|
URI |
getProjectAvatarAbsoluteURL(Project project,
Avatar.Size size)
Returns the URL for the avatar of the given project.
|
URI |
getProjectAvatarURL(Project project,
Avatar.Size size)
Returns the URL for the avatar of the given project.
|
URI |
getProjectDefaultAvatarAbsoluteURL(Avatar.Size size)
Returns the URL for the default avatar of a project.
|
URI |
getProjectDefaultAvatarURL(Avatar.Size size)
Returns the URL for the default avatar of a project.
|
boolean |
hasCustomUserAvatar(ApplicationUser remoteUser,
ApplicationUser user)
Returns true if the user has configured a custom avatar, false otherwise.
|
boolean |
hasCustomUserAvatar(ApplicationUser remoteUser,
String username)
Returns true if the user has configured a custom avatar, false otherwise.
|
boolean |
isGravatarEnabled()
Returns true if Gravatar support is enabled.
|
boolean |
isUsingExternalAvatar(ApplicationUser remoteUser,
ApplicationUser avatarUser)
Check whether a user currently has an external avatar (for example, a Gravatar).
|
protected void |
setConfiguredAvatarIdFor(ApplicationUser user,
Long avatarId)
Sets the given avatar id as the configured avatar id for a user.
|
void |
setCustomUserAvatar(ApplicationUser remoteUser,
ApplicationUser user,
Long avatarId)
Sets a custom avatar for a given user.
|
void |
setCustomUserAvatar(ApplicationUser remoteUser,
String username,
Long avatarId)
Sets a custom avatar for a given user.
|
public AvatarServiceImpl(UserManager userManager, AvatarManager avatarManager, UserPropertyManager userPropertyManager, VelocityRequestContextFactory velocityRequestContextFactory, ApplicationProperties applicationProperties, GravatarSettings gravatarSettings, EncodingConfiguration encodingConfiguration)
public Avatar getAvatar(ApplicationUser remoteUser, String username) throws AvatarsDisabledException
AvatarService
If this method would return the default user avatar but none is configured, or if this method would return the anonymous avatar but none is configured, this method returns null.
getAvatar
in interface AvatarService
remoteUser
- the User that wants to view an Avatarusername
- a String containing a username (may have been deleted)AvatarsDisabledException
- if avatars are disabledpublic Avatar getAvatar(ApplicationUser remoteUser, ApplicationUser avatarUser) throws AvatarsDisabledException
AvatarService
If this method would return the default user avatar but none is configured, or if this method would return the anonymous avatar but none is configured, this method returns null.
getAvatar
in interface AvatarService
remoteUser
- the User that wants to view an AvataravatarUser
- the User that the avatar will be returned for (if null it will return a default avatar if it's set or null)AvatarsDisabledException
- if avatars are disabledpublic Avatar getAvatarTagged(ApplicationUser remoteUser, ApplicationUser avatarUser) throws AvatarsDisabledException
getAvatarTagged
in interface AvatarService
AvatarsDisabledException
public URI getAvatarURL(ApplicationUser remoteUser, String username) throws AvatarsDisabledException
AvatarService
If the user does not have a custom avatar, or if the calling user does not have permission to view the Avatar, this method returns the URL of the default avatar. If the user does not exist, this method returns the URL of the anonymous avatar.
getAvatarURL
in interface AvatarService
remoteUser
- a User object for the currently logged in userusername
- a String containing a username (may have been deleted)AvatarsDisabledException
- if avatars are disabledAvatarService.getAvatar(ApplicationUser, String)
public Optional<URI> getGravatarAvatarURL(ApplicationUser avatarUser, Avatar.Size size)
AvatarService
getGravatarAvatarURL
in interface AvatarService
avatarUser
- a User to get the avatar for (if null, Optional.empty() is returned)size
- the size of the avatar to be displayed (if null, the default size is used)public URI getAvatarURL(ApplicationUser remoteUser, ApplicationUser avatarUser) throws AvatarsDisabledException
AvatarService
If the user does not have a custom avatar, or if the calling user does not have permission to view the Avatar, this method returns the URL of the default avatar. If the user does not exist, this method returns the URL of the anonymous avatar.
getAvatarURL
in interface AvatarService
remoteUser
- a User object for the currently logged in useravatarUser
- a User object to get the avatar for (if null, the default avatar is used)AvatarsDisabledException
- if avatars are disabledAvatarService.getAvatar(ApplicationUser, String)
public URI getAvatarURL(ApplicationUser remoteUser, String username, Avatar.Size size) throws AvatarsDisabledException
AvatarService
If the user does not have a custom avatar, or if the calling user does not have permission to view the Avatar, this method returns the URL of the default avatar. If the user does not exist, this method returns the URL of the anonymous avatar.
getAvatarURL
in interface AvatarService
remoteUser
- a User object for the currently logged in userusername
- a String containing a username (may have been deleted)size
- the size of the avatar to be displayed (if null, the default size is used)AvatarsDisabledException
- if avatars are disabledAvatarService.getAvatar(ApplicationUser, String)
public URI getAvatarURL(ApplicationUser remoteUser, ApplicationUser avatarUser, Avatar.Size size) throws AvatarsDisabledException
AvatarService
If the user does not have a custom avatar, or if the calling user does not have permission to view the Avatar, this method returns the URL of the default avatar. If the user does not exist, this method returns the URL of the anonymous avatar.
getAvatarURL
in interface AvatarService
remoteUser
- a User object for the currently logged in useravatarUser
- a User to get the avatar for (if null, the default avatar is used)size
- the size of the avatar to be displayed (if null, the default size is used)AvatarsDisabledException
- if avatars are disabledAvatarService.getAvatar(ApplicationUser, String)
public URI getAvatarUrlNoPermCheck(String username, Avatar.Size size) throws AvatarsDisabledException
AvatarService
#getAvatarURL(ApplicationUser, String, Size)
but does no permission checking.getAvatarUrlNoPermCheck
in interface AvatarService
username
- a String containing a username (may have been deleted)size
- the size of the avatar to be displayedAvatarsDisabledException
- if avatars are disabledpublic URI getAvatarUrlNoPermCheck(ApplicationUser avatarUser, Avatar.Size size) throws AvatarsDisabledException
AvatarService
#getAvatarURL(ApplicationUser, String, Size)
but does no permission checking.getAvatarUrlNoPermCheck
in interface AvatarService
avatarUser
- a String containing a username (if null, the default avatar is used)size
- the size of the avatar to be displayedAvatarsDisabledException
- if avatars are disabledpublic URI getAvatarUrlNoPermCheck(ApplicationUser avatarUser, Avatar avatar, @Nonnull Avatar.Size size)
getAvatarUrlNoPermCheck
in interface AvatarService
avatarUser
- the ApplicationUser whose avatar we'd like to displayavatar
- the Avatar whose URI we wantsize
- the size in which the avatar should be displayedAvatarService.getAvatar(ApplicationUser, String)
public URI getAvatarAbsoluteURL(ApplicationUser remoteUser, String username, Avatar.Size size) throws AvatarsDisabledException
AvatarService
AvatarService.getAvatarURL(ApplicationUser, String, Avatar.Size)
but returns an absolute URL.getAvatarAbsoluteURL
in interface AvatarService
AvatarsDisabledException
public URI getAvatarAbsoluteURL(ApplicationUser remoteUser, ApplicationUser avatarUser, Avatar.Size size) throws AvatarsDisabledException
AvatarService
AvatarService.getAvatarURL(ApplicationUser, String, Avatar.Size)
but returns an absolute URL.getAvatarAbsoluteURL
in interface AvatarService
AvatarsDisabledException
public boolean hasCustomUserAvatar(ApplicationUser remoteUser, String username)
AvatarService
hasCustomUserAvatar
in interface AvatarService
remoteUser
- a User object for the currently logged in userusername
- the username of the user whose avatar we will checkpublic boolean hasCustomUserAvatar(ApplicationUser remoteUser, ApplicationUser user)
AvatarService
hasCustomUserAvatar
in interface AvatarService
remoteUser
- a User object for the currently logged in useruser
- the username of the user whose avatar we will checkpublic void setCustomUserAvatar(ApplicationUser remoteUser, String username, Long avatarId) throws AvatarsDisabledException, NoPermissionException
AvatarService
setCustomUserAvatar
in interface AvatarService
remoteUser
- a User object for the currently logged in userusername
- the username of the user whose avatar we will configureavatarId
- the id of the avatar to configure for the userAvatarsDisabledException
- if avatars are disabledNoPermissionException
- if the remote user does not have permission to update the given user's avatarAvatarService.canSetCustomUserAvatar(ApplicationUser, String)
public void setCustomUserAvatar(ApplicationUser remoteUser, ApplicationUser user, Long avatarId) throws AvatarsDisabledException, NoPermissionException
AvatarService
setCustomUserAvatar
in interface AvatarService
remoteUser
- a User object for the currently logged in useruser
- the user whose avatar we will configureavatarId
- the id of the avatar to configure for the userAvatarsDisabledException
- if avatars are disabledNoPermissionException
- if the remote user does not have permission to update the given user's avatarAvatarService.canSetCustomUserAvatar(ApplicationUser, String)
public boolean canSetCustomUserAvatar(ApplicationUser remoteUser, String username)
AvatarService
canSetCustomUserAvatar
in interface AvatarService
remoteUser
- a User object for the currently logged in userusername
- the username of the user whose avatar we will configurepublic boolean canSetCustomUserAvatar(ApplicationUser remoteUser, ApplicationUser user)
AvatarService
canSetCustomUserAvatar
in interface AvatarService
remoteUser
- a User object for the currently logged in useruser
- the user whose avatar we will configurepublic URI getProjectAvatarURL(Project project, Avatar.Size size)
AvatarService
If running in the context of a web request, this will return a URL relative to the server root (ie "/jira/..."). Otherwise, it will return an absolute URL (eg. "http://example.com/jira/...").
getProjectAvatarURL
in interface AvatarService
project
- the Project of which to get the avatar URLsize
- the size of the avatar to be displayed (if null, the default size is used)public URI getProjectAvatarAbsoluteURL(Project project, Avatar.Size size)
AvatarService
This will always return an absolute URL (eg. "http://example.com/jira/...").
getProjectAvatarAbsoluteURL
in interface AvatarService
project
- the Project of which to get the avatar URLsize
- the size of the avatar to be displayed (if null, the default size is used)public URI getProjectDefaultAvatarURL(Avatar.Size size)
AvatarService
If running in the context of a web request, this will return a URL relative to the server root (ie "/jira/..."). Otherwise, it will return an absolute URL (eg. "http://example.com/jira/...").
getProjectDefaultAvatarURL
in interface AvatarService
size
- the size of the avatar to be displayed (if null, the default size is used)public URI getProjectDefaultAvatarAbsoluteURL(Avatar.Size size)
AvatarService
This will always return an absolute URL (eg. "http://example.com/jira/...").
getProjectDefaultAvatarAbsoluteURL
in interface AvatarService
size
- the size of the avatar to be displayed (if null, the default size is used)protected Long configuredAvatarIdFor(ApplicationUser user)
user
- the user whose avatar we wantpublic boolean isGravatarEnabled()
isGravatarEnabled
in interface AvatarService
public boolean isUsingExternalAvatar(ApplicationUser remoteUser, ApplicationUser avatarUser)
AvatarService
AvatarService.getAvatarURL(ApplicationUser, ApplicationUser)
to get the avatar URL.isUsingExternalAvatar
in interface AvatarService
protected void setConfiguredAvatarIdFor(ApplicationUser user, Long avatarId)
user
- the User whose avatar is being configuredavatarId
- the avatar id to configureprotected Avatar getAnonymousAvatar()
Copyright © 2002-2021 Atlassian. All Rights Reserved.