Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JC-963 An incorrect message appears when a user performs the 'Remove … #288

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,11 @@ public class ImageService {
* user-friendly string with all valid image types
*/
private static final String VALID_IMAGE_EXTENSIONS = "*.jpeg, *.jpg, *.gif, *.png, *.ico";

private static final Logger LOGGER = LoggerFactory.getLogger(ImageService.class);
private ImageConverter imageConverter;
private Base64Wrapper base64Wrapper;
private JCommuneProperty imageSizeProperty;
private String defaultImagePath;
private static final Logger LOGGER = LoggerFactory.getLogger(ImageService.class);

/**
* Create ImageService instance
Expand Down Expand Up @@ -90,6 +89,23 @@ public byte[] getDefaultImage() {
return result;
}

/**
* Check image user avatar
*
* @param avatar image for compare with default image
* @return true if avatar image default
*/
public boolean isDefaultImage(byte[] avatar) {
boolean isDefaultImage = false;
try {
isDefaultImage = Arrays.equals(getDefaultImage(), avatar) ? true
: preProcessAndEncodeInString64(getDefaultImage()).equals(imageConverter.prepareHtmlImgSrc(avatar));
} catch (ImageProcessException e) {
LOGGER.error("Can't convert default image user avatar", e);
}
return isDefaultImage;
}

/**
* Pre process image to fit maximum size and be in the target format and
* convert the contents of the result image into String64 format
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ public ModelAndView showUserSecuritySettings(@PathVariable Long editedUserId)
private void setAvatarToUserProfileView(EditUserProfileDto editUserProfileDto, JCUser user) {
byte[] avatar = user.getAvatar();
editUserProfileDto.setAvatar(imageConverter.prepareHtmlImgSrc(avatar));
editUserProfileDto.setDefaultAvatarFlag(imageService.isDefaultImage(avatar));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class EditUserProfileDto {
private long userId;
private String username;
private String avatar;
private boolean defaultAvatarFlag;
private Long userProfileVersion;

@Valid
Expand All @@ -53,6 +54,14 @@ public class EditUserProfileDto {
@Valid
private UserContactsDto userContactsDto;

public boolean isDefaultAvatarFlag() {
return defaultAvatarFlag;
}

public void setDefaultAvatarFlag(Boolean defaultAvatarFlag) {
this.defaultAvatarFlag = defaultAvatarFlag;
}

/**
* Create instance with UserProfileDto. All required fields retrieved from JCUser.
* @param userProfileDto dto for user profile fields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@
<i class="icon-picture"></i>
<spring:message code="label.avatar.load"/>
</a>
<c:if test="${!editedUser.avatar.isEmpty() && !editedUser.defaultAvatarFlag}">
<a id="removeAvatar" href="#" class="btn btn-mini btn-danger space-left-big-nf"
title="<spring:message code="label.avatar.remove" />">
<i class="icon-remove icon-white"></i>
</a>
</c:if>
</div>
</c:if>

Expand Down