/** * @since v6.3 */ @GET @Path ("type/{type}/owner/{owningObjectId}") public Response getAvatars(final @PathParam ("type") String avatarType, final @PathParam ("owningObjectId") String owningObjectId) { final Avatar.Type avatarsType = Avatar.Type.getByName(avatarType); final TypeAvatarService avatarsForType = universalAvatars.getAvatars(avatarsType); if (null == avatarsForType) { return Response.status(Response.Status.NOT_FOUND).entity("avatarType").build(); } final AvatarImageResolver uriResolver = universalAvatars.getImages(avatarsType); if (null == uriResolver) { return Response.status(Response.Status.NOT_FOUND).entity("avatarType").build(); } final SystemAndCustomAvatars allAvatars = avatarsForType.getAvatars(authContext.getUser(), owningObjectId); final ApplicationUser remoteUser = authContext.getUser(); final List<AvatarBean> systemAvatarBeans = createAvatarBeans(allAvatars.getSystemAvatars(), remoteUser, uriResolver); final List<AvatarBean> customAvatarBeans = createAvatarBeans(allAvatars.getCustomAvatars(), remoteUser, uriResolver); Map<String, List<AvatarBean>> result = ImmutableMap.<String, List<AvatarBean>>builder(). put(SYSTEM_AVATARS_FIELD, systemAvatarBeans). put(CUSTOM_AVATARS_FIELD, customAvatarBeans). build(); return Response.ok(result).build(); }
@Override public void storeTemporaryAvatar(ApplicationUser remoteUser, TemporaryAvatar avatar, Avatar.Type type, String ownerId) throws IllegalAccessException { final TypeAvatarService typeAvatars = avatars.getAvatars(type); if (typeAvatars==null || !typeAvatars.canUserCreateAvatar(remoteUser, ownerId)) { throw new IllegalAccessException("User cannot store temporary avatars"); } ExecutingHttpRequest.get().getSession().setAttribute(SessionKeys.TEMP_AVATAR, avatar); }
@Override public IssueType createIssueType(GenericValue issueTypeGv) { final IssueTypeImpl issueType = new IssueTypeImpl(issueTypeGv, translationManager, authenticationContext, baseUrl, avatarManager); final Avatar avatar = issueType.getAvatar(); if (avatar != null) { // dirty trick to update iconURL to this in avatar // this shouldn't be here but somewhere in presentation layer where i should transform it to link // (and apply user permissions - thankfully its not needed for issue types). // I cannot inject UniversalAvatars here beacause there is circular dependecy project->issue+types->avatars->project. // if i could put such code to presentation layer it would be possible. of course because of backward compatibility final UniversalAvatarsService universalAvatars = ComponentAccessor.getComponent(UniversalAvatarsService.class); final AvatarImageResolver uriForIssueType = universalAvatars.getImages(Avatar.Type.ISSUETYPE); final URI avatarURI = uriForIssueType.getAvatarRelativeUri(null, avatar, Avatar.Size.SMALL); final String avatarURIString = avatarURI.toASCIIString(); issueType.setIconUrl(avatarURIString); } return issueType; }
/** * Deletes avatar * * @param avatarType Project id or project key * @param id database id for avatar * @return temporary avatar cropping instructions * @since v5.0 */ @DELETE @Path ("type/{type}/owner/{owningObjectId}/avatar/{id}") public Response deleteAvatar(final @PathParam ("type") String avatarType, final @PathParam ("owningObjectId") String owningObjectId, @PathParam ("id") final Long id) { final Avatar.Type avatarsType = Avatar.Type.getByName(avatarType); final TypeAvatarService avatarsForType = universalAvatars.getAvatars(avatarsType); if (null == avatarsForType) { return Response.status(Response.Status.NOT_FOUND).build(); } if (!avatarsForType.canUserCreateAvatar(authContext.getUser(), owningObjectId)) { return Response.status(Response.Status.FORBIDDEN).build(); } final Response avatarFromTemporaryResponse = avatarResourceHelper.deleteAvatar(id); return avatarFromTemporaryResponse; }
/** * @throws java.lang.IllegalArgumentException */ @Nonnull private Avatar getAvatar(final HttpServletRequest request) { final ApplicationUser user = authenticationContext.getUser(); final long avatarId = getValidAvatarId(request); final Avatar.Type avatarType = getValidAvatarType(request); final TypeAvatarService avatarsForType = avatars.getAvatars(avatarType); if ( null==avatarsForType) { throw new IllegalArgumentException("Avatar type: "+avatarType); } Avatar avatar = avatarsForType.getAvatar(user, avatarId); if (null==avatar) { avatar = avatarsForType.getDefaultAvatar(); } return avatar; }
private boolean isAllowedToPickAvatar(final String ownerId, Avatar.Type type) { final ApplicationUser user = authenticationContext.getUser(); if (type == Avatar.Type.USER) { return avatarManager.hasPermissionToEdit(user, userUtil.getUserByKey(ownerId)); } else { final Option<TypeAvatarService> avatars = Option.option(universalAvatarsService.getAvatars(type)); final Option<Boolean> canCreateAvatarOption = avatars.flatMap(new Function<TypeAvatarService, Option<Boolean>>() { @Override public Option<Boolean> apply(final TypeAvatarService typeAvatarService) { return Option.some(typeAvatarService.canUserCreateAvatar(user, ownerId)); } }); return canCreateAvatarOption.getOrElse(Boolean.FALSE); } }
final TypeAvatarService typeAvatars = avatars.getAvatars(type); if (typeAvatars == null)