@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 getAvatarAbsoluteURL(ApplicationUser remoteUser, String username, Avatar.Size size) throws AvatarsDisabledException { return getAvatarURLImpl(fromStaleUser(remoteUser), false, userManager.getUserByName(username), size); }
@Override public URI getAvatarURL(ApplicationUser remoteUser, String username, Avatar.Size size) throws AvatarsDisabledException { return getAvatarURLImpl(fromStaleUser(remoteUser), false, userManager.getUserByName(username), size); }
@Override public URI getAvatarURL(ApplicationUser remoteUser, String username) throws AvatarsDisabledException { return getAvatarURL(fromStaleUser(remoteUser), userManager.getUserByName(username)); }
@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 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; } }
@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); }