@Override public void setCustomUserAvatar(ApplicationUser remoteUser, ApplicationUser user, Long avatarId) throws AvatarsDisabledException, NoPermissionException { if (!canSetCustomUserAvatar(remoteUser, user)) { throw new NoPermissionException(); } setConfiguredAvatarIdFor(user, avatarId); }
@Override public boolean hasCustomUserAvatar(ApplicationUser remoteUser, ApplicationUser user) { // In addition to no configured avatar, if the user's avatar is external, it is considered "custom". // This should be finessed into the real question which is "can I have the edit link for this?" which should // be encapsulated by the avatar support plugin moduletype. Bonus is that question would work for admin use case // As of end of 2014 this belongs to the Identity team's backlog and the Atlassian ID project's ongoing work on // cross-product avatar APIs. Delete this comment by the end of 2016 if everything has changed again - christo return remoteUser != null && (configuredAvatarIdFor(user) != null || isUsingExternalAvatar(remoteUser, user)); }
@Override public URI getAvatarAbsoluteURL(ApplicationUser remoteUser, String username, Avatar.Size size) throws AvatarsDisabledException { return getAvatarURLImpl(fromStaleUser(remoteUser), false, userManager.getUserByName(username), size); }
@Override public Avatar getAvatar(ApplicationUser remoteUser, ApplicationUser avatarUser) throws AvatarsDisabledException { if (avatarUser == null) { return getAnonymousAvatar(); } return getAvatarImpl(remoteUser, false, avatarUser, false); }
@Override public Avatar getAvatar(ApplicationUser remoteUser, String username) throws AvatarsDisabledException { ApplicationUser user = userManager.getUserByName(username); if (user == null) { Avatar anonymousAvatar = getAnonymousAvatar(); LOGGER.debug("User with key '{}' does not exist, using anonymous avatar id {}", username, anonymousAvatar != null ? anonymousAvatar.getId() : null); return anonymousAvatar; } return getAvatarImpl(fromStaleUser(remoteUser), false, user, false); }
@Override public URI getAvatarURL(ApplicationUser remoteUser, String username) throws AvatarsDisabledException { return getAvatarURL(fromStaleUser(remoteUser), userManager.getUserByName(username)); }
@Override public void setCustomUserAvatar(ApplicationUser remoteUser, String username, Long avatarId) throws AvatarsDisabledException, NoPermissionException { ApplicationUser user = userManager.getUserByName(username); if (user == null) { throw new IllegalArgumentException(String.format("User '%s' does not exist", username)); } setCustomUserAvatar(fromStaleUser(remoteUser), user, avatarId); }
@Override public boolean canSetCustomUserAvatar(ApplicationUser remoteUser, String username) { ApplicationUser user = userManager.getUserByName(username); if (user == null) { throw new IllegalArgumentException(String.format("User '%s' does not exist", username)); } return canSetCustomUserAvatar(fromStaleUser(remoteUser), user); }
@Override public boolean hasCustomUserAvatar(ApplicationUser remoteUser, String username) { ApplicationUser user = userManager.getUserByName(username); if (user == null) { throw new IllegalArgumentException(String.format("User '%s' does not exist", username)); } return hasCustomUserAvatar(fromStaleUser(remoteUser), user); }
@Override public URI getAvatarURL(ApplicationUser remoteUser, ApplicationUser avatarUser, Avatar.Size size) throws AvatarsDisabledException { return getAvatarURLImpl(remoteUser, false, avatarUser, size); }
@Override public URI getProjectDefaultAvatarURL(final Avatar.Size size) { final String baseUrl = velocityRequestContextFactory.getJiraVelocityRequestContext().getBaseUrl(); return getProjectDefaultAvatarURLImpl(size, baseUrl); }
@Override public URI getProjectAvatarAbsoluteURL(final Project project, final Avatar.Size size) { final String baseUrl = velocityRequestContextFactory.getJiraVelocityRequestContext().getCanonicalBaseUrl(); return getProjectAvatarURLImpl(project, size, baseUrl); }
@Override public boolean hasPermissionToEdit(final ApplicationUser remoteUser, final Avatar.Type type, final String ownerId) { if (ownerId == null) { return false; } try { if (type == PROJECT) { return hasPermissionToEdit(fromStaleUser(remoteUser), getProjectManager().getProjectObj(Long.parseLong(ownerId))); } if (type == USER) { return hasPermissionToEdit(fromStaleUser(remoteUser), ApplicationUsers.byKey(ownerId)); } // check for other types are removed form this manager into AvatarAccessPolicy return true; } catch (NumberFormatException e) { return false; } }
/** * Builds a URI for a JIRA avatar with the requested size. * * @param avatarUser the ApplicationUser whose avatar we'd like to display * @param avatar the Avatar whose URI we want * @param size the size in which the avatar should be displayed * @return a URI that can be used to display the avatar */ public URI getAvatarUrlNoPermCheck(final ApplicationUser avatarUser, final Avatar avatar, @Nonnull Size size) { final Long id = avatar.getId(); final String sizeName = size.getParam(); if (avatar.getAvatarType() == Avatar.Type.USER) { return URI.create(jiraAvatarSupport.get().getAvatarById(id, sizeName).getUrl()); } else { return getProjectAvatarUrl(avatar, size); } }
@Override public Avatar getAvatarTagged(ApplicationUser remoteUser, ApplicationUser avatarUser) throws AvatarsDisabledException { if (avatarUser == null) { return getAnonymousAvatar(); } return getAvatarImpl(remoteUser, false, avatarUser, true); }
@Override public URI getAvatarUrlNoPermCheck(ApplicationUser avatarUser, Avatar.Size size) throws AvatarsDisabledException { return getAvatarURLImpl(null, true, avatarUser, size); }
@Override public URI getProjectDefaultAvatarAbsoluteURL(final Avatar.Size size) { final String baseUrl = velocityRequestContextFactory.getJiraVelocityRequestContext().getCanonicalBaseUrl(); return getProjectDefaultAvatarURLImpl(size, baseUrl); }
@Override public URI getProjectAvatarURL(final Project project, final Avatar.Size size) { final String baseUrl = velocityRequestContextFactory.getJiraVelocityRequestContext().getBaseUrl(); return getProjectAvatarURLImpl(project, size, baseUrl); }
@Override public boolean hasPermissionToView(final ApplicationUser remoteUser, final Avatar.Type type, final String ownerId) { if (ownerId == null) { return type != Avatar.Type.PROJECT; } try { return type == Avatar.Type.PROJECT ? hasPermissionToView(fromStaleUser(remoteUser), getProjectManager().getProjectObj(Long.parseLong(ownerId))) : hasPermissionToView(fromStaleUser(remoteUser), ApplicationUsers.byKey(ownerId)); } catch (NumberFormatException e) { return false; } }
@Override public URI getAvatarURL(ApplicationUser remoteUser, String username, Avatar.Size size) throws AvatarsDisabledException { return getAvatarURLImpl(fromStaleUser(remoteUser), false, userManager.getUserByName(username), size); }