From f16cf81a77dabe174c250c3cf806f98d9da4b568 Mon Sep 17 00:00:00 2001 From: zhx Date: Fri, 26 Jun 2026 16:02:16 +0800 Subject: [PATCH] fix: block app country updates --- .../inner/asserts/user/UserErrorCode.java | 5 ++ .../command/user/UpdateUserProfileCmdExe.java | 63 +++---------------- 2 files changed, 13 insertions(+), 55 deletions(-) diff --git a/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/asserts/user/UserErrorCode.java b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/asserts/user/UserErrorCode.java index f2050f34..ee0d5db5 100644 --- a/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/asserts/user/UserErrorCode.java +++ b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/asserts/user/UserErrorCode.java @@ -244,6 +244,11 @@ public enum UserErrorCode implements IResponseErrorCode { */ TASK_TIER_NOT_FOUND(4079, "Task tier not found"), + /** + * App 不允许用户自己修改国家. + */ + USER_COUNTRY_UPDATE_NOT_ALLOWED(4080, "Country cannot be changed"), + ; diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/UpdateUserProfileCmdExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/UpdateUserProfileCmdExe.java index 5fb986b0..9caacc7a 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/UpdateUserProfileCmdExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/UpdateUserProfileCmdExe.java @@ -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.constant.KeywordConstant; 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.framework.core.asserts.ResponseAssert; 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.user.UserProfile; 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.tool.core.collection.CollectionUtils; 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.model.dto.user.UserProfileDTO; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Objects; -import java.util.concurrent.TimeUnit; import lombok.RequiredArgsConstructor; import org.slf4j.Logger; @@ -52,12 +44,8 @@ public class UpdateUserProfileCmdExe { private static final Logger log = LoggerFactory.getLogger(UpdateUserProfileCmdExe.class); private final OssServiceClient ossServiceClient; private final UserProfileGateway userProfileGateway; - private final RedisService redisService; - private final BaseInfoService baseInfoService; - private final SysCountryCodeService sysCountryCodeService; private final ProfileApprovalGateway profileApprovalGateway; private final UserProfileAppConvertor userProfileAppConvertor; - private final RoomProfileManagerService roomProfileManagerService; private final CpRelationshipCacheService cpRelationshipCacheService; public UserProfileDTO execute(UserProfileModifyCmd cmd) { @@ -68,6 +56,7 @@ public class UpdateUserProfileCmdExe { userProfileGateway.removeCacheAll(cmd.requiredReqUserId()); UserProfile userProfile = userProfileGateway.getByUserId(cmd.requiredReqUserId()); ResponseAssert.notNull(UserErrorCode.USER_INFO_NOT_FOUND, userProfile); + assertCountryNotChanged(cmd, userProfile); if (StringUtils.isNotBlank(cmd.getUserAvatar())) { cmd.setUserAvatar(ossServiceClient.processImgSaveAsCompressZoom(cmd.getUserAvatar(), ImageSizeConst.COVER_HEIGHT).getBody() @@ -77,6 +66,7 @@ public class UpdateUserProfileCmdExe { UserProfile updateUserProfile = userProfileAppConvertor.toUserProfile(cmd); ResponseAssert.notNull(CommonErrorCode.UPDATE_FAILURE, updateUserProfile); updateUserProfile.setId(userProfile.getId()); + updateUserProfile.setCountryId(null); // 处理背景照片:如果传入非null,则更新(包括空列表) if (cmd.getBackgroundPhotos() != null) { @@ -106,47 +96,28 @@ public class UpdateUserProfileCmdExe { // 计算年龄 processAge(updateUserProfile); - processCountry(cmd, userProfile); - // 处理照片状态 processPhotoStatus(updateUserProfile.getBackgroundPhotos(), userProfile.getBackgroundPhotos()); processPhotoStatus(updateUserProfile.getPersonalPhotos(), userProfile.getPersonalPhotos()); 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); log.warn("cmd: {},{}", cmd, userProfile); updateUserProfile.setOriginSys(cmd.requireReqSysOrigin()); 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())); return userProfileAppConvertor.toUserProfileDTO(userProfile); } - private void updateBaseInfo(UserProfileModifyCmd cmd, UserProfile userProfile) { - BaseInfo baseInfo = new BaseInfo(); - baseInfo.setId(cmd.requiredReqUserId()); - baseInfo.setCountryId(userProfile.getCountryId()); - baseInfo.setCountryCode(userProfile.getCountryCode()); - baseInfo.setCountryName(userProfile.getCountryName()); - baseInfoService.updateSelectiveById(baseInfo); + private void assertCountryNotChanged(UserProfileModifyCmd cmd, UserProfile userProfile) { + // App 保存资料可能会携带当前国家 id,只拦截真实变更,避免昵称、头像等普通资料保存被误伤。 + if (Objects.nonNull(cmd.getCountryId()) + && !Objects.equals(userProfile.getCountryId(), cmd.getCountryId())) { + ResponseAssert.failure(UserErrorCode.USER_COUNTRY_UPDATE_NOT_ALLOWED); + } } private void submitApproval(UserProfile updateUserProfile) { @@ -247,24 +218,6 @@ public class UpdateUserProfileCmdExe { 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); - } - /** * 处理照片状态:新照片设置为待审核,已存在照片保持原状态,空列表表示清空照片. */