refactor: 检查资源和项目关系支持批量id
This commit is contained in:
parent
e014f34d14
commit
d5ec1cf140
|
@ -2,6 +2,8 @@ package io.metersphere.system.mapper;
|
||||||
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface ExtCheckOwnerMapper {
|
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<String> ids);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,12 @@
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="io.metersphere.system.mapper.ExtCheckOwnerMapper">
|
<mapper namespace="io.metersphere.system.mapper.ExtCheckOwnerMapper">
|
||||||
<select id="checkoutOwner" resultType="boolean">
|
<select id="checkoutOwner" resultType="boolean">
|
||||||
SELECT 1
|
SELECT count(id) = ${ids.size()}
|
||||||
FROM ${table}
|
FROM ${table}
|
||||||
WHERE id = #{id}
|
WHERE project_id = #{projectId}
|
||||||
AND project_id = #{projectId}
|
and id in
|
||||||
|
<foreach collection="ids" item="id" separator="," open="(" close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
</select>
|
</select>
|
||||||
</mapper>
|
</mapper>
|
|
@ -22,6 +22,7 @@ import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
@Aspect
|
@Aspect
|
||||||
|
@ -68,7 +69,12 @@ public class CheckOwnerAspect {
|
||||||
Expression titleExp = parser.parseExpression(resourceId);
|
Expression titleExp = parser.parseExpression(resourceId);
|
||||||
Object v = titleExp.getValue(context, Object.class);
|
Object v = titleExp.getValue(context, Object.class);
|
||||||
if (v instanceof String id) {
|
if (v instanceof String id) {
|
||||||
if (!extCheckOwnerMapper.checkoutOwner(resourceType, SessionUtils.getCurrentProjectId(), id)) {
|
if (!extCheckOwnerMapper.checkoutOwner(resourceType, SessionUtils.getCurrentProjectId(), List.of(id))) {
|
||||||
|
throw new MSException(Translator.get("check_owner_case"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (v instanceof List ids) {
|
||||||
|
if (!extCheckOwnerMapper.checkoutOwner(resourceType, SessionUtils.getCurrentProjectId(), ids)) {
|
||||||
throw new MSException(Translator.get("check_owner_case"));
|
throw new MSException(Translator.get("check_owner_case"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue