Skip to content

Commit

Permalink
Merge pull request #16168 from hennevogel/refactoring/report-events
Browse files Browse the repository at this point in the history
Unify how we refer to involved people in report events
  • Loading branch information
hennevogel committed May 23, 2024
2 parents d5b1f4a + a5debb8 commit 54e0bb1
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/api/app/components/notification_avatars_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def avatar_objects
when 'Project', 'Package'
[User.find_by(login: @notification.event_payload['who'])]
when 'Report'
[User.find(@notification.event_payload['user_id'])]
[User.find_by(login: @notification.event_payload['reporter'])]
when 'Decision'
[User.find(@notification.event_payload['moderator_id'])]
when 'Appeal'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def notifiable_link_path
when 'Event::ReportForProject', 'Event::ReportForPackage'
@notification.event_type.constantize.notification_link_path(@notification)
when 'Event::ReportForUser'
Rails.application.routes.url_helpers.user_path(@notification.event_payload['user_login'], notification_id: @notification.id) if !@notification.event_user.is_deleted? || @current_user.is_admin?
Rails.application.routes.url_helpers.user_path(@notification.accused, notification_id: @notification.id) if !@notification.accused.is_deleted? || @current_user.is_admin?
when 'Event::ReportForRequest'
bs_request = @notification.notifiable.reportable
Rails.application.routes.url_helpers.request_show_path(bs_request.number, notification_id: @notification.id)
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/models/event/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Report < Base
receiver_roles :moderator
self.description = 'Report for inappropriate content created'

payload_keys :id, :user_id, :reportable_id, :reportable_type, :reason, :category
payload_keys :id, :reporter, :reportable_id, :reportable_type, :reason, :category

def subject
raise AbstractMethodCalled
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/models/event/report_for_user.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module Event
class ReportForUser < Report
self.description = 'Report for a user created'
payload_keys :user_login
payload_keys :accused

def subject
"User #{payload['user_login']} reported"
"User #{payload['accused']} reported"
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/models/notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ def unread_date
last_seen_at || created_at
end

def event_user
User.find_by_login(event_payload['user_login']) if event_payload['user_login']
def accused
User.find_by(login: event_payload['accused']) if event_payload['accused']
end

private
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/models/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ def create_event
when 'Project'
Event::ReportForProject.create(event_parameters.merge(project_name: reportable.name))
when 'User'
Event::ReportForUser.create(event_parameters.merge(user_login: reportable.login))
Event::ReportForUser.create(event_parameters.merge(accused: reportable.login))
when 'BsRequest'
Event::ReportForRequest.create(event_parameters.merge(bs_request_number: reportable.number))
end
end

def event_parameters
{ id: id, user_id: user_id, reportable_id: reportable_id, reportable_type: reportable_type, reason: reason, category: category }
{ id: id, reporter: user.login, reportable_id: reportable_id, reportable_type: reportable_type, reason: reason, category: category }
end

def event_parameters_for_comment(commentable:)
Expand Down
3 changes: 1 addition & 2 deletions src/api/app/views/event_mailer/report_for_comment.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
%p
= User.find(event['user_id']).login
reported a #{event['reportable_type'].downcase} as #{event['category'].humanize} for the following reason:
#{event['reporter']} reported a #{event['reportable_type'].downcase} as #{event['category'].humanize} for the following reason:
%p
= event['reason']
%p
Expand Down
3 changes: 1 addition & 2 deletions src/api/app/views/event_mailer/report_for_package.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
%p
= User.find(event['user_id']).login
reported a #{event['reportable_type'].downcase} as #{event['category'].humanize} for the following reason:
"#{event['reporter']}" reported a #{event['reportable_type'].downcase} as #{event['category'].humanize} for the following reason:
%p
= event['reason']
%p
Expand Down
3 changes: 1 addition & 2 deletions src/api/app/views/event_mailer/report_for_project.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
%p
= User.find(event['user_id']).login
reported a #{event['reportable_type'].downcase} as #{event['category'].humanize} for the following reason:
#{event['reporter']} reported a #{event['reportable_type'].downcase} as #{event['category'].humanize} for the following reason:
%p
= event['reason']
%p
Expand Down
5 changes: 2 additions & 3 deletions src/api/app/views/event_mailer/report_for_user.html.haml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
%p
= User.find(event['user_id']).login
reported a #{event['reportable_type'].downcase} as #{event['category'].humanize} for the following reason:
#{event['reporter']} reported a #{event['reportable_type'].downcase} as #{event['category'].humanize} for the following reason:
%p
= event['reason']
%p
= link_to("#{event['user_login']}", user_url(event['user_login'], only_path: false, host: @host))
= link_to("#{event['accused']}", user_url(event['accused'], only_path: false, host: @host))

0 comments on commit 54e0bb1

Please sign in to comment.