-
Notifications
You must be signed in to change notification settings - Fork 437
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14934 from hellcp-work/report-notices
Show information about existing reports on the associated objects
- Loading branch information
Showing
9 changed files
with
64 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.text-warning | ||
%i.fas.fa-flag | ||
- if by_user? | ||
You reported this #{reportable_name}. | ||
- else | ||
This #{reportable_name} has #{report_amount}. |
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,25 @@ | ||
class ReportsNoticeComponent < ApplicationComponent | ||
attr_reader :reportable, :reportable_name, :user, :reports | ||
|
||
def initialize(reportable:, user:) | ||
super | ||
|
||
@reportable = reportable | ||
@reportable_name = reportable.class.name.downcase | ||
@user = user | ||
@reports = reportable&.reports | ||
end | ||
|
||
def by_user? | ||
Report.exists?(user:, reportable:) | ||
end | ||
|
||
def report_amount | ||
pluralize(reports.count, 'report') | ||
end | ||
|
||
def render? | ||
Flipper.enabled?(:content_moderation, user) && | ||
reports&.any? { |r| Pundit.policy(user, r).show? } | ||
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
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,4 @@ | ||
- reports_component = ReportsNoticeComponent.new(reportable: package, user: User.session) | ||
- if reports_component.render? | ||
%li | ||
= render reports_component |
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
20 changes: 20 additions & 0 deletions
20
src/api/spec/components/previews/reports_notice_component_preview.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,20 @@ | ||
class ReportsNoticeComponentPreview < ViewComponent::Preview | ||
# Preview at http://HOST:PORT/rails/view_components/reports_notice_component/user_reportable_as_admin | ||
def user_reportable_as_admin | ||
reportable = User.last | ||
User.take(3).each do |user| | ||
Report.new(reportable:, user:).save! | ||
end | ||
render(ReportsNoticeComponent.new(reportable:, user: User.admins.first)) | ||
end | ||
|
||
# Preview at http://HOST:PORT/rails/view_components/reports_notice_component/user_reportable_as_reporter | ||
def user_reportable_as_reporter | ||
reportable = User.last | ||
reporters = User.take(3) | ||
reporters.each do |user| | ||
Report.new(reportable:, user:).save! | ||
end | ||
render(ReportsNoticeComponent.new(reportable:, user: reporters.last)) | ||
end | ||
end |