2018-09-29 18:34:47 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-07-25 05:35:45 -04:00
|
|
|
module API
|
|
|
|
module Helpers
|
|
|
|
module RelatedResourcesHelpers
|
2018-05-30 05:57:46 -04:00
|
|
|
include GrapePathHelpers::NamedRouteMatcher
|
2017-07-25 05:35:45 -04:00
|
|
|
|
|
|
|
def issues_available?(project, options)
|
|
|
|
available?(:issues, project, options[:current_user])
|
|
|
|
end
|
|
|
|
|
|
|
|
def mrs_available?(project, options)
|
|
|
|
available?(:merge_requests, project, options[:current_user])
|
|
|
|
end
|
|
|
|
|
2019-05-07 03:28:35 -04:00
|
|
|
def expose_path(path)
|
|
|
|
Gitlab::Utils.append_path(Gitlab.config.gitlab.relative_url_root, path)
|
|
|
|
end
|
|
|
|
|
2017-07-25 05:35:45 -04:00
|
|
|
def expose_url(path)
|
2017-07-27 05:15:57 -04:00
|
|
|
url_options = Gitlab::Application.routes.default_url_options
|
2018-05-22 04:54:20 -04:00
|
|
|
protocol, host, port, script_name = url_options.values_at(:protocol, :host, :port, :script_name)
|
2017-07-25 05:35:45 -04:00
|
|
|
|
2018-05-22 04:54:20 -04:00
|
|
|
# Using a blank component at the beginning of the join we ensure
|
|
|
|
# that the resulted path will start with '/'. If the resulted path
|
2021-04-26 17:10:25 -04:00
|
|
|
# does not start with '/', URI::Generic#new will fail
|
2018-05-22 04:54:20 -04:00
|
|
|
path_with_script_name = File.join('', [script_name, path].select(&:present?))
|
|
|
|
|
2021-04-26 17:10:25 -04:00
|
|
|
URI::Generic.new(protocol, nil, host, port, nil, path_with_script_name, nil, nil, nil, URI::RFC3986_PARSER, true).to_s
|
2017-07-25 05:35:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def available?(feature, project, current_user)
|
|
|
|
project.feature_available?(feature, current_user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|