ci: 增加check owner注解
This commit is contained in:
parent
d9f2193977
commit
b334bdd72d
|
@ -2,6 +2,8 @@ package io.metersphere.base.mapper.ext;
|
|||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ExtCheckOwnerMapper {
|
||||
boolean checkoutOwner(@Param("table") String resourceType, @Param("projectId") String projectId, @Param("id") String id);
|
||||
boolean checkoutOwner(@Param("table") String resourceType, @Param("projectId") String projectId, @Param("ids") List ids);
|
||||
}
|
||||
|
|
|
@ -2,9 +2,12 @@
|
|||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="io.metersphere.base.mapper.ext.ExtCheckOwnerMapper">
|
||||
<select id="checkoutOwner" resultType="boolean">
|
||||
SELECT 1
|
||||
SELECT count(id) = #{ids.size()}
|
||||
FROM ${table}
|
||||
WHERE id = #{id}
|
||||
AND project_id = #{projectId}
|
||||
WHERE project_id = #{projectId}
|
||||
and id in
|
||||
<foreach collection="ids" item="id" separator="," open="(" close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</select>
|
||||
</mapper>
|
|
@ -4,7 +4,6 @@ package io.metersphere.security;
|
|||
import io.metersphere.base.mapper.ext.ExtCheckOwnerMapper;
|
||||
import io.metersphere.commons.constants.UserGroupConstants;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import io.metersphere.i18n.Translator;
|
||||
import jakarta.annotation.Resource;
|
||||
|
@ -23,6 +22,8 @@ import org.springframework.expression.spel.support.StandardEvaluationContext;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Aspect
|
||||
|
@ -41,7 +42,7 @@ public class CheckOwnerAspect {
|
|||
|
||||
@Before("pointcut()")
|
||||
public void before(JoinPoint joinPoint) {
|
||||
try {
|
||||
|
||||
//从切面织入点处通过反射机制获取织入点处的方法
|
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||
//获取切入点所在的方法
|
||||
|
@ -72,13 +73,14 @@ public class CheckOwnerAspect {
|
|||
Expression titleExp = parser.parseExpression(resourceId);
|
||||
Object v = titleExp.getValue(context, Object.class);
|
||||
if (v instanceof String id) {
|
||||
if (!extCheckOwnerMapper.checkoutOwner(resourceType, SessionUtils.getCurrentProjectId(), id)) {
|
||||
if (!extCheckOwnerMapper.checkoutOwner(resourceType, SessionUtils.getCurrentProjectId(), List.of(id))) {
|
||||
MSException.throwException(Translator.get("check_owner_case"));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e.getMessage(), e);
|
||||
if (v instanceof List ids) {
|
||||
if (!extCheckOwnerMapper.checkoutOwner(resourceType, SessionUtils.getCurrentProjectId(), ids)) {
|
||||
MSException.throwException(Translator.get("check_owner_case"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue