fix: block app country updates
This commit is contained in:
parent
28335ed1de
commit
f16cf81a77
@ -244,6 +244,11 @@ public enum UserErrorCode implements IResponseErrorCode {
|
|||||||
*/
|
*/
|
||||||
TASK_TIER_NOT_FOUND(4079, "Task tier not found"),
|
TASK_TIER_NOT_FOUND(4079, "Task tier not found"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* App 不允许用户自己修改国家.
|
||||||
|
*/
|
||||||
|
USER_COUNTRY_UPDATE_NOT_ALLOWED(4080, "Country cannot be changed"),
|
||||||
|
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import com.red.circle.common.business.core.ImageSizeConst;
|
|||||||
import com.red.circle.common.business.core.SensitiveWordFilter;
|
import com.red.circle.common.business.core.SensitiveWordFilter;
|
||||||
import com.red.circle.common.business.core.constant.KeywordConstant;
|
import com.red.circle.common.business.core.constant.KeywordConstant;
|
||||||
import com.red.circle.common.business.core.enums.DataApprovalTypeEnum;
|
import com.red.circle.common.business.core.enums.DataApprovalTypeEnum;
|
||||||
import com.red.circle.component.redis.service.RedisService;
|
|
||||||
import com.red.circle.external.inner.endpoint.oss.OssServiceClient;
|
import com.red.circle.external.inner.endpoint.oss.OssServiceClient;
|
||||||
import com.red.circle.framework.core.asserts.ResponseAssert;
|
import com.red.circle.framework.core.asserts.ResponseAssert;
|
||||||
import com.red.circle.framework.core.response.CommonErrorCode;
|
import com.red.circle.framework.core.response.CommonErrorCode;
|
||||||
@ -16,11 +15,6 @@ import com.red.circle.other.domain.gateway.user.UserProfileGateway;
|
|||||||
import com.red.circle.other.domain.model.approval.ProfileApprovalContent;
|
import com.red.circle.other.domain.model.approval.ProfileApprovalContent;
|
||||||
import com.red.circle.other.domain.model.user.UserProfile;
|
import com.red.circle.other.domain.model.user.UserProfile;
|
||||||
import com.red.circle.other.infra.database.cache.service.cp.CpRelationshipCacheService;
|
import com.red.circle.other.infra.database.cache.service.cp.CpRelationshipCacheService;
|
||||||
import com.red.circle.other.infra.database.mongo.service.live.RoomProfileManagerService;
|
|
||||||
import com.red.circle.other.infra.database.rds.entity.sys.SysCountryCode;
|
|
||||||
import com.red.circle.other.infra.database.rds.entity.user.user.BaseInfo;
|
|
||||||
import com.red.circle.other.infra.database.rds.service.sys.SysCountryCodeService;
|
|
||||||
import com.red.circle.other.infra.database.rds.service.user.user.BaseInfoService;
|
|
||||||
import com.red.circle.other.inner.asserts.DynamicErrorCode;
|
import com.red.circle.other.inner.asserts.DynamicErrorCode;
|
||||||
import com.red.circle.tool.core.collection.CollectionUtils;
|
import com.red.circle.tool.core.collection.CollectionUtils;
|
||||||
import com.red.circle.tool.core.text.StringUtils;
|
import com.red.circle.tool.core.text.StringUtils;
|
||||||
@ -29,11 +23,9 @@ import com.red.circle.other.inner.model.dto.user.PhotoItem;
|
|||||||
import com.red.circle.other.inner.asserts.user.UserErrorCode;
|
import com.red.circle.other.inner.asserts.user.UserErrorCode;
|
||||||
import com.red.circle.other.inner.model.dto.user.UserProfileDTO;
|
import com.red.circle.other.inner.model.dto.user.UserProfileDTO;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -52,12 +44,8 @@ public class UpdateUserProfileCmdExe {
|
|||||||
private static final Logger log = LoggerFactory.getLogger(UpdateUserProfileCmdExe.class);
|
private static final Logger log = LoggerFactory.getLogger(UpdateUserProfileCmdExe.class);
|
||||||
private final OssServiceClient ossServiceClient;
|
private final OssServiceClient ossServiceClient;
|
||||||
private final UserProfileGateway userProfileGateway;
|
private final UserProfileGateway userProfileGateway;
|
||||||
private final RedisService redisService;
|
|
||||||
private final BaseInfoService baseInfoService;
|
|
||||||
private final SysCountryCodeService sysCountryCodeService;
|
|
||||||
private final ProfileApprovalGateway profileApprovalGateway;
|
private final ProfileApprovalGateway profileApprovalGateway;
|
||||||
private final UserProfileAppConvertor userProfileAppConvertor;
|
private final UserProfileAppConvertor userProfileAppConvertor;
|
||||||
private final RoomProfileManagerService roomProfileManagerService;
|
|
||||||
private final CpRelationshipCacheService cpRelationshipCacheService;
|
private final CpRelationshipCacheService cpRelationshipCacheService;
|
||||||
|
|
||||||
public UserProfileDTO execute(UserProfileModifyCmd cmd) {
|
public UserProfileDTO execute(UserProfileModifyCmd cmd) {
|
||||||
@ -68,6 +56,7 @@ public class UpdateUserProfileCmdExe {
|
|||||||
userProfileGateway.removeCacheAll(cmd.requiredReqUserId());
|
userProfileGateway.removeCacheAll(cmd.requiredReqUserId());
|
||||||
UserProfile userProfile = userProfileGateway.getByUserId(cmd.requiredReqUserId());
|
UserProfile userProfile = userProfileGateway.getByUserId(cmd.requiredReqUserId());
|
||||||
ResponseAssert.notNull(UserErrorCode.USER_INFO_NOT_FOUND, userProfile);
|
ResponseAssert.notNull(UserErrorCode.USER_INFO_NOT_FOUND, userProfile);
|
||||||
|
assertCountryNotChanged(cmd, userProfile);
|
||||||
if (StringUtils.isNotBlank(cmd.getUserAvatar())) {
|
if (StringUtils.isNotBlank(cmd.getUserAvatar())) {
|
||||||
cmd.setUserAvatar(ossServiceClient.processImgSaveAsCompressZoom(cmd.getUserAvatar(),
|
cmd.setUserAvatar(ossServiceClient.processImgSaveAsCompressZoom(cmd.getUserAvatar(),
|
||||||
ImageSizeConst.COVER_HEIGHT).getBody()
|
ImageSizeConst.COVER_HEIGHT).getBody()
|
||||||
@ -77,6 +66,7 @@ public class UpdateUserProfileCmdExe {
|
|||||||
UserProfile updateUserProfile = userProfileAppConvertor.toUserProfile(cmd);
|
UserProfile updateUserProfile = userProfileAppConvertor.toUserProfile(cmd);
|
||||||
ResponseAssert.notNull(CommonErrorCode.UPDATE_FAILURE, updateUserProfile);
|
ResponseAssert.notNull(CommonErrorCode.UPDATE_FAILURE, updateUserProfile);
|
||||||
updateUserProfile.setId(userProfile.getId());
|
updateUserProfile.setId(userProfile.getId());
|
||||||
|
updateUserProfile.setCountryId(null);
|
||||||
|
|
||||||
// 处理背景照片:如果传入非null,则更新(包括空列表)
|
// 处理背景照片:如果传入非null,则更新(包括空列表)
|
||||||
if (cmd.getBackgroundPhotos() != null) {
|
if (cmd.getBackgroundPhotos() != null) {
|
||||||
@ -106,47 +96,28 @@ public class UpdateUserProfileCmdExe {
|
|||||||
// 计算年龄
|
// 计算年龄
|
||||||
processAge(updateUserProfile);
|
processAge(updateUserProfile);
|
||||||
|
|
||||||
processCountry(cmd, userProfile);
|
|
||||||
|
|
||||||
// 处理照片状态
|
// 处理照片状态
|
||||||
processPhotoStatus(updateUserProfile.getBackgroundPhotos(), userProfile.getBackgroundPhotos());
|
processPhotoStatus(updateUserProfile.getBackgroundPhotos(), userProfile.getBackgroundPhotos());
|
||||||
processPhotoStatus(updateUserProfile.getPersonalPhotos(), userProfile.getPersonalPhotos());
|
processPhotoStatus(updateUserProfile.getPersonalPhotos(), userProfile.getPersonalPhotos());
|
||||||
|
|
||||||
userProfileGateway.updateSelectiveById(updateUserProfile);
|
userProfileGateway.updateSelectiveById(updateUserProfile);
|
||||||
|
|
||||||
// 同步修改房间国家
|
|
||||||
if (Objects.nonNull(userProfile.getCountryCode()) && Objects.nonNull(
|
|
||||||
userProfile.getCountryName())) {
|
|
||||||
// 修改个人信息
|
|
||||||
updateBaseInfo(cmd, userProfile);
|
|
||||||
roomProfileManagerService.updateUserCountry(userProfile.getId(),
|
|
||||||
userProfile.getCountryCode(),
|
|
||||||
userProfile.getCountryName());
|
|
||||||
// 清除缓存
|
|
||||||
userProfileGateway.removeCacheAll(cmd.requiredReqUserId());
|
|
||||||
}
|
|
||||||
|
|
||||||
syncProperty(userProfile, cmd);
|
syncProperty(userProfile, cmd);
|
||||||
log.warn("cmd: {},{}", cmd, userProfile);
|
log.warn("cmd: {},{}", cmd, userProfile);
|
||||||
updateUserProfile.setOriginSys(cmd.requireReqSysOrigin());
|
updateUserProfile.setOriginSys(cmd.requireReqSysOrigin());
|
||||||
submitApproval(updateUserProfile);
|
submitApproval(updateUserProfile);
|
||||||
if (cmd.getCountryId() != null && cmd.getCountryId() > 0) {
|
|
||||||
// 更改国家 设置redis表示已修改 两年过期
|
|
||||||
redisService.setString("IS_UPDATE_COUNTRY:" + cmd.requiredReqUserId(), "1", 730, TimeUnit.DAYS);
|
|
||||||
}
|
|
||||||
|
|
||||||
cpRelationshipCacheService.remove(Collections.singletonList(cmd.requiredReqUserId()));
|
cpRelationshipCacheService.remove(Collections.singletonList(cmd.requiredReqUserId()));
|
||||||
|
|
||||||
return userProfileAppConvertor.toUserProfileDTO(userProfile);
|
return userProfileAppConvertor.toUserProfileDTO(userProfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateBaseInfo(UserProfileModifyCmd cmd, UserProfile userProfile) {
|
private void assertCountryNotChanged(UserProfileModifyCmd cmd, UserProfile userProfile) {
|
||||||
BaseInfo baseInfo = new BaseInfo();
|
// App 保存资料可能会携带当前国家 id,只拦截真实变更,避免昵称、头像等普通资料保存被误伤。
|
||||||
baseInfo.setId(cmd.requiredReqUserId());
|
if (Objects.nonNull(cmd.getCountryId())
|
||||||
baseInfo.setCountryId(userProfile.getCountryId());
|
&& !Objects.equals(userProfile.getCountryId(), cmd.getCountryId())) {
|
||||||
baseInfo.setCountryCode(userProfile.getCountryCode());
|
ResponseAssert.failure(UserErrorCode.USER_COUNTRY_UPDATE_NOT_ALLOWED);
|
||||||
baseInfo.setCountryName(userProfile.getCountryName());
|
}
|
||||||
baseInfoService.updateSelectiveById(baseInfo);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void submitApproval(UserProfile updateUserProfile) {
|
private void submitApproval(UserProfile updateUserProfile) {
|
||||||
@ -247,24 +218,6 @@ public class UpdateUserProfileCmdExe {
|
|||||||
userProfile.setBornDay(null);
|
userProfile.setBornDay(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processCountry(UserProfileModifyCmd cmd, UserProfile baseInfo) {
|
|
||||||
if (Objects.nonNull(cmd.getCountryId()) && !Objects.equals(baseInfo.getCountryId(),
|
|
||||||
cmd.getCountryId())) {
|
|
||||||
// 设置新国家
|
|
||||||
SysCountryCode sysCountryCode = sysCountryCodeService.getById(cmd.getCountryId());
|
|
||||||
if (Objects.nonNull(sysCountryCode)) {
|
|
||||||
baseInfo.setCountryCode(sysCountryCode.getAlphaTwo());
|
|
||||||
baseInfo.setCountryName(sysCountryCode.getCountryName());
|
|
||||||
baseInfo.setCountryId(sysCountryCode.getId());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
baseInfo.setCountryCode(null);
|
|
||||||
baseInfo.setCountryName(null);
|
|
||||||
baseInfo.setCountryId(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理照片状态:新照片设置为待审核,已存在照片保持原状态,空列表表示清空照片.
|
* 处理照片状态:新照片设置为待审核,已存在照片保持原状态,空列表表示清空照片.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user