@Override public Option<Boolean> apply(final TypeAvatarService typeAvatarService) { return Option.some(typeAvatarService.canUserCreateAvatar(user, ownerId)); } });
@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); }
/** * 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; }