debian-mirror-gitlab/app/helpers/gitlab_routing_helper.rb

313 lines
9.1 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
# 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
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
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
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-09-29 09:46:39 +05:30
def toggle_award_emoji_personal_snippet_path(*args)
toggle_award_emoji_snippet_path(*args)
end
def toggle_award_emoji_namespace_project_project_snippet_path(*args)
toggle_award_emoji_namespace_project_snippet_path(*args)
end
## Members
def project_members_url(project, *args)
2017-09-10 17:25:29 +05:30
project_project_members_url(project, *args)
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)
end
def request_access_project_members_path(project, *args)
2017-09-10 17:25:29 +05:30
request_access_project_project_members_path(project)
end
def leave_project_members_path(project, *args)
2017-09-10 17:25:29 +05:30
leave_project_project_members_path(project)
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)
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
# 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
# Artifacts
2020-03-09 13:42:32 +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)
def fast_download_project_job_artifacts_path(project, job)
expose_fast_artifacts_path(project, job, :download)
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
def expose_fast_artifacts_path(project, job, action)
path = "#{project.full_path}/-/jobs/#{job.id}/artifacts/#{action}"
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
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
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
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
GitlabRoutingHelper.include_if_ee('EE::GitlabRoutingHelper')