Skip to content

Commit

Permalink
Handle notification from the report show page
Browse files Browse the repository at this point in the history
Passing the notification id in the query string we can go back to the
notifications page or mark it as read.
  • Loading branch information
saraycp committed Apr 26, 2024
1 parent 2b7a352 commit 526b38f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def notifiable_link_path
reportable = @notification.notifiable.reportable
link_for_reportables(reportable)
when 'Event::ReportForComment', 'Event::ReportForProject', 'Event::ReportForPackage', 'Event::ReportForUser', 'Event::ReportForRequest'
Rails.application.routes.url_helpers.report_path(@notification.notifiable)
Rails.application.routes.url_helpers.report_path(@notification.notifiable, notification_id: @notification.id)

Check warning on line 119 in src/api/app/components/notification_notifiable_link_component.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/components/notification_notifiable_link_component.rb#L119

Added line #L119 was not covered by tests
when 'Event::ClearedDecision', 'Event::FavoredDecision'
reportable = @notification.notifiable.reports.first.reportable
link_for_reportables(reportable)
Expand Down
9 changes: 9 additions & 0 deletions src/api/app/controllers/webui/reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class Webui::ReportsController < Webui::WebuiController

def show
authorize @report

handle_notification

Check warning on line 11 in src/api/app/controllers/webui/reports_controller.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/controllers/webui/reports_controller.rb#L11

Added line #L11 was not covered by tests
end

def create
Expand Down Expand Up @@ -43,4 +45,11 @@ def report_params
def set_report
@report = Report.find(params[:id])
end

def handle_notification
return unless User.session && params[:notification_id]

Check warning on line 50 in src/api/app/controllers/webui/reports_controller.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/controllers/webui/reports_controller.rb#L50

Added line #L50 was not covered by tests

@current_notification = Notification.find(params[:notification_id])
authorize @current_notification, :update?, policy_class: NotificationPolicy

Check warning on line 53 in src/api/app/controllers/webui/reports_controller.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/controllers/webui/reports_controller.rb#L52-L53

Added lines #L52 - L53 were not covered by tests
end
end

0 comments on commit 526b38f

Please sign in to comment.