2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
# Shorter routing method for some project items
|
2015-04-26 12:48:37 +05:30
|
|
|
module GitlabRoutingHelper
|
2017-09-10 17:25:29 +05:30
|
|
|
extend ActiveSupport::Concern
|
2016-06-16 23:09:34 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
include ::ProjectsHelper
|
|
|
|
include ::ApplicationSettingsHelper
|
2020-04-22 19:07:51 +05:30
|
|
|
include API::Helpers::RelatedResourcesHelpers
|
2017-09-10 17:25:29 +05:30
|
|
|
included do
|
|
|
|
Gitlab::Routing.includes_helpers(self)
|
2015-09-25 12:07:36 +05:30
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
# Project
|
|
|
|
def project_tree_path(project, ref = nil, *args)
|
|
|
|
namespace_project_tree_path(project.namespace, project, ref || @ref || project.repository.root_ref, *args) # rubocop:disable Cop/ProjectPathHelper
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
def project_commits_path(project, ref = nil, *args)
|
|
|
|
namespace_project_commits_path(project.namespace, project, ref || @ref || project.repository.root_ref, *args) # rubocop:disable Cop/ProjectPathHelper
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
def project_ref_path(project, ref_name, *args)
|
|
|
|
project_commits_path(project, ref_name, *args)
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
def environment_path(environment, *args)
|
2017-09-10 17:25:29 +05:30
|
|
|
project_environment_path(environment.project, environment, *args)
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def environment_metrics_path(environment, *args)
|
2017-09-10 17:25:29 +05:30
|
|
|
metrics_project_environment_path(environment.project, environment, *args)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
def environment_delete_path(environment, *args)
|
|
|
|
expose_path(api_v4_projects_environments_path(id: environment.project.id, environment_id: environment.id))
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def issue_path(entity, *args)
|
2017-09-10 17:25:29 +05:30
|
|
|
project_issue_path(entity.project, entity, *args)
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def merge_request_path(entity, *args)
|
2017-09-10 17:25:29 +05:30
|
|
|
project_merge_request_path(entity.project, entity, *args)
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def pipeline_path(pipeline, *args)
|
2017-09-10 17:25:29 +05:30
|
|
|
project_pipeline_path(pipeline.project, pipeline.id, *args)
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def issue_url(entity, *args)
|
2017-09-10 17:25:29 +05:30
|
|
|
project_issue_url(entity.project, entity, *args)
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def merge_request_url(entity, *args)
|
2017-09-10 17:25:29 +05:30
|
|
|
project_merge_request_url(entity.project, entity, *args)
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
def pipeline_url(pipeline, *args)
|
2017-09-10 17:25:29 +05:30
|
|
|
project_pipeline_url(pipeline.project, pipeline.id, *args)
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
def pipeline_job_url(pipeline, build, *args)
|
|
|
|
project_job_url(pipeline.project, build.id, *args)
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def commits_url(entity, *args)
|
2019-12-21 20:55:43 +05:30
|
|
|
project_commits_url(entity.project, entity.source_ref, *args)
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def commit_url(entity, *args)
|
2017-09-10 17:25:29 +05:30
|
|
|
project_commit_url(entity.project, entity.sha, *args)
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
2015-09-11 14:41:01 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
def release_url(entity, *args)
|
|
|
|
project_release_url(entity.project, entity, *args)
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def preview_markdown_path(parent, *args)
|
2019-12-26 22:10:19 +05:30
|
|
|
return group_preview_markdown_path(parent, *args) if parent.is_a?(Group)
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
if @snippet.is_a?(PersonalSnippet)
|
2017-09-10 17:25:29 +05:30
|
|
|
preview_markdown_snippets_path
|
2017-08-17 22:00:37 +05:30
|
|
|
else
|
2018-03-17 18:26:18 +05:30
|
|
|
preview_markdown_project_path(parent, *args)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
def edit_milestone_path(entity, *args)
|
2019-12-21 20:55:43 +05:30
|
|
|
if entity.resource_parent.is_a?(Group)
|
|
|
|
edit_group_milestone_path(entity.resource_parent, entity, *args)
|
2018-10-15 14:42:47 +05:30
|
|
|
else
|
2019-12-21 20:55:43 +05:30
|
|
|
edit_project_milestone_path(entity.resource_parent, entity, *args)
|
2018-10-15 14:42:47 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
def toggle_subscription_path(entity, *args)
|
|
|
|
if entity.is_a?(Issue)
|
2017-09-10 17:25:29 +05:30
|
|
|
toggle_subscription_project_issue_path(entity.project, entity)
|
2015-09-11 14:41:01 +05:30
|
|
|
else
|
2017-09-10 17:25:29 +05:30
|
|
|
toggle_subscription_project_merge_request_path(entity.project, entity)
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
|
|
|
end
|
2016-06-16 23:09:34 +05:30
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
def toggle_award_emoji_personal_snippet_path(*args)
|
|
|
|
toggle_award_emoji_snippet_path(*args)
|
|
|
|
end
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
def toggle_award_emoji_project_project_snippet_path(*args)
|
|
|
|
toggle_award_emoji_project_snippet_path(*args)
|
|
|
|
end
|
|
|
|
|
|
|
|
def toggle_award_emoji_project_project_snippet_url(*args)
|
|
|
|
toggle_award_emoji_project_snippet_url(*args)
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
## Members
|
|
|
|
def project_members_url(project, *args)
|
2017-09-10 17:25:29 +05:30
|
|
|
project_project_members_url(project, *args)
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def project_member_path(project_member, *args)
|
2017-09-10 17:25:29 +05:30
|
|
|
project_project_member_path(project_member.source, project_member)
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def request_access_project_members_path(project, *args)
|
2017-09-10 17:25:29 +05:30
|
|
|
request_access_project_project_members_path(project)
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def leave_project_members_path(project, *args)
|
2017-09-10 17:25:29 +05:30
|
|
|
leave_project_project_members_path(project)
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def approve_access_request_project_member_path(project_member, *args)
|
2017-09-10 17:25:29 +05:30
|
|
|
approve_access_request_project_project_member_path(project_member.source, project_member)
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def resend_invite_project_member_path(project_member, *args)
|
2017-09-10 17:25:29 +05:30
|
|
|
resend_invite_project_project_member_path(project_member.source, project_member)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
# Groups
|
|
|
|
|
|
|
|
## Members
|
|
|
|
def group_members_url(group, *args)
|
|
|
|
group_group_members_url(group, *args)
|
|
|
|
end
|
|
|
|
|
|
|
|
def group_member_path(group_member, *args)
|
|
|
|
group_group_member_path(group_member.source, group_member)
|
|
|
|
end
|
|
|
|
|
|
|
|
def request_access_group_members_path(group, *args)
|
|
|
|
request_access_group_group_members_path(group)
|
|
|
|
end
|
|
|
|
|
|
|
|
def leave_group_members_path(group, *args)
|
|
|
|
leave_group_group_members_path(group)
|
|
|
|
end
|
|
|
|
|
|
|
|
def approve_access_request_group_member_path(group_member, *args)
|
|
|
|
approve_access_request_group_group_member_path(group_member.source, group_member)
|
|
|
|
end
|
|
|
|
|
|
|
|
def resend_invite_group_member_path(group_member, *args)
|
|
|
|
resend_invite_group_group_member_path(group_member.source, group_member)
|
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
# Members
|
|
|
|
def source_members_url(member)
|
|
|
|
case member.source_type
|
|
|
|
when 'Namespace'
|
|
|
|
group_group_members_url(member.source)
|
|
|
|
when 'Project'
|
|
|
|
project_project_members_url(member.source)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
# Artifacts
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
# Rails path generators are slow because they need to do large regex comparisons
|
|
|
|
# against the arguments. We can speed this up 10x by generating the strings directly.
|
|
|
|
|
|
|
|
# /*namespace_id/:project_id/-/jobs/:job_id/artifacts/download(.:format)
|
2020-06-23 00:09:42 +05:30
|
|
|
def fast_download_project_job_artifacts_path(project, job, params = {})
|
|
|
|
expose_fast_artifacts_path(project, job, :download, params)
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
# /*namespace_id/:project_id/-/jobs/:job_id/artifacts/keep(.:format)
|
|
|
|
def fast_keep_project_job_artifacts_path(project, job)
|
|
|
|
expose_fast_artifacts_path(project, job, :keep)
|
|
|
|
end
|
|
|
|
|
|
|
|
# /*namespace_id/:project_id/-/jobs/:job_id/artifacts/browse(/*path)
|
|
|
|
def fast_browse_project_job_artifacts_path(project, job)
|
|
|
|
expose_fast_artifacts_path(project, job, :browse)
|
|
|
|
end
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
def expose_fast_artifacts_path(project, job, action, params = {})
|
2020-03-13 15:44:24 +05:30
|
|
|
path = "#{project.full_path}/-/jobs/#{job.id}/artifacts/#{action}"
|
2020-06-23 00:09:42 +05:30
|
|
|
|
|
|
|
unless params.empty?
|
|
|
|
path += "?#{params.to_query}"
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
Gitlab::Utils.append_path(Gitlab.config.gitlab.relative_url_root, path)
|
|
|
|
end
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
def artifacts_action_path(path, project, build)
|
|
|
|
action, path_params = path.split('/', 2)
|
2017-09-10 17:25:29 +05:30
|
|
|
args = [project, build, path_params]
|
2016-09-29 09:46:39 +05:30
|
|
|
|
|
|
|
case action
|
|
|
|
when 'download'
|
2017-09-10 17:25:29 +05:30
|
|
|
download_project_job_artifacts_path(*args)
|
2016-09-29 09:46:39 +05:30
|
|
|
when 'browse'
|
2017-09-10 17:25:29 +05:30
|
|
|
browse_project_job_artifacts_path(*args)
|
2016-09-29 09:46:39 +05:30
|
|
|
when 'file'
|
2017-09-10 17:25:29 +05:30
|
|
|
file_project_job_artifacts_path(*args)
|
2017-08-17 22:00:37 +05:30
|
|
|
when 'raw'
|
2017-09-10 17:25:29 +05:30
|
|
|
raw_project_job_artifacts_path(*args)
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
# Pipeline Schedules
|
|
|
|
def pipeline_schedules_path(project, *args)
|
2017-09-10 17:25:29 +05:30
|
|
|
project_pipeline_schedules_path(project, *args)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def pipeline_schedule_path(schedule, *args)
|
|
|
|
project = schedule.project
|
2017-09-10 17:25:29 +05:30
|
|
|
project_pipeline_schedule_path(project, schedule, *args)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def edit_pipeline_schedule_path(schedule)
|
|
|
|
project = schedule.project
|
2017-09-10 17:25:29 +05:30
|
|
|
edit_project_pipeline_schedule_path(project, schedule)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def play_pipeline_schedule_path(schedule, *args)
|
|
|
|
project = schedule.project
|
|
|
|
play_project_pipeline_schedule_path(project, schedule, *args)
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def take_ownership_pipeline_schedule_path(schedule, *args)
|
|
|
|
project = schedule.project
|
2017-09-10 17:25:29 +05:30
|
|
|
take_ownership_project_pipeline_schedule_path(project, schedule, *args)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
def gitlab_snippet_path(snippet, *args)
|
|
|
|
if snippet.is_a?(ProjectSnippet)
|
|
|
|
project_snippet_path(snippet.project, snippet, *args)
|
|
|
|
else
|
|
|
|
new_args = snippet_query_params(snippet, *args)
|
|
|
|
snippet_path(snippet, *new_args)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def gitlab_snippet_url(snippet, *args)
|
|
|
|
if snippet.is_a?(ProjectSnippet)
|
|
|
|
project_snippet_url(snippet.project, snippet, *args)
|
|
|
|
else
|
|
|
|
new_args = snippet_query_params(snippet, *args)
|
|
|
|
snippet_url(snippet, *new_args)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
def gitlab_dashboard_snippets_path(snippet, *args)
|
|
|
|
if snippet.is_a?(ProjectSnippet)
|
|
|
|
project_snippets_path(snippet.project, *args)
|
|
|
|
else
|
|
|
|
dashboard_snippets_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
def gitlab_raw_snippet_path(snippet, *args)
|
|
|
|
if snippet.is_a?(ProjectSnippet)
|
|
|
|
raw_project_snippet_path(snippet.project, snippet, *args)
|
|
|
|
else
|
|
|
|
new_args = snippet_query_params(snippet, *args)
|
|
|
|
raw_snippet_path(snippet, *new_args)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def gitlab_raw_snippet_url(snippet, *args)
|
|
|
|
if snippet.is_a?(ProjectSnippet)
|
|
|
|
raw_project_snippet_url(snippet.project, snippet, *args)
|
|
|
|
else
|
|
|
|
new_args = snippet_query_params(snippet, *args)
|
|
|
|
raw_snippet_url(snippet, *new_args)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
def gitlab_raw_snippet_blob_url(snippet, path, ref = nil, **options)
|
2020-07-28 23:09:34 +05:30
|
|
|
params = {
|
|
|
|
snippet_id: snippet,
|
|
|
|
ref: ref || snippet.repository.root_ref,
|
|
|
|
path: path
|
|
|
|
}
|
|
|
|
|
|
|
|
if snippet.is_a?(ProjectSnippet)
|
2020-10-24 23:57:45 +05:30
|
|
|
project_snippet_blob_raw_url(snippet.project, **params, **options)
|
2020-07-28 23:09:34 +05:30
|
|
|
else
|
2020-10-24 23:57:45 +05:30
|
|
|
snippet_blob_raw_url(**params, **options)
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
def gitlab_raw_snippet_blob_path(snippet, path, ref = nil, **options)
|
|
|
|
gitlab_raw_snippet_blob_url(snippet, path, ref, only_path: true, **options)
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
def gitlab_snippet_notes_path(snippet, *args)
|
|
|
|
new_args = snippet_query_params(snippet, *args)
|
|
|
|
snippet_notes_path(snippet, *new_args)
|
|
|
|
end
|
|
|
|
|
|
|
|
def gitlab_snippet_notes_url(snippet, *args)
|
|
|
|
new_args = snippet_query_params(snippet, *args)
|
|
|
|
snippet_notes_url(snippet, *new_args)
|
|
|
|
end
|
|
|
|
|
|
|
|
def gitlab_snippet_note_path(snippet, note, *args)
|
|
|
|
new_args = snippet_query_params(snippet, *args)
|
|
|
|
snippet_note_path(snippet, note, *new_args)
|
|
|
|
end
|
|
|
|
|
|
|
|
def gitlab_snippet_note_url(snippet, note, *args)
|
|
|
|
new_args = snippet_query_params(snippet, *args)
|
|
|
|
snippet_note_url(snippet, note, *new_args)
|
|
|
|
end
|
|
|
|
|
|
|
|
def gitlab_toggle_award_emoji_snippet_note_path(snippet, note, *args)
|
|
|
|
new_args = snippet_query_params(snippet, *args)
|
|
|
|
toggle_award_emoji_snippet_note_path(snippet, note, *new_args)
|
|
|
|
end
|
|
|
|
|
|
|
|
def gitlab_toggle_award_emoji_snippet_note_url(snippet, note, *args)
|
|
|
|
new_args = snippet_query_params(snippet, *args)
|
|
|
|
toggle_award_emoji_snippet_note_url(snippet, note, *new_args)
|
|
|
|
end
|
|
|
|
|
|
|
|
def gitlab_toggle_award_emoji_snippet_path(snippet, *args)
|
|
|
|
new_args = snippet_query_params(snippet, *args)
|
|
|
|
toggle_award_emoji_snippet_path(snippet, *new_args)
|
|
|
|
end
|
|
|
|
|
|
|
|
def gitlab_toggle_award_emoji_snippet_url(snippet, *args)
|
|
|
|
new_args = snippet_query_params(snippet, *args)
|
|
|
|
toggle_award_emoji_snippet_url(snippet, *new_args)
|
|
|
|
end
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
# Wikis
|
|
|
|
|
|
|
|
def wiki_path(wiki, **options)
|
|
|
|
Gitlab::UrlBuilder.wiki_url(wiki, only_path: true, **options)
|
|
|
|
end
|
|
|
|
|
|
|
|
def wiki_page_path(wiki, page, **options)
|
|
|
|
Gitlab::UrlBuilder.wiki_page_url(wiki, page, only_path: true, **options)
|
|
|
|
end
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
# GraphQL ETag routes
|
|
|
|
def graphql_etag_pipeline_path(pipeline)
|
|
|
|
[api_graphql_path, "pipelines/id/#{pipeline.id}"].join(':')
|
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
def graphql_etag_pipeline_sha_path(sha)
|
|
|
|
[api_graphql_path, "pipelines/sha/#{sha}"].join(':')
|
|
|
|
end
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def snippet_query_params(snippet, *args)
|
|
|
|
opts = case args.last
|
|
|
|
when Hash
|
|
|
|
args.pop
|
|
|
|
when ActionController::Parameters
|
|
|
|
args.pop.to_h
|
|
|
|
else
|
|
|
|
{}
|
|
|
|
end
|
|
|
|
|
|
|
|
args << opts
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
GitlabRoutingHelper.include_mod_with('GitlabRoutingHelper')
|