Class AvatarServiceImpl
- All Implemented Interfaces:
AvatarService
- Since:
- v4.3
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
Build avatar URLs that point to Gravatar avatars. -
Constructor Summary
ConstructorsConstructorDescriptionAvatarServiceImpl
(UserManager userManager, AvatarManager avatarManager, UserPropertyManager userPropertyManager, VelocityRequestContextFactory velocityRequestContextFactory, ApplicationProperties applicationProperties, GravatarSettings gravatarSettings, JiraBaseUrls jiraBaseUrls, EncodingConfiguration encodingConfiguration) Injectable constructor. -
Method Summary
Modifier and TypeMethodDescriptionboolean
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
Returns the avatar id that is configured for the given User.protected Avatar
Returns the anonymous avatar, if configured.getAvatar
(ApplicationUser remoteUser, ApplicationUser avatarUser) Returns the Avatar for the given user, if configured.getAvatar
(ApplicationUser remoteUser, String username) Returns the Avatar for the given user, if configured.getAvatarAbsoluteURL
(ApplicationUser remoteUser, ApplicationUser avatarUser, Avatar.Size size) This is the same asAvatarService.getAvatarURL(ApplicationUser, String, Avatar.Size)
but returns an absolute URL.getAvatarAbsoluteURL
(ApplicationUser remoteUser, String username, Avatar.Size size) This is the same asAvatarService.getAvatarURL(ApplicationUser, String, Avatar.Size)
but returns an absolute URL.getAvatarTagged
(ApplicationUser remoteUser, ApplicationUser avatarUser) 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.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.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.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.getAvatarUrlNoPermCheck
(ApplicationUser avatarUser, Avatar.Size size) This is the same asAvatarService.getAvatarURL(ApplicationUser, String, Size)
but does no permission checking.getAvatarUrlNoPermCheck
(ApplicationUser avatarUser, Avatar avatar, Avatar.Size size) Builds a URI for a JIRA avatar with the requested size.getAvatarUrlNoPermCheck
(String username, Avatar.Size size) This is the same asAvatarService.getAvatarURL(ApplicationUser, String, Size)
but does no permission checking.getGravatarAvatarURL
(ApplicationUser avatarUser, Avatar.Size size) If Gravatar is enabled returns Gravatar url for given user at given size.getProjectAvatarAbsoluteURL
(Project project, Avatar.Size size) Returns the URL for the avatar of the given project.getProjectAvatarURL
(Project project, Avatar.Size size) Returns the URL for the avatar of the given project.Returns the URL for the default avatar of a project.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
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.
-
Constructor Details
-
AvatarServiceImpl
public AvatarServiceImpl(UserManager userManager, AvatarManager avatarManager, UserPropertyManager userPropertyManager, VelocityRequestContextFactory velocityRequestContextFactory, ApplicationProperties applicationProperties, GravatarSettings gravatarSettings, JiraBaseUrls jiraBaseUrls, EncodingConfiguration encodingConfiguration) Injectable constructor.
-
-
Method Details
-
getAvatar
public Avatar getAvatar(ApplicationUser remoteUser, String username) throws AvatarsDisabledException Description copied from interface:AvatarService
Returns the Avatar for the given user, if configured. 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 default avatar. If the user does not exist, this method returns the anonymous avatar.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.
- Specified by:
getAvatar
in interfaceAvatarService
- Parameters:
remoteUser
- the User that wants to view an Avatarusername
- a String containing a username (may have been deleted)- Returns:
- an Avatar, or null
- Throws:
AvatarsDisabledException
- if avatars are disabled
-
getAvatar
public Avatar getAvatar(ApplicationUser remoteUser, ApplicationUser avatarUser) throws AvatarsDisabledException Description copied from interface:AvatarService
Returns the Avatar for the given user, if configured. 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 default avatar. If the user does not exist, this method returns the anonymous avatar.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.
- Specified by:
getAvatar
in interfaceAvatarService
- Parameters:
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)- Returns:
- an Avatar, or null
- Throws:
AvatarsDisabledException
- if avatars are disabled
-
getAvatarTagged
public Avatar getAvatarTagged(ApplicationUser remoteUser, ApplicationUser avatarUser) throws AvatarsDisabledException - Specified by:
getAvatarTagged
in interfaceAvatarService
- Throws:
AvatarsDisabledException
-
getAvatarURL
public URI getAvatarURL(ApplicationUser remoteUser, String username) throws AvatarsDisabledException Description copied from interface:AvatarService
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. This method returns a URL for an avatar with the default size.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.
- Specified by:
getAvatarURL
in interfaceAvatarService
- Parameters:
remoteUser
- a User object for the currently logged in userusername
- a String containing a username (may have been deleted)- Returns:
- a URL that can be used to display the avatar
- Throws:
AvatarsDisabledException
- if avatars are disabled- See Also:
-
getGravatarAvatarURL
Description copied from interface:AvatarService
If Gravatar is enabled returns Gravatar url for given user at given size.- Specified by:
getGravatarAvatarURL
in interfaceAvatarService
- Parameters:
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)- Returns:
- a URL that can be used to display the avatar
-
getAvatarURL
public URI getAvatarURL(ApplicationUser remoteUser, ApplicationUser avatarUser) throws AvatarsDisabledException Description copied from interface:AvatarService
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. This method returns a URL for an avatar with the default size.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.
- Specified by:
getAvatarURL
in interfaceAvatarService
- Parameters:
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)- Returns:
- a URL that can be used to display the avatar
- Throws:
AvatarsDisabledException
- if avatars are disabled- See Also:
-
getAvatarURL
public URI getAvatarURL(ApplicationUser remoteUser, String username, Avatar.Size size) throws AvatarsDisabledException Description copied from interface:AvatarService
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.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.
- Specified by:
getAvatarURL
in interfaceAvatarService
- Parameters:
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)- Returns:
- a URL that can be used to display the avatar
- Throws:
AvatarsDisabledException
- if avatars are disabled- See Also:
-
getAvatarURL
public URI getAvatarURL(ApplicationUser remoteUser, ApplicationUser avatarUser, Avatar.Size size) throws AvatarsDisabledException Description copied from interface:AvatarService
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.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.
- Specified by:
getAvatarURL
in interfaceAvatarService
- Parameters:
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)- Returns:
- a URL that can be used to display the avatar
- Throws:
AvatarsDisabledException
- if avatars are disabled- See Also:
-
getAvatarUrlNoPermCheck
public URI getAvatarUrlNoPermCheck(String username, Avatar.Size size) throws AvatarsDisabledException Description copied from interface:AvatarService
This is the same asAvatarService.getAvatarURL(ApplicationUser, String, Size)
but does no permission checking.- Specified by:
getAvatarUrlNoPermCheck
in interfaceAvatarService
- Parameters:
username
- a String containing a username (may have been deleted)size
- the size of the avatar to be displayed- Returns:
- a URL that can be used to display the avatar
- Throws:
AvatarsDisabledException
- if avatars are disabled
-
getAvatarUrlNoPermCheck
public URI getAvatarUrlNoPermCheck(ApplicationUser avatarUser, Avatar.Size size) throws AvatarsDisabledException Description copied from interface:AvatarService
This is the same asAvatarService.getAvatarURL(ApplicationUser, String, Size)
but does no permission checking.- Specified by:
getAvatarUrlNoPermCheck
in interfaceAvatarService
- Parameters:
avatarUser
- a String containing a username (if null, the default avatar is used)size
- the size of the avatar to be displayed- Returns:
- a URL that can be used to display the avatar
- Throws:
AvatarsDisabledException
- if avatars are disabled
-
getAvatarUrlNoPermCheck
public URI getAvatarUrlNoPermCheck(ApplicationUser avatarUser, Avatar avatar, @Nonnull Avatar.Size size) Builds a URI for a JIRA avatar with the requested size.- Specified by:
getAvatarUrlNoPermCheck
in interfaceAvatarService
- Parameters:
avatarUser
- the ApplicationUser whose avatar we'd like to displayavatar
- the Avatar whose URI we wantsize
- the size in which the avatar should be displayed- Returns:
- a URI that can be used to display the avatar
- See Also:
-
getAvatarAbsoluteURL
public URI getAvatarAbsoluteURL(ApplicationUser remoteUser, String username, Avatar.Size size) throws AvatarsDisabledException Description copied from interface:AvatarService
This is the same asAvatarService.getAvatarURL(ApplicationUser, String, Avatar.Size)
but returns an absolute URL.- Specified by:
getAvatarAbsoluteURL
in interfaceAvatarService
- Throws:
AvatarsDisabledException
-
getAvatarAbsoluteURL
public URI getAvatarAbsoluteURL(ApplicationUser remoteUser, ApplicationUser avatarUser, Avatar.Size size) throws AvatarsDisabledException Description copied from interface:AvatarService
This is the same asAvatarService.getAvatarURL(ApplicationUser, String, Avatar.Size)
but returns an absolute URL.- Specified by:
getAvatarAbsoluteURL
in interfaceAvatarService
- Throws:
AvatarsDisabledException
-
hasCustomUserAvatar
Description copied from interface:AvatarService
Returns true if the user has configured a custom avatar, false otherwise.- Specified by:
hasCustomUserAvatar
in interfaceAvatarService
- Parameters:
remoteUser
- a User object for the currently logged in userusername
- the username of the user whose avatar we will check- Returns:
- a boolean indicating whether the given user has configued a custom avatar
-
hasCustomUserAvatar
Description copied from interface:AvatarService
Returns true if the user has configured a custom avatar, false otherwise.- Specified by:
hasCustomUserAvatar
in interfaceAvatarService
- Parameters:
remoteUser
- a User object for the currently logged in useruser
- the username of the user whose avatar we will check- Returns:
- a boolean indicating whether the given user has configued a custom avatar
-
setCustomUserAvatar
public void setCustomUserAvatar(ApplicationUser remoteUser, String username, Long avatarId) throws AvatarsDisabledException, NoPermissionException Description copied from interface:AvatarService
Sets a custom avatar for a given user.- Specified by:
setCustomUserAvatar
in interfaceAvatarService
- Parameters:
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 user- Throws:
AvatarsDisabledException
- if avatars are disabledNoPermissionException
- if the remote user does not have permission to update the given user's avatar- See Also:
-
setCustomUserAvatar
public void setCustomUserAvatar(ApplicationUser remoteUser, ApplicationUser user, Long avatarId) throws AvatarsDisabledException, NoPermissionException Description copied from interface:AvatarService
Sets a custom avatar for a given user.- Specified by:
setCustomUserAvatar
in interfaceAvatarService
- Parameters:
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 user- Throws:
AvatarsDisabledException
- if avatars are disabledNoPermissionException
- if the remote user does not have permission to update the given user's avatar- See Also:
-
canSetCustomUserAvatar
Description copied from interface:AvatarService
Returns a boolean indicating whether the calling user can edit the custom user avatar for the user with the given username.- Specified by:
canSetCustomUserAvatar
in interfaceAvatarService
- Parameters:
remoteUser
- a User object for the currently logged in userusername
- the username of the user whose avatar we will configure- Returns:
- a indicating whether the calling user can edit the custom user avatar for another user
-
canSetCustomUserAvatar
Description copied from interface:AvatarService
Returns a boolean indicating whether the calling user can edit the custom user avatar for the user with the given username.- Specified by:
canSetCustomUserAvatar
in interfaceAvatarService
- Parameters:
remoteUser
- a User object for the currently logged in useruser
- the user whose avatar we will configure- Returns:
- a indicating whether the calling user can edit the custom user avatar for another user
-
getProjectAvatarURL
Description copied from interface:AvatarService
Returns the URL for the avatar of the given project.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/...").
- Specified by:
getProjectAvatarURL
in interfaceAvatarService
- Parameters:
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)- Returns:
- a URL that can be used to display the avatar
-
getProjectAvatarAbsoluteURL
Description copied from interface:AvatarService
Returns the URL for the avatar of the given project.This will always return an absolute URL (eg. "http://example.com/jira/...").
- Specified by:
getProjectAvatarAbsoluteURL
in interfaceAvatarService
- Parameters:
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)- Returns:
- a URL that can be used to display the avatar
-
getProjectDefaultAvatarURL
Description copied from interface:AvatarService
Returns the URL for the default avatar of a project.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/...").
- Specified by:
getProjectDefaultAvatarURL
in interfaceAvatarService
- Parameters:
size
- the size of the avatar to be displayed (if null, the default size is used)- Returns:
- a URL that can be used to display the avatar
-
getProjectDefaultAvatarAbsoluteURL
Description copied from interface:AvatarService
Returns the URL for the default avatar of a project.This will always return an absolute URL (eg. "http://example.com/jira/...").
- Specified by:
getProjectDefaultAvatarAbsoluteURL
in interfaceAvatarService
- Parameters:
size
- the size of the avatar to be displayed (if null, the default size is used)- Returns:
- a URL that can be used to display the avatar
-
configuredAvatarIdFor
Returns the avatar id that is configured for the given User. If the user has not configured an avatar, this method returns null.- Parameters:
user
- the user whose avatar we want- Returns:
- an avatar id, or null
-
isGravatarEnabled
public boolean isGravatarEnabled()Returns true if Gravatar support is enabled.- Specified by:
isGravatarEnabled
in interfaceAvatarService
- Returns:
- a boolean indicating whether Gravatar support is on
-
isUsingExternalAvatar
Description copied from interface:AvatarService
Check whether a user currently has an external avatar (for example, a Gravatar). UseAvatarService.getAvatarURL(ApplicationUser, ApplicationUser)
to get the avatar URL.- Specified by:
isUsingExternalAvatar
in interfaceAvatarService
- Returns:
- a boolean indicating whether the given currently user has an external avatar
-
setConfiguredAvatarIdFor
Sets the given avatar id as the configured avatar id for a user.- Parameters:
user
- the User whose avatar is being configuredavatarId
- the avatar id to configure
-
getAnonymousAvatar
Returns the anonymous avatar, if configured. Otherwise returns null.- Returns:
- the anonymous avatar, or null
-