Skip to content

Commit

Permalink
added new moderation button to quickly convert an answer to a comment
Browse files Browse the repository at this point in the history
  • Loading branch information
albogdano committed Oct 16, 2023
1 parent 873da8d commit 997e86c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions src/main/resources/static/scripts/scoold.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/templates/macro.vm
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,12 @@
#end
#end

#if ($scooldUtils.isMod($authUser) && $showpost.isReply())
<a href="$!actionlink/$showpost.parentid/make-comment/$showpost.id" title="Convert to comment" class="post-refresh-ask prm">
<i class="fa fa-level-up"></i> $!lang.get('posts.makecomment')
</a>
#end

#if (!$authenticated || ($authenticated && $showpost.creatorid != $authUser.id))
#getreportlink($showpost "$questionlink/$!showpost.id" "prm")
#end
Expand Down

0 comments on commit 997e86c

Please sign in to comment.