gitlab_routing_helper.rb 5.48 KB
Newer Older
1 2
# frozen_string_literal: true

3
# Shorter routing method for some project items
4
module GitlabRoutingHelper
5
  extend ActiveSupport::Concern
Kamil Trzcinski's avatar
Kamil Trzcinski committed
6

7 8 9 10
  included do
    Gitlab::Routing.includes_helpers(self)
  end

11 12 13
  # 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
14 15
  end

16 17
  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
Kamil Trzcinski's avatar
Kamil Trzcinski committed
18 19
  end

20
  def project_ref_path(project, ref_name, *args)
21
    project_commits_path(project, ref_name, *args)
22 23
  end

24
  def environment_path(environment, *args)
25
    project_environment_path(environment.project, environment, *args)
26 27
  end

28
  def environment_metrics_path(environment, *args)
29
    metrics_project_environment_path(environment.project, environment, *args)
30 31
  end

32
  def issue_path(entity, *args)
33
    project_issue_path(entity.project, entity, *args)
34 35 36
  end

  def merge_request_path(entity, *args)
37
    project_merge_request_path(entity.project, entity, *args)
38
  end
39

40
  def pipeline_path(pipeline, *args)
41
    project_pipeline_path(pipeline.project, pipeline.id, *args)
42 43
  end

44
  def issue_url(entity, *args)
45
    project_issue_url(entity.project, entity, *args)
46 47 48
  end

  def merge_request_url(entity, *args)
49
    project_merge_request_url(entity.project, entity, *args)
50
  end
51

52
  def pipeline_url(pipeline, *args)
53
    project_pipeline_url(pipeline.project, pipeline.id, *args)
54 55
  end

56
  def pipeline_job_url(pipeline, build, *args)
57
    project_job_url(pipeline.project, build.id, *args)
58 59 60
  end

  def commits_url(entity, *args)
61
    project_commits_url(entity.project, entity.ref, *args)
62 63 64
  end

  def commit_url(entity, *args)
65
    project_commit_url(entity.project, entity.sha, *args)
66
  end
67

68 69 70
  def preview_markdown_path(parent, *args)
    return group_preview_markdown_path(parent) if parent.is_a?(Group)

71
    if @snippet.is_a?(PersonalSnippet)
72
      preview_markdown_snippets_path
73
    else
74
      preview_markdown_project_path(parent, *args)
75
    end
76 77
  end

78 79 80 81 82 83 84 85
  def edit_milestone_path(entity, *args)
    if entity.parent.is_a?(Group)
      edit_group_milestone_path(entity.parent, entity, *args)
    else
      edit_project_milestone_path(entity.parent, entity, *args)
    end
  end

86 87
  def toggle_subscription_path(entity, *args)
    if entity.is_a?(Issue)
88
      toggle_subscription_project_issue_path(entity.project, entity)
89
    else
90
      toggle_subscription_project_merge_request_path(entity.project, entity)
91 92
    end
  end
93

94 95 96 97 98 99 100 101
  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

102 103
  ## Members
  def project_members_url(project, *args)
104
    project_project_members_url(project, *args)
105 106 107
  end

  def project_member_path(project_member, *args)
108
    project_project_member_path(project_member.source, project_member)
109 110 111
  end

  def request_access_project_members_path(project, *args)
112
    request_access_project_project_members_path(project)
113 114 115
  end

  def leave_project_members_path(project, *args)
116
    leave_project_project_members_path(project)
117 118 119
  end

  def approve_access_request_project_member_path(project_member, *args)
120
    approve_access_request_project_project_member_path(project_member.source, project_member)
121 122 123
  end

  def resend_invite_project_member_path(project_member, *args)
124
    resend_invite_project_project_member_path(project_member.source, project_member)
125 126
  end

127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
  # 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
153 154 155

  # Artifacts

156
  def artifacts_action_path(path, project, build)
157
    action, path_params = path.split('/', 2)
158
    args = [project, build, path_params]
159

160
    case action
161
    when 'download'
162
      download_project_job_artifacts_path(*args)
163
    when 'browse'
164
      browse_project_job_artifacts_path(*args)
165
    when 'file'
166
      file_project_job_artifacts_path(*args)
167
    when 'raw'
168
      raw_project_job_artifacts_path(*args)
169 170
    end
  end
171

172 173
  # Pipeline Schedules
  def pipeline_schedules_path(project, *args)
174
    project_pipeline_schedules_path(project, *args)
175 176 177 178
  end

  def pipeline_schedule_path(schedule, *args)
    project = schedule.project
179
    project_pipeline_schedule_path(project, schedule, *args)
180 181 182 183
  end

  def edit_pipeline_schedule_path(schedule)
    project = schedule.project
184
    edit_project_pipeline_schedule_path(project, schedule)
185 186
  end

187
  def play_pipeline_schedule_path(schedule, *args)
188
    project = schedule.project
189
    play_project_pipeline_schedule_path(project, schedule, *args)
190 191
  end

192 193
  def take_ownership_pipeline_schedule_path(schedule, *args)
    project = schedule.project
194
    take_ownership_project_pipeline_schedule_path(project, schedule, *args)
195
  end
196
end