fix:知识库编辑权限
This commit is contained in:
parent
37ad9bc288
commit
0a2f2c1d70
|
@ -71,6 +71,7 @@ public class KnowledgeBaseService extends ServiceImpl<KnowledgeBaseMapper, Knowl
|
||||||
knowledgeBase.setOwnerName(user.getName());
|
knowledgeBase.setOwnerName(user.getName());
|
||||||
baseMapper.insert(knowledgeBase);
|
baseMapper.insert(knowledgeBase);
|
||||||
} else {
|
} else {
|
||||||
|
checkPrivilege(kbEditReq.getId(), null);
|
||||||
knowledgeBase.setId(kbEditReq.getId());
|
knowledgeBase.setId(kbEditReq.getId());
|
||||||
baseMapper.updateById(knowledgeBase);
|
baseMapper.updateById(knowledgeBase);
|
||||||
}
|
}
|
||||||
|
@ -83,6 +84,7 @@ public class KnowledgeBaseService extends ServiceImpl<KnowledgeBaseMapper, Knowl
|
||||||
if (ArrayUtils.isEmpty(docs)) {
|
if (ArrayUtils.isEmpty(docs)) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
checkPrivilege(null, kbUuid);
|
||||||
List<AdiFile> result = new ArrayList<>();
|
List<AdiFile> result = new ArrayList<>();
|
||||||
KnowledgeBase knowledgeBase = ChainWrappers.lambdaQueryChain(baseMapper)
|
KnowledgeBase knowledgeBase = ChainWrappers.lambdaQueryChain(baseMapper)
|
||||||
.eq(KnowledgeBase::getUuid, kbUuid)
|
.eq(KnowledgeBase::getUuid, kbUuid)
|
||||||
|
@ -162,8 +164,7 @@ public class KnowledgeBaseService extends ServiceImpl<KnowledgeBaseMapper, Knowl
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean embedding(String kbUuid, boolean forceAll) {
|
public boolean embedding(String kbUuid, boolean forceAll) {
|
||||||
boolean privilege = checkPrivilege(null, kbUuid);
|
checkPrivilege(null, kbUuid);
|
||||||
if (!privilege) throw new BaseException(A_USER_NOT_AUTH);
|
|
||||||
LambdaQueryWrapper<KnowledgeBaseItem> wrapper = new LambdaQueryWrapper();
|
LambdaQueryWrapper<KnowledgeBaseItem> wrapper = new LambdaQueryWrapper();
|
||||||
wrapper.eq(KnowledgeBaseItem::getIsDeleted, false);
|
wrapper.eq(KnowledgeBaseItem::getIsDeleted, false);
|
||||||
wrapper.eq(KnowledgeBaseItem::getUuid, kbUuid);
|
wrapper.eq(KnowledgeBaseItem::getUuid, kbUuid);
|
||||||
|
@ -186,8 +187,7 @@ public class KnowledgeBaseService extends ServiceImpl<KnowledgeBaseMapper, Knowl
|
||||||
|
|
||||||
|
|
||||||
public boolean softDelete(String uuid) {
|
public boolean softDelete(String uuid) {
|
||||||
boolean privs = checkPrivilege(null, uuid);
|
checkPrivilege(null, uuid);
|
||||||
if (!privs) throw new BaseException(A_USER_NOT_AUTH);
|
|
||||||
return ChainWrappers.lambdaUpdateChain(baseMapper)
|
return ChainWrappers.lambdaUpdateChain(baseMapper)
|
||||||
.eq(KnowledgeBase::getUuid, uuid)
|
.eq(KnowledgeBase::getUuid, uuid)
|
||||||
.set(KnowledgeBase::getIsDeleted, true)
|
.set(KnowledgeBase::getIsDeleted, true)
|
||||||
|
@ -225,7 +225,7 @@ public class KnowledgeBaseService extends ServiceImpl<KnowledgeBaseMapper, Knowl
|
||||||
.oneOpt().orElseThrow(() -> new BaseException(A_DATA_NOT_FOUND));
|
.oneOpt().orElseThrow(() -> new BaseException(A_DATA_NOT_FOUND));
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkPrivilege(Long kbId, String kbUuid) {
|
private void checkPrivilege(Long kbId, String kbUuid) {
|
||||||
if (null == kbId && StringUtils.isBlank(kbUuid)) {
|
if (null == kbId && StringUtils.isBlank(kbUuid)) {
|
||||||
throw new BaseException(A_PARAMS_ERROR);
|
throw new BaseException(A_PARAMS_ERROR);
|
||||||
}
|
}
|
||||||
|
@ -235,7 +235,7 @@ public class KnowledgeBaseService extends ServiceImpl<KnowledgeBaseMapper, Knowl
|
||||||
}
|
}
|
||||||
boolean privilege = user.getIsAdmin();
|
boolean privilege = user.getIsAdmin();
|
||||||
if (privilege) {
|
if (privilege) {
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
LambdaQueryWrapper<KnowledgeBase> wrapper = new LambdaQueryWrapper();
|
LambdaQueryWrapper<KnowledgeBase> wrapper = new LambdaQueryWrapper();
|
||||||
wrapper.eq(KnowledgeBase::getOwnerId, user.getId());
|
wrapper.eq(KnowledgeBase::getOwnerId, user.getId());
|
||||||
|
@ -244,6 +244,9 @@ public class KnowledgeBaseService extends ServiceImpl<KnowledgeBaseMapper, Knowl
|
||||||
} else if (StringUtils.isNotBlank(kbUuid)) {
|
} else if (StringUtils.isNotBlank(kbUuid)) {
|
||||||
wrapper = wrapper.eq(KnowledgeBase::getUuid, kbUuid);
|
wrapper = wrapper.eq(KnowledgeBase::getUuid, kbUuid);
|
||||||
}
|
}
|
||||||
return baseMapper.exists(wrapper);
|
boolean exists = baseMapper.exists(wrapper);
|
||||||
|
if (!exists) {
|
||||||
|
throw new BaseException(A_USER_NOT_AUTH);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
where is_deleted = false
|
where is_deleted = false
|
||||||
<choose>
|
<choose>
|
||||||
<when test="includeOthersPublic">
|
<when test="includeOthersPublic">
|
||||||
nd (is_public = true or owner_id = #{ownerId})
|
and (is_public = true or owner_id = #{ownerId})
|
||||||
</when>
|
</when>
|
||||||
<otherwise>
|
<otherwise>
|
||||||
and owner_id = #{ownerId}
|
and owner_id = #{ownerId}
|
||||||
|
|
Loading…
Reference in New Issue