-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE: Implement Flags on Post Voting Comments, Comment edit and de…
…lete for moderators, only_allow_post_voting_in_this_category (#180) * FEATURE: Implement Flags on Post Voting Comments, Comment edit and delete for moderators, only_allow_post_voting_in_this_category * linter fix * linter fix * FEATURE: Implement Flags on Post Voting Comments * linting issues * added tests for only_post_voting_in_this_category * remove debugging * lint fix * fixed failing system test * fixed failing tests * added proper title with link to ReviewablePostVotingComments * fixed linter problem * implemented requested changes * implemented additional changes
- Loading branch information
1 parent
776b743
commit 44984bc
Showing
31 changed files
with
1,295 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
# frozen_string_literal: true | ||
|
||
class ReviewablePostVotingComment < Reviewable | ||
def serializer | ||
ReviewablePostVotingCommentSerializer | ||
end | ||
|
||
def self.action_aliases | ||
{ | ||
agree_and_keep_hidden: :agree_and_delete, | ||
agree_and_silence: :agree_and_delete, | ||
agree_and_suspend: :agree_and_delete, | ||
delete_and_agree: :agree_and_delete, | ||
} | ||
end | ||
|
||
def flagged_by_user_ids | ||
@flagged_by_user_ids ||= reviewable_scores.map(&:user_id) | ||
end | ||
|
||
def post | ||
nil | ||
end | ||
|
||
def comment | ||
@comment ||= (target || PostVotingComment.with_deleted.find_by(id: target_id)) | ||
end | ||
|
||
def comment_creator | ||
@comment_creator ||= User.find_by(id: comment.user_id) | ||
end | ||
|
||
def build_actions(actions, guardian, args) | ||
return unless pending? | ||
return if comment.blank? | ||
|
||
agree = | ||
actions.add_bundle("#{id}-agree", icon: "thumbs-up", label: "reviewables.actions.agree.title") | ||
|
||
if comment.deleted_at? | ||
build_action(actions, :agree_and_restore, icon: "far-eye", bundle: agree) | ||
build_action(actions, :agree_and_keep_deleted, icon: "thumbs-up", bundle: agree) | ||
build_action(actions, :disagree_and_restore, icon: "thumbs-down") | ||
else | ||
build_action(actions, :agree_and_delete, icon: "far-eye-slash", bundle: agree) | ||
build_action(actions, :agree_and_keep_comment, icon: "thumbs-up", bundle: agree) | ||
build_action(actions, :disagree, icon: "thumbs-down") | ||
end | ||
|
||
if guardian.can_suspend?(comment_creator) | ||
build_action( | ||
actions, | ||
:agree_and_suspend, | ||
icon: "ban", | ||
bundle: agree, | ||
client_action: "suspend", | ||
) | ||
build_action( | ||
actions, | ||
:agree_and_silence, | ||
icon: "microphone-slash", | ||
bundle: agree, | ||
client_action: "silence", | ||
) | ||
end | ||
|
||
ignore_bundle = actions.add_bundle("#{id}-ignore", label: "reviewables.actions.ignore.title") | ||
|
||
build_action(actions, :ignore, icon: "external-link-alt", bundle: ignore_bundle) | ||
|
||
unless comment.deleted_at? | ||
build_action(actions, :delete_and_agree, icon: "far-trash-alt", bundle: ignore_bundle) | ||
end | ||
end | ||
|
||
def perform_agree_and_keep_comment(performed_by, args) | ||
agree | ||
end | ||
|
||
def perform_agree_and_restore(performed_by, args) | ||
agree { comment.recover! } | ||
end | ||
|
||
def perform_agree_and_delete(performed_by, args) | ||
agree { comment.trash!(performed_by) } | ||
end | ||
|
||
def perform_disagree_and_restore(performed_by, args) | ||
disagree { comment.recover! } | ||
end | ||
|
||
def perform_disagree(performed_by, args) | ||
disagree | ||
end | ||
|
||
def perform_ignore(performed_by, args) | ||
ignore | ||
end | ||
|
||
def perform_delete_and_ignore(performed_by, args) | ||
ignore { comment.trash!(performed_by) } | ||
end | ||
|
||
private | ||
|
||
def agree | ||
yield if block_given? | ||
create_result(:success, :approved) do |result| | ||
result.update_flag_stats = { status: :agreed, user_ids: flagged_by_user_ids } | ||
result.recalculate_score = true | ||
end | ||
end | ||
|
||
def disagree | ||
yield if block_given? | ||
|
||
UserSilencer.unsilence(comment_creator) | ||
|
||
create_result(:success, :rejected) do |result| | ||
result.update_flag_stats = { status: :disagreed, user_ids: flagged_by_user_ids } | ||
result.recalculate_score = true | ||
end | ||
end | ||
|
||
def ignore | ||
yield if block_given? | ||
create_result(:success, :ignored) do |result| | ||
result.update_flag_stats = { status: :ignored, user_ids: flagged_by_user_ids } | ||
end | ||
end | ||
|
||
def build_action( | ||
actions, | ||
id, | ||
icon:, | ||
button_class: nil, | ||
bundle: nil, | ||
client_action: nil, | ||
confirm: false | ||
) | ||
actions.add(id, bundle: bundle) do |action| | ||
prefix = "reviewables.actions.#{id}" | ||
action.icon = icon | ||
action.button_class = button_class | ||
action.label = "post_voting.comment.#{prefix}.title" | ||
action.description = "post_voting.comment.#{prefix}.description" | ||
action.client_action = client_action | ||
action.confirm_message = "#{prefix}.confirm" if confirm | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
app/serializers/reviewable_post_voting_comments_serializer.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
require_dependency "reviewable_serializer" | ||
|
||
class ReviewablePostVotingCommentSerializer < ReviewableSerializer | ||
target_attributes :cooked, :raw, :comment_cooked, :post_id | ||
payload_attributes :comment_cooked, :transcript_topic_id, :cooked, :raw, :created_by | ||
attributes :target_id, :comment_cooked | ||
|
||
def created_from_flag? | ||
true | ||
end | ||
|
||
def target_id | ||
object.target&.id | ||
end | ||
|
||
def comment_cooked | ||
object.payload["comment_cooked"] | ||
end | ||
end |
39 changes: 25 additions & 14 deletions
39
assets/javascripts/discourse/components/post-voting-comment-actions.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,25 @@ | ||
<span class="post-voting-comment-actions"> | ||
<DButton | ||
@display="link" | ||
@class="post-voting-comment-actions-edit-link" | ||
@action={{@updateComment}} | ||
@icon="pencil-alt" | ||
/> | ||
<DButton | ||
@display="link" | ||
@class="post-voting-comment-actions-delete-link" | ||
@action={{this.deleteConfirm}} | ||
@icon="far-trash-alt" | ||
/> | ||
</span> | ||
{{#if this.canEdit}} | ||
<span class="post-voting-comment-actions"> | ||
<DButton | ||
@display="link" | ||
class="post-voting-comment-actions-edit-link" | ||
@action={{@updateComment}} | ||
@icon="pencil-alt" | ||
/> | ||
<DButton | ||
@display="link" | ||
class="post-voting-comment-actions-delete-link" | ||
@action={{this.deleteConfirm}} | ||
@icon="far-trash-alt" | ||
/> | ||
|
||
{{#if this.canFlag}} | ||
<DButton | ||
@display="link" | ||
class="post-voting-comment-actions-flag-link" | ||
@action={{this.showFlag}} | ||
@icon="flag" | ||
/> | ||
{{/if}} | ||
</span> | ||
{{/if}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.