From 997e86c4e827e37a64f95cb5523056ee37ef144d Mon Sep 17 00:00:00 2001 From: Alex Bogdanovski Date: Mon, 16 Oct 2023 20:34:53 +0300 Subject: [PATCH] added new moderation button to quickly convert an answer to a comment --- .../controllers/QuestionController.java | 27 +++++++++++++++++++ src/main/resources/lang_en.properties | 1 + src/main/resources/static/scripts/scoold.js | 5 ++-- src/main/resources/templates/macro.vm | 6 +++++ 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/erudika/scoold/controllers/QuestionController.java b/src/main/java/com/erudika/scoold/controllers/QuestionController.java index 541e9438..2f34123b 100755 --- a/src/main/java/com/erudika/scoold/controllers/QuestionController.java +++ b/src/main/java/com/erudika/scoold/controllers/QuestionController.java @@ -28,6 +28,7 @@ import com.erudika.scoold.ScooldConfig; import static com.erudika.scoold.ScooldServer.QUESTIONSLINK; import static com.erudika.scoold.ScooldServer.SIGNINLINK; +import com.erudika.scoold.core.Comment; import com.erudika.scoold.core.Post; import com.erudika.scoold.core.Profile; import com.erudika.scoold.core.Profile.Badge; @@ -341,6 +342,32 @@ public String close(@PathVariable String id, HttpServletRequest req) { return "redirect:" + showPost.getPostLinkForRedirect(); } + @PostMapping("/{id}/make-comment/{answerid}") + public String makeComment(@PathVariable String id, @PathVariable String answerid, HttpServletRequest req) { + Post question = pc.read(id); + Post answer = pc.read(answerid); + Profile authUser = utils.getAuthUser(req); + if (question == null || answer == null) { + return "redirect:" + req.getRequestURI(); + } + if (utils.isMod(authUser) && answer.isReply()) { + Profile author = pc.read(answer.getCreatorid()); + Comment c = new Comment(); + c.setParentid(answer.getParentid()); + c.setComment(answer.getBody()); + c.setCreatorid(answer.getCreatorid()); + c.setAuthorName(Optional.ofNullable(author).orElse(authUser).getName()); + c = pc.create(c); + if (c != null) { + question.addCommentId(c.getId()); + pc.update(question); + answer.delete(); + return "redirect:" + question.getPostLinkForRedirect(); + } + } + return "redirect:" + QUESTIONSLINK + "/" + answer.getParentid(); + } + @PostMapping("/{id}/restore/{revisionid}") public String restore(@PathVariable String id, @PathVariable String revisionid, HttpServletRequest req) { Post showPost = pc.read(id); diff --git a/src/main/resources/lang_en.properties b/src/main/resources/lang_en.properties index 5e8f568b..24120a83 100644 --- a/src/main/resources/lang_en.properties +++ b/src/main/resources/lang_en.properties @@ -388,6 +388,7 @@ posts.matchall = Match all posts.matchany = Match any posts.creationdate = Creation date posts.creatorid = Creator ID +posts.makecomment = Convert to comment revisions.revision = Revision revisions.current = This is the current revision. diff --git a/src/main/resources/static/scripts/scoold.js b/src/main/resources/static/scripts/scoold.js index 01fce926..e4443861 100755 --- a/src/main/resources/static/scripts/scoold.js +++ b/src/main/resources/static/scripts/scoold.js @@ -349,11 +349,12 @@ $(function () { $(document).on("click", ".post-refresh-ask", function() { var elem = $(this); - return areYouSure(function() { + areYouSure(function() { $.post(elem.attr("href"), function(data) { - window.location = elem.attr("href"); + window.location.reload(true); }); }, rusuremsg, false); + return false; }); $(document).on("click", ".post-refresh", function() { diff --git a/src/main/resources/templates/macro.vm b/src/main/resources/templates/macro.vm index e10e6a58..00967c79 100755 --- a/src/main/resources/templates/macro.vm +++ b/src/main/resources/templates/macro.vm @@ -854,6 +854,12 @@ #end #end + #if ($scooldUtils.isMod($authUser) && $showpost.isReply()) + + $!lang.get('posts.makecomment') + + #end + #if (!$authenticated || ($authenticated && $showpost.creatorid != $authUser.id)) #getreportlink($showpost "$questionlink/$!showpost.id" "prm") #end