Skip to content

Commit

Permalink
Add comments to reports
Browse files Browse the repository at this point in the history
Moderators could need to keep a conversion between each other to take
the right decision. They can now use comments on the report page for
that.
  • Loading branch information
saraycp committed Apr 25, 2024
1 parent c9f4574 commit f607c2f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/api/app/controllers/webui/comments_controller.rb
Expand Up @@ -158,7 +158,7 @@ def set_comment
end

def set_commented
@commentable_type = [Project, Package, BsRequest, BsRequestActionSubmit].find { |klass| klass.name == params[:commentable_type] }
@commentable_type = [Project, Package, BsRequest, BsRequestActionSubmit, Report].find { |klass| klass.name == params[:commentable_type] }
@commented = @commentable_type&.find_by(id: params[:commentable_id])
return if @commentable_type.present?

Expand Down
1 change: 1 addition & 0 deletions src/api/app/models/report.rb
Expand Up @@ -6,6 +6,7 @@ class Report < ApplicationRecord

belongs_to :user, optional: false
belongs_to :reportable, polymorphic: true, optional: true
has_many :comments, as: :commentable, dependent: :destroy

belongs_to :decision, optional: true

Expand Down
2 changes: 2 additions & 0 deletions src/api/app/policies/comment_lock_policy.rb
Expand Up @@ -2,6 +2,8 @@ class CommentLockPolicy < ApplicationPolicy
def create?
return false unless Flipper.enabled?(:content_moderation, user)

return false if record.is_a?(Report)

return true if user.is_moderator? || user.is_admin?

case record
Expand Down
2 changes: 2 additions & 0 deletions src/api/app/policies/comment_policy.rb
Expand Up @@ -63,6 +63,8 @@ def locked?
record.commentable.project.comment_lock.present? || record.commentable.comment_lock.present?
when BsRequestAction
record.commentable.bs_request.comment_lock.present? || record.commentable.comment_lock.present?
when Report
false
else
record.commentable.comment_lock.present?
end
Expand Down
9 changes: 9 additions & 0 deletions src/api/app/views/webui/reports/show.html.haml
Expand Up @@ -13,3 +13,12 @@
%h5 Description
%p
= @report.reason

.comments.mt-3
.card#comments-list
%h5.card-header.text-word-break-all
Comments
%span.badge.text-bg-primary{ id: "comment-counter-report-#{@report.id}" }
= @report.comments.length
.card-body#comments
= render partial: 'webui/comment/show', locals: { commentable: @report, comment_counter_id: "#comment-counter-report-#{@report.id}" }

0 comments on commit f607c2f

Please sign in to comment.