From 87956215311215ae4c2699409a67824f968f4695 Mon Sep 17 00:00:00 2001 From: ronger Date: Mon, 3 Jan 2022 21:27:48 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E5=88=A0=E9=99=A4=E6=97=A0=E6=95=88?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/ArticleServiceImpl.java | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/rymcu/forest/service/impl/ArticleServiceImpl.java b/src/main/java/com/rymcu/forest/service/impl/ArticleServiceImpl.java index 10d344a..be8d1aa 100644 --- a/src/main/java/com/rymcu/forest/service/impl/ArticleServiceImpl.java +++ b/src/main/java/com/rymcu/forest/service/impl/ArticleServiceImpl.java @@ -143,7 +143,7 @@ public class ArticleServiceImpl extends AbstractService
implements Arti if (DEFAULT_STATUS.equals(newArticle.getArticleStatus())) { isUpdate = true; } - if (!user.getIdUser().equals(newArticle.getArticleAuthorId())) { + if (!isAuthor(newArticle.getArticleAuthorId())) { map.put("message", "非法访问!"); return map; } @@ -237,13 +237,9 @@ public class ArticleServiceImpl extends AbstractService
implements Arti @Transactional(rollbackFor = Exception.class) public Map delete(Integer id) throws BaseApiException { Map map = new HashMap(1); - // 鉴权 - User user = UserUtils.getCurrentUserByToken(); - if (Objects.isNull(user)) { - throw new BaseApiException(ErrorCode.INVALID_TOKEN); - } Article article = articleMapper.selectByPrimaryKey(id); - if (!user.getIdUser().equals(article.getArticleAuthorId())) { + // 鉴权 + if (!isAuthor(article.getArticleAuthorId())) { map.put("message", "非法访问!"); return map; } @@ -327,10 +323,15 @@ public class ArticleServiceImpl extends AbstractService
implements Arti Map map = new HashMap(2); Article article = articleMapper.selectByPrimaryKey(idArticle); if (Objects.nonNull(article)) { - article.setArticleTags(tags); - articleMapper.updateArticleTags(idArticle, tags); - tagService.saveTagArticle(article, ""); - map.put("success", true); + if (isAuthor(article.getArticleAuthorId())) { + article.setArticleTags(tags); + articleMapper.updateArticleTags(idArticle, tags); + tagService.saveTagArticle(article, ""); + map.put("success", true); + } else { + map.put("success", false); + map.put("message", "非法访问!"); + } } else { map.put("success", false); map.put("message", "更新失败,文章不存在!"); @@ -338,6 +339,14 @@ public class ArticleServiceImpl extends AbstractService
implements Arti return map; } + private boolean isAuthor(Integer idUser) throws BaseApiException { + User user = UserUtils.getCurrentUserByToken(); + if (Objects.nonNull(user)) { + return user.getIdUser().equals(idUser); + } + return false; + } + @Override public Map updatePerfect(Integer idArticle, String articlePerfect) { Map map = new HashMap(2);