fix: 修复处理组织checkowner时出现的问题

This commit is contained in:
CaptainB 2024-03-08 15:57:53 +08:00 committed by 刘瑞斌
parent bbb217e2c5
commit 95aad7082f
3 changed files with 30 additions and 0 deletions

View File

@ -8,4 +8,6 @@ public interface ExtCheckOwnerMapper {
boolean checkoutOwner(@Param("table") String resourceType, @Param("userId") String userId, @Param("ids") List<String> ids);
boolean checkoutOrganizationOwner(@Param("table") String resourceType, @Param("userId") String userId, @Param("ids") List<String> ids);
boolean checkoutOrganization(@Param("userId") String userId, @Param("ids") List<String> ids);
}

View File

@ -24,4 +24,17 @@
</foreach>)
AND user_id = #{userId}
</select>
<select id="checkoutOrganization" resultType="boolean">
SELECT count(1) > 0
FROM user_role_relation
WHERE source_id IN (SELECT id
FROM organization
WHERE organization.enable = TRUE
AND organization.id IN
<foreach collection="ids" item="id" separator="," open="(" close=")">
#{id}
</foreach>)
AND user_id = #{userId}
</select>
</mapper>

View File

@ -71,11 +71,26 @@ public class CheckOwnerAspect {
Object v = titleExp.getValue(context, Object.class);
if (orgResources.contains(resourceType)) {
handleOrganizationResource(v, resourceType);
} else if (StringUtils.equals(resourceType, "organization")) {
handleOrganization(v);
} else {
handleProjectResource(v, resourceType);
}
}
private void handleOrganization(Object v) {
if (v instanceof String id) {
if (!extCheckOwnerMapper.checkoutOrganization(SessionUtils.getUserId(), List.of(id))) {
throw new MSException(Translator.get("check_owner_case"));
}
}
if (v instanceof List ids) {
if (!extCheckOwnerMapper.checkoutOrganization(SessionUtils.getUserId(), ids)) {
throw new MSException(Translator.get("check_owner_case"));
}
}
}
private void handleProjectResource(Object v, String resourceType) {
if (v instanceof String id) {
if (!extCheckOwnerMapper.checkoutOwner(resourceType, SessionUtils.getUserId(), List.of(id))) {