Skip to content

Commit

Permalink
Set only_path in reportables helper to make sure the right link is used
Browse files Browse the repository at this point in the history
  • Loading branch information
hellcp-work authored and saraycp committed Apr 29, 2024
1 parent fefaef9 commit 76023ae
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
22 changes: 12 additions & 10 deletions src/api/app/helpers/webui/reportables_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,38 @@
module Webui::ReportablesHelper
include Webui::WebuiHelper

def link_to_reportables(report_id:, reportable_type:, host:)
def link_to_reportables(report_id:, reportable_type:, host: nil)
reportable = Report.find(report_id).reportable
return "The reported #{reportable_type.downcase} does not exist anymore." if reportable.blank?

only_path = host.blank?

case reportable_type
when 'Comment'
link_to_commentables_on_reportables(commentable: reportable.commentable, host: host)
link_to_commentables_on_reportables(commentable: reportable.commentable, only_path: only_path, host: host)
when 'Package'
link_to("#{reportable.name}", Rails.application.routes.url_helpers.package_show_url(package: reportable, project: reportable.project,
anchor: 'comments-list', only_path: false, host: host))
anchor: 'comments-list', only_path: only_path, host: host))
when 'Project'
link_to("#{reportable.name}", Rails.application.routes.url_helpers.project_show_url(reportable, anchor: 'comments-list', only_path: false, host: host))
link_to("#{reportable.name}", Rails.application.routes.url_helpers.project_show_url(reportable, anchor: 'comments-list', only_path: only_path, host: host))
when 'User'
link_to("#{reportable.login}", Rails.application.routes.url_helpers.user_url(reportable, only_path: false, host: host))
link_to("#{reportable.login}", Rails.application.routes.url_helpers.user_url(reportable, only_path: only_path, host: host))
end
end

def link_to_commentables_on_reportables(commentable:, host:)
def link_to_commentables_on_reportables(commentable:, only_path:, host:)
case commentable
when BsRequest
link_to("Request #{commentable.number}", Rails.application.routes.url_helpers.request_show_url(commentable.number, anchor: 'comments-list', only_path: false, host: host))
link_to("Request #{commentable.number}", Rails.application.routes.url_helpers.request_show_url(commentable.number, anchor: 'comments-list', only_path: only_path, host: host))
when BsRequestAction
link_to("Request #{commentable.bs_request.number}", Rails.application.routes.url_helpers.request_show_url(number: commentable.bs_request.number,
request_action_id: commentable.id,
anchor: 'tab-pane-changes', only_path: false, host: host))
anchor: 'tab-pane-changes', only_path: only_path, host: host))
when Package
link_to("#{commentable.name}", Rails.application.routes.url_helpers.package_show_url(package: commentable, project: commentable.project,
anchor: 'comments-list', only_path: false, host: host))
anchor: 'comments-list', only_path: only_path, host: host))
when Project
link_to("#{commentable.name}", Rails.application.routes.url_helpers.project_show_url(commentable, anchor: 'comments-list', only_path: false, host: host))
link_to("#{commentable.name}", Rails.application.routes.url_helpers.project_show_url(commentable, anchor: 'comments-list', only_path: only_path, host: host))
end
end

Expand Down
2 changes: 1 addition & 1 deletion src/api/app/views/webui/reports/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Created by
= render UserAvatarComponent.new(@report.user.login)
on
= link_to_reportables(report_id: @report.id, reportable_type: @report.reportable_type, host: Configuration.obs_url)
= link_to_reportables(report_id: @report.id, reportable_type: @report.reportable_type)
%h5 Description
%p
= @report.reason
Expand Down

0 comments on commit 76023ae

Please sign in to comment.