Skip to content

Commit

Permalink
Implement notification bars in remaining views
Browse files Browse the repository at this point in the history
  • Loading branch information
hellcp-work committed May 28, 2024
1 parent c654b55 commit 2213f0a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/api/app/components/notification_notifiable_link_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,15 @@ def notifiable_link_path
when 'Event::RelationshipCreate', 'Event::RelationshipDelete'
if @notification.event_payload['package']
Rails.application.routes.url_helpers.package_users_path(@notification.event_payload['project'],
@notification.event_payload['package'])
@notification.event_payload['package'],
notification_id: @notification.id)
else
Rails.application.routes.url_helpers.project_users_path(@notification.event_payload['project'])
Rails.application.routes.url_helpers.project_users_path(@notification.event_payload['project'], notification_id: @notification.id)

Check warning on line 111 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#L111

Added line #L111 was not covered by tests
end
when 'Event::BuildFail'
Rails.application.routes.url_helpers.package_live_build_log_path(package: @notification.event_payload['package'], project: @notification.event_payload['project'],
repository: @notification.event_payload['repository'], arch: @notification.event_payload['arch'])
repository: @notification.event_payload['repository'], arch: @notification.event_payload['arch'],
notification_id: @notification.id)
# TODO: Remove `Event::CreateReport` after all existing records are migrated to the new STI classes
when 'Event::CreateReport'
reportable = @notification.notifiable.reportable
Expand All @@ -130,9 +132,9 @@ def notifiable_link_path
reportable = @notification.notifiable.reports.first.reportable
link_for_reportables(reportable)
when 'Event::AppealCreated'
Rails.application.routes.url_helpers.appeal_path(@notification.notifiable)
Rails.application.routes.url_helpers.appeal_path(@notification.notifiable, notification_id: @notification.id)

Check warning on line 135 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#L135

Added line #L135 was not covered by tests
when 'Event::WorkflowRunFail'
Rails.application.routes.url_helpers.token_workflow_run_path(@notification.notifiable.token, @notification.notifiable)
Rails.application.routes.url_helpers.token_workflow_run_path(@notification.notifiable.token, @notification.notifiable, notification_id: @notification.id)

Check warning on line 137 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#L137

Added line #L137 was not covered by tests
end
end
# rubocop:enable Metrics/CyclomaticComplexity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class BuildLogController < Webui::WebuiController

before_action :check_ajax, only: :update_build_log
before_action :check_build_log_access
before_action :handle_notification, only: :live_build_log

def live_build_log
@repo = @project.repositories.find_by(name: params[:repository]).try(:name)
Expand Down Expand Up @@ -142,6 +143,13 @@ def set_job_status
@buildtime = nil
end
end

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

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

Check warning on line 151 in src/api/app/controllers/webui/packages/build_log_controller.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/controllers/webui/packages/build_log_controller.rb#L150-L151

Added lines #L150 - L151 were not covered by tests
end
end
end
end
9 changes: 9 additions & 0 deletions src/api/app/controllers/webui/workflow_runs_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class Webui::WorkflowRunsController < Webui::WebuiController
before_action :handle_notification, only: :show

def index
# TODO: The pull/merge request dropdown should accept multiple selections

Expand Down Expand Up @@ -35,4 +37,11 @@ def status_params
def event_type_params
@event_type_params ||= %w[pull_request push tag_push].select { |f| params[f] }
end

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

Check warning on line 42 in src/api/app/controllers/webui/workflow_runs_controller.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/controllers/webui/workflow_runs_controller.rb#L42

Added line #L42 was not covered by tests

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

Check warning on line 45 in src/api/app/controllers/webui/workflow_runs_controller.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/controllers/webui/workflow_runs_controller.rb#L44-L45

Added lines #L44 - L45 were not covered by tests
end
end

0 comments on commit 2213f0a

Please sign in to comment.