debian-mirror-gitlab/lib/api/helpers/related_resources_helpers.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

44 lines
1.4 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
module API
module Helpers
module RelatedResourcesHelpers
2018-11-08 19:23:39 +05:30
include GrapePathHelpers::NamedRouteMatcher
2017-09-10 17:25:29 +05:30
def issues_available?(project, options)
available?(:issues, project, options[:current_user])
end
2022-08-27 11:52:29 +05:30
def project_feature_string_access_level(project, feature)
project.project_feature&.string_access_level(feature)
end
2017-09-10 17:25:29 +05:30
def mrs_available?(project, options)
available?(:merge_requests, project, options[:current_user])
end
2019-07-07 11:18:12 +05:30
def expose_path(path)
Gitlab::Utils.append_path(Gitlab.config.gitlab.relative_url_root, path)
end
2017-09-10 17:25:29 +05:30
def expose_url(path)
url_options = Gitlab::Application.routes.default_url_options
2018-11-08 19:23:39 +05:30
protocol, host, port, script_name = url_options.values_at(:protocol, :host, :port, :script_name)
2017-09-10 17:25:29 +05:30
2018-11-08 19:23:39 +05:30
# Using a blank component at the beginning of the join we ensure
# that the resulted path will start with '/'. If the resulted path
2021-06-08 01:23:25 +05:30
# does not start with '/', URI::Generic#new will fail
2018-11-08 19:23:39 +05:30
path_with_script_name = File.join('', [script_name, path].select(&:present?))
2021-06-08 01:23:25 +05:30
URI::Generic.new(protocol, nil, host, port, nil, path_with_script_name, nil, nil, nil, URI::RFC3986_PARSER, true).to_s
2017-09-10 17:25:29 +05:30
end
private
def available?(feature, project, current_user)
project.feature_available?(feature, current_user)
end
end
end
end