fix: default pass profile approvals before review

- make user/room/family/photo profile assets visible before follow-up review

- disable Tencent censor by default with a config switch

- replace the missing SUD auth dependency with an in-repo implementation so deploy-machine builds can pass
This commit is contained in:
hy001 2026-04-15 18:05:05 +08:00
parent b2938a17bf
commit ad0feebfb2
16 changed files with 452 additions and 225 deletions

View File

@ -62,12 +62,6 @@
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
<groupId>com.github.sud</groupId>
<artifactId>sud-mgp-auth-java</artifactId>
<version>1.0.4</version>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>

View File

@ -0,0 +1,25 @@
package com.red.circle.external.app.censor;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* 腾讯云内容审核配置.
*/
@Component
@ConfigurationProperties(prefix = "red-circle.censor.tencent")
public class TencentCensorProperties {
/**
* 是否启用腾讯云内容审核.
*/
private boolean enabled = false;
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
}

View File

@ -2,10 +2,13 @@ package com.red.circle.external.inner.service.censor.impl;
import com.red.circle.component.censor.api.AuditingRequest;
import com.red.circle.component.censor.api.ICensorImageService;
import com.red.circle.external.app.censor.TencentCensorProperties;
import com.red.circle.external.inner.convertor.CensorImageInnerConvertor;
import com.red.circle.external.inner.model.dto.CensorImageResponseDTO;
import com.red.circle.external.inner.model.dto.CensorSuggestion;
import com.red.circle.external.inner.service.censor.CensorImageClientService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
@ -13,15 +16,25 @@ import org.springframework.stereotype.Service;
*
* @author pengliang on 2023/10/17
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class CensorImageClientServiceImpl implements CensorImageClientService {
private final ICensorImageService censorImageService;
private final CensorImageInnerConvertor censorImageInnerConvertor;
private final TencentCensorProperties tencentCensorProperties;
@Override
public CensorImageResponseDTO auditing(String detectUrl) {
if (!tencentCensorProperties.isEnabled()) {
log.info("Tencent censor disabled, skip auditing. detectUrl={}", detectUrl);
CensorImageResponseDTO response = new CensorImageResponseDTO();
response.setDetectUrl(detectUrl);
response.setSuggestion(CensorSuggestion.Pass);
return response;
}
AuditingRequest request = new AuditingRequest();
request.setDetectUrl(detectUrl);
return censorImageInnerConvertor.toCensorImageResponseDTO(censorImageService.auditing(request));

View File

@ -38,3 +38,8 @@ management:
rtc:
appId: ceb9e2620d454bca9725f7a7f11d4019
certificate: 1fe700671f1641a8b42a474d4ad990a7
red-circle:
censor:
tencent:
enabled: false

View File

@ -91,6 +91,7 @@ public class FamilyCreateExe {
checkCreateWhereAndPayCandy(cmd);
familyMessageService.cancelUserPendingMessages(cmd.getReqUserId());
addApproveRecord(cmd);
return familyId;
@ -109,14 +110,15 @@ public class FamilyCreateExe {
Long createUserId = cmd.getReqUserId();
String sysOrigin = cmd.getReqSysOrigin().getOrigin();
if (StringUtils.isNotBlank(cmd.getFamilyAvatar())) {
approvalUserSettingDataService.saveOrUpdateApproval(createUserId, sysOrigin,
DataApprovalTypeEnum.FAMILY_AVATAR);
}
if (StringUtils.isNotBlank(cmd.getFamilyName())) {
approvalUserSettingDataService.saveOrUpdateApproval(createUserId, sysOrigin,
DataApprovalTypeEnum.FAMILY_NICKNAME);
approvalUserSettingDataService.saveOrUpdateApproval(createUserId, sysOrigin,
DataApprovalTypeEnum.FAMILY_NOTICE);
}
}
private void sendHonor(FamilyCreateCmd cmd, FamilyLevelConfig levelConfig) {

View File

@ -56,9 +56,21 @@ public class FamilyInfoEditExe {
FamilyBaseInfo baseInfo = familyBaseInfoService.getBaseInfoById(manageMember.getFamilyId());
ResponseAssert.notNull(FamilyErrorCode.NOT_EXIST_FAMILY_INFO_DATA, baseInfo);
boolean noticeChanged = StringUtils.isNotBlank(cmd.getFamilyNotice());
boolean avatarChanged = StringUtils.isNotBlank(cmd.getFamilyAvatar());
boolean nameChanged = StringUtils.isNotBlank(cmd.getFamilyName());
boolean noticeChanged = cmd.getFamilyNotice() != null;
familyBaseInfoService.updateSelectiveById(getFamilyBaseInfo(cmd, manageMember.getFamilyId()));
if (avatarChanged) {
saveApproval(cmd, DataApprovalTypeEnum.FAMILY_AVATAR);
}
if (nameChanged) {
saveApproval(cmd, DataApprovalTypeEnum.FAMILY_NICKNAME);
}
if (noticeChanged) {
saveApproval(cmd, DataApprovalTypeEnum.FAMILY_NOTICE);
}
FamilyNewsTypeEnum newsType = noticeChanged
? FamilyNewsTypeEnum.FAMILY_NOTICE_EDIT
: FamilyNewsTypeEnum.FAMILY_INFO_EDIT;

View File

@ -136,7 +136,7 @@ public class UpdateUserProfileCmdExe {
syncProperty(userProfile, cmd);
log.warn("cmd {},{}", cmd, userProfile);
updateUserProfile.setOriginSys(cmd.requireReqSysOrigin());
submitApproval(updateUserProfile);
submitApproval(updateUserProfile, userProfile);
if (cmd.getCountryId() != null && cmd.getCountryId() > 0) {
// 更改国家 设置redis表示已修改 两年过期
redisService.setString("IS_UPDATE_COUNTRY:" + cmd.requiredReqUserId(), "1", 730, TimeUnit.DAYS);
@ -156,7 +156,7 @@ public class UpdateUserProfileCmdExe {
baseInfoService.updateSelectiveById(baseInfo);
}
private void submitApproval(UserProfile updateUserProfile) {
private void submitApproval(UserProfile updateUserProfile, UserProfile originalUserProfile) {
List<ProfileApprovalContent> approvalParam = CollectionUtils.newArrayList();
if (StringUtils.isNotBlank(updateUserProfile.getUserAvatar())) {
approvalParam.add(
@ -183,35 +183,10 @@ public class UpdateUserProfileCmdExe {
)
);
}
// 背景照片审核
if (CollectionUtils.isNotEmpty(updateUserProfile.getBackgroundPhotos())) {
for (PhotoItem photo : updateUserProfile.getBackgroundPhotos()) {
if (StringUtils.isNotBlank(photo.getUrl()) && PhotoAuditStatus.PENDING.getCode().equals(photo.getStatus())) {
approvalParam.add(
new ProfileApprovalContent()
.setBeUserId(updateUserProfile.getId())
.setSysOrigin(updateUserProfile.getOriginSys())
.setApprovalType(DataApprovalTypeEnum.BACKGROUND_PHOTO)
.addContent(updateUserProfile.getId(), photo.getUrl())
);
}
}
}
// 个人形象照片审核
if (CollectionUtils.isNotEmpty(updateUserProfile.getPersonalPhotos())) {
for (PhotoItem photo : updateUserProfile.getPersonalPhotos()) {
if (StringUtils.isNotBlank(photo.getUrl()) && PhotoAuditStatus.PENDING.getCode().equals(photo.getStatus())) {
approvalParam.add(
new ProfileApprovalContent()
.setBeUserId(updateUserProfile.getId())
.setSysOrigin(updateUserProfile.getOriginSys())
.setApprovalType(DataApprovalTypeEnum.PERSONAL_PHOTO)
.addContent(updateUserProfile.getId(), photo.getUrl())
);
}
}
}
addNewPhotoApproval(approvalParam, updateUserProfile, updateUserProfile.getBackgroundPhotos(),
originalUserProfile.getBackgroundPhotos(), DataApprovalTypeEnum.BACKGROUND_PHOTO);
addNewPhotoApproval(approvalParam, updateUserProfile, updateUserProfile.getPersonalPhotos(),
originalUserProfile.getPersonalPhotos(), DataApprovalTypeEnum.PERSONAL_PHOTO);
if (CollectionUtils.isNotEmpty(approvalParam)) {
profileApprovalGateway.submitApprovalBatch(approvalParam);
@ -219,6 +194,32 @@ public class UpdateUserProfileCmdExe {
}
private void addNewPhotoApproval(List<ProfileApprovalContent> approvalParam,
UserProfile updateUserProfile, List<PhotoItem> newPhotos, List<PhotoItem> originalPhotos,
DataApprovalTypeEnum approvalType) {
if (CollectionUtils.isEmpty(newPhotos)) {
return;
}
for (PhotoItem photo : newPhotos) {
if (StringUtils.isBlank(photo.getUrl()) || !isNewPhoto(photo, originalPhotos)) {
continue;
}
approvalParam.add(
new ProfileApprovalContent()
.setBeUserId(updateUserProfile.getId())
.setSysOrigin(updateUserProfile.getOriginSys())
.setApprovalType(approvalType)
.addContent(updateUserProfile.getId(), photo.getUrl())
);
}
}
private boolean isNewPhoto(PhotoItem photo, List<PhotoItem> originalPhotos) {
return CollectionUtils.isEmpty(originalPhotos)
|| originalPhotos.stream().noneMatch(item -> Objects.equals(item.getUrl(), photo.getUrl()));
}
private void syncProperty(UserProfile oldProfile, UserProfileModifyCmd cmd) {
if (StringUtils.isNotBlank(cmd.getUserNickname())) {
@ -273,7 +274,7 @@ public class UpdateUserProfileCmdExe {
}
/**
* 处理照片状态新照片设置为待审核已存在照片保持原状态空列表表示清空照片.
* 处理照片状态新照片默认先通过机审回写最终状态已存在照片保持原状态.
*/
private void processPhotoStatus(List<PhotoItem> newPhotos, List<PhotoItem> originalPhotos) {
if (newPhotos == null) {
@ -289,7 +290,7 @@ public class UpdateUserProfileCmdExe {
|| originalPhotos.stream().noneMatch(p -> Objects.equals(p.getUrl(), photo.getUrl()));
if (isNew) {
photo.setStatus(PhotoAuditStatus.PENDING.getCode());
photo.setStatus(PhotoAuditStatus.APPROVED.getCode());
} else {
originalPhotos.stream()
.filter(p -> Objects.equals(p.getUrl(), photo.getUrl()))

View File

@ -76,7 +76,7 @@ public interface UserProfileAppConvertor {
.filter(url -> url != null && !url.trim().isEmpty())
.map(url -> new PhotoItem()
.setUrl(url)
.setStatus(PhotoAuditStatus.PENDING.getCode())
.setStatus(PhotoAuditStatus.APPROVED.getCode())
.setCreateTime(Timestamp.valueOf(LocalDateTime.now())))
.collect(Collectors.toList());
}

View File

@ -286,7 +286,7 @@ public class CensorProfileListener implements MessageListener {
String labelNames = response.formatLabelString();
if (!response.checkPass()) {
if (response.checkBlock()) {
// 审核不通过记录违规
photoViolationHandle(param.getUserId(), censorContent.getContent(), labelNames, approvalType);
// 更新MongoDB中图片状态

View File

@ -65,7 +65,11 @@ public class CreateRoomSuccessListener implements MessageListener {
}
try {
approvalUserSettingDataService.saveBatchApproval(cmd.getUserId(), cmd.getSysOrigin(), approvalTypes);
approvalTypes.forEach(approvalType -> approvalUserSettingDataService.saveOrUpdateApproval(
cmd.getUserId(),
cmd.getSysOrigin(),
approvalType
));
} catch (Exception ex) {
log.error("{}", Throwables.getStackTraceAsString(ex));
}

View File

@ -0,0 +1,31 @@
package tech.sud.mgp.auth.api;
public class SudCode {
private final String code;
private final Long expireDate;
private final boolean success;
private final Integer sdkErrorCode;
public SudCode(String code, Long expireDate, boolean success, Integer sdkErrorCode) {
this.code = code;
this.expireDate = expireDate;
this.success = success;
this.sdkErrorCode = sdkErrorCode;
}
public String getCode() {
return code;
}
public Long getExpireDate() {
return expireDate;
}
public boolean isSuccess() {
return success;
}
public Integer getSdkErrorCode() {
return sdkErrorCode;
}
}

View File

@ -0,0 +1,82 @@
package tech.sud.mgp.auth.api;
import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.exceptions.JWTVerificationException;
import com.auth0.jwt.interfaces.DecodedJWT;
import java.util.Date;
import java.util.Objects;
/**
* Minimal in-repo replacement for the original SUD auth SDK.
* The project only uses round-trip code generation and verification on our own backend,
* so a signed JWT is enough to preserve the current integration flow.
*/
public class SudMGPAuth {
private static final String CLAIM_UID = "uid";
private static final String CLAIM_TYPE = "type";
private static final String TOKEN_TYPE_CODE = "code";
private static final int ERROR_INVALID_TOKEN = 10001;
private static final int ERROR_TOKEN_EXPIRED = 10002;
private static final int ERROR_INVALID_ARGUMENT = 10003;
private static final long DEFAULT_EXPIRE_MILLIS = 24 * 60 * 60 * 1000L;
private final String appId;
private final Algorithm algorithm;
private final JWTVerifier codeVerifier;
public SudMGPAuth(String appId, String appSecret) {
this.appId = appId;
this.algorithm = Algorithm.HMAC256(appSecret);
this.codeVerifier = JWT.require(algorithm)
.withIssuer(appId)
.withClaim(CLAIM_TYPE, TOKEN_TYPE_CODE)
.build();
}
public SudCode getCode(String uid, Long expireDuration) {
if (uid == null || uid.isBlank()) {
return new SudCode(null, null, false, ERROR_INVALID_ARGUMENT);
}
long expireMillis = System.currentTimeMillis() + normalizedExpire(expireDuration);
String code = JWT.create()
.withIssuer(appId)
.withIssuedAt(new Date())
.withExpiresAt(new Date(expireMillis))
.withClaim(CLAIM_UID, uid)
.withClaim(CLAIM_TYPE, TOKEN_TYPE_CODE)
.sign(algorithm);
return new SudCode(code, expireMillis, true, 0);
}
public SudUid getUidByCode(String code) {
if (code == null || code.isBlank()) {
return new SudUid(null, false, ERROR_INVALID_ARGUMENT);
}
try {
DecodedJWT decodedJWT = codeVerifier.verify(code);
String uid = decodedJWT.getClaim(CLAIM_UID).asString();
if (uid == null || uid.isBlank()) {
return new SudUid(null, false, ERROR_INVALID_TOKEN);
}
return new SudUid(uid, true, 0);
} catch (com.auth0.jwt.exceptions.TokenExpiredException ex) {
return new SudUid(null, false, ERROR_TOKEN_EXPIRED);
} catch (JWTVerificationException ex) {
return new SudUid(null, false, ERROR_INVALID_TOKEN);
}
}
public boolean verifyCode(String code) {
return getUidByCode(code).isSuccess();
}
private static long normalizedExpire(Long expireDuration) {
if (Objects.isNull(expireDuration) || expireDuration <= 0) {
return DEFAULT_EXPIRE_MILLIS;
}
return expireDuration;
}
}

View File

@ -0,0 +1,25 @@
package tech.sud.mgp.auth.api;
public class SudUid {
private final String uid;
private final boolean success;
private final Integer sdkErrorCode;
public SudUid(String uid, boolean success, Integer sdkErrorCode) {
this.uid = uid;
this.success = success;
this.sdkErrorCode = sdkErrorCode;
}
public String getUid() {
return uid;
}
public boolean isSuccess() {
return success;
}
public Integer getSdkErrorCode() {
return sdkErrorCode;
}
}

View File

@ -50,6 +50,17 @@ public interface ApprovalUserSettingDataService extends BaseService<ApprovalUser
*/
void saveOrUpdateApproval(Long userId, String sysOrigin, DataApprovalTypeEnum approveType);
/**
* 审批类型.
*
* @param userId 用户id
* @param sysOrigin 系统来源
* @param approveType 审批类型
* @param approvalStatusEnum 初始化状态
*/
void saveOrUpdateApproval(Long userId, String sysOrigin, DataApprovalTypeEnum approveType,
ApprovalStatusEnum approvalStatusEnum);
/**
* 设置审批状态.
*

View File

@ -61,8 +61,15 @@ public class ApprovalUserSettingDataServiceImpl extends
@Override
public void saveOrUpdateApproval(Long userId, String sysOrigin,
DataApprovalTypeEnum approveType) {
saveOrUpdateApproval(userId, sysOrigin, approveType, initialApprovalStatus(approveType));
}
@Override
public void saveOrUpdateApproval(Long userId, String sysOrigin,
DataApprovalTypeEnum approveType, ApprovalStatusEnum approvalStatusEnum) {
if (existsByUserApprovalType(userId, approveType)) {
update().set(ApprovalUserSettingData::getApproveStatus, ApprovalStatusEnum.PENDING)
update().set(ApprovalUserSettingData::getApproveStatus, approvalStatusEnum)
.set(ApprovalUserSettingData::getMachineLabel, StringUtils.EMPTY)
.eq(ApprovalUserSettingData::getUserId, userId)
.eq(ApprovalUserSettingData::getApproveType, approveType)
.last(PageConstant.LIMIT_ONE)
@ -75,7 +82,8 @@ public class ApprovalUserSettingDataServiceImpl extends
.setUserId(userId)
.setSysOrigin(sysOrigin)
.setApproveType(approveType.name())
.setApproveStatus(ApprovalStatusEnum.PENDING.name())
.setApproveStatus(approvalStatusEnum.name())
.setMachineLabel(StringUtils.EMPTY)
.setNotPassSize(0)
);
} catch (DuplicateKeyException ignore) {
@ -102,7 +110,7 @@ public class ApprovalUserSettingDataServiceImpl extends
.setSysOrigin(sysOriginPlatform)
.setUserId(userId)
.setApproveType(approvalTypeEnum.name())
.setApproveStatus(ApprovalStatusEnum.PENDING.name())
.setApproveStatus(initialApprovalStatus(approvalTypeEnum).name())
.setMachineLabel("")
.setNotPassSize(0);
approvalUserSettingData.setCreateTime(TimestampUtils.now());
@ -181,6 +189,20 @@ public class ApprovalUserSettingDataServiceImpl extends
.orElse(Boolean.FALSE);
}
private ApprovalStatusEnum initialApprovalStatus(DataApprovalTypeEnum approveType) {
if (Objects.isNull(approveType)) {
return ApprovalStatusEnum.PENDING;
}
return switch (approveType) {
case NICKNAME, AVATAR, PHOTO_WALL, ROOM_NICKNAME, ROOM_AVATAR, ROOM_NOTICE,
PROFILE_DESC, FAMILY_AVATAR, FAMILY_NICKNAME, FAMILY_NOTICE, DYNAMIC_CONTENT,
TEAM_AVATAR, TEAM_NICKNAME, BACKGROUND_PHOTO, PERSONAL_PHOTO ->
ApprovalStatusEnum.PASS;
default -> ApprovalStatusEnum.PENDING;
};
}
@Override
public void deleteFamilyApproval(Long userId) {