Skip to content

Commit

Permalink
fix:知识库编辑权限
Browse files Browse the repository at this point in the history
  • Loading branch information
moyangzhan committed Feb 19, 2024
1 parent 37ad9bc commit 0a2f2c1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public KnowledgeBase saveOrUpdate(KbEditReq kbEditReq) {
knowledgeBase.setOwnerName(user.getName());
baseMapper.insert(knowledgeBase);
} else {
checkPrivilege(kbEditReq.getId(), null);
knowledgeBase.setId(kbEditReq.getId());
baseMapper.updateById(knowledgeBase);
}
Expand All @@ -83,6 +84,7 @@ public List<AdiFile> uploadDocs(String kbUuid, Boolean embedding, MultipartFile[
if (ArrayUtils.isEmpty(docs)) {
return Collections.emptyList();
}
checkPrivilege(null, kbUuid);
List<AdiFile> result = new ArrayList<>();
KnowledgeBase knowledgeBase = ChainWrappers.lambdaQueryChain(baseMapper)
.eq(KnowledgeBase::getUuid, kbUuid)
Expand Down Expand Up @@ -162,8 +164,7 @@ private AdiFile uploadDoc(KnowledgeBase knowledgeBase, MultipartFile doc, Boolea
}

public boolean embedding(String kbUuid, boolean forceAll) {
boolean privilege = checkPrivilege(null, kbUuid);
if (!privilege) throw new BaseException(A_USER_NOT_AUTH);
checkPrivilege(null, kbUuid);
LambdaQueryWrapper<KnowledgeBaseItem> wrapper = new LambdaQueryWrapper();
wrapper.eq(KnowledgeBaseItem::getIsDeleted, false);
wrapper.eq(KnowledgeBaseItem::getUuid, kbUuid);
Expand All @@ -186,8 +187,7 @@ public Page<KnowledgeBase> search(String keyword, Boolean includeOthersPublic, I


public boolean softDelete(String uuid) {
boolean privs = checkPrivilege(null, uuid);
if (!privs) throw new BaseException(A_USER_NOT_AUTH);
checkPrivilege(null, uuid);
return ChainWrappers.lambdaUpdateChain(baseMapper)
.eq(KnowledgeBase::getUuid, uuid)
.set(KnowledgeBase::getIsDeleted, true)
Expand Down Expand Up @@ -225,7 +225,7 @@ public KnowledgeBase getOrThrow(String kbUuid) {
.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)) {
throw new BaseException(A_PARAMS_ERROR);
}
Expand All @@ -235,7 +235,7 @@ private boolean checkPrivilege(Long kbId, String kbUuid) {
}
boolean privilege = user.getIsAdmin();
if (privilege) {
return true;
return;
}
LambdaQueryWrapper<KnowledgeBase> wrapper = new LambdaQueryWrapper();
wrapper.eq(KnowledgeBase::getOwnerId, user.getId());
Expand All @@ -244,6 +244,9 @@ private boolean checkPrivilege(Long kbId, String kbUuid) {
} else if (StringUtils.isNotBlank(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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
where is_deleted = false
<choose>
<when test="includeOthersPublic">
nd (is_public = true or owner_id = #{ownerId})
and (is_public = true or owner_id = #{ownerId})
</when>
<otherwise>
and owner_id = #{ownerId}
Expand Down

0 comments on commit 0a2f2c1

Please sign in to comment.