gitlab_routing_helper.rb 5.4 KB
Newer Older
1
# Shorter routing method for some project items
2
module GitlabRoutingHelper
3
  extend ActiveSupport::Concern
Kamil Trzcinski's avatar
Kamil Trzcinski committed
4

5 6 7 8
  included do
    Gitlab::Routing.includes_helpers(self)
  end

9 10 11
  # 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
12 13
  end

14 15
  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
16 17
  end

18
  def project_ref_path(project, ref_name, *args)
19
    project_commits_path(project, ref_name, *args)
20 21
  end

22
  def runners_path(project, *args)
23
    project_runners_path(project, *args)
24 25 26
  end

  def runner_path(runner, *args)
27
    project_runner_path(@project, runner, *args)
28 29
  end

30
  def environment_path(environment, *args)
31
    project_environment_path(environment.project, environment, *args)
32 33
  end

34
  def environment_metrics_path(environment, *args)
35
    metrics_project_environment_path(environment.project, environment, *args)
36 37
  end

38
  def issue_path(entity, *args)
39
    project_issue_path(entity.project, entity, *args)
40 41 42
  end

  def merge_request_path(entity, *args)
43
    project_merge_request_path(entity.project, entity, *args)
44
  end
45

46
  def pipeline_path(pipeline, *args)
47
    project_pipeline_path(pipeline.project, pipeline.id, *args)
48 49
  end

50
  def issue_url(entity, *args)
51
    project_issue_url(entity.project, entity, *args)
52 53 54
  end

  def merge_request_url(entity, *args)
55
    project_merge_request_url(entity.project, entity, *args)
56
  end
57

58
  def pipeline_url(pipeline, *args)
59
    project_pipeline_url(pipeline.project, pipeline.id, *args)
60 61
  end

62
  def pipeline_job_url(pipeline, build, *args)
63
    project_job_url(pipeline.project, build.id, *args)
64 65 66
  end

  def commits_url(entity, *args)
67
    project_commits_url(entity.project, entity.ref, *args)
68 69 70
  end

  def commit_url(entity, *args)
71
    project_commit_url(entity.project, entity.sha, *args)
72
  end
73

74 75 76
  def preview_markdown_path(parent, *args)
    return group_preview_markdown_path(parent) if parent.is_a?(Group)

77
    if @snippet.is_a?(PersonalSnippet)
78
      preview_markdown_snippets_path
79
    else
80
      preview_markdown_project_path(parent, *args)
81
    end
82 83
  end

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

92 93 94 95 96 97 98 99
  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

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

  def project_member_path(project_member, *args)
106
    project_project_member_path(project_member.source, project_member)
107 108 109
  end

  def request_access_project_members_path(project, *args)
110
    request_access_project_project_members_path(project)
111 112 113
  end

  def leave_project_members_path(project, *args)
114
    leave_project_project_members_path(project)
115 116 117
  end

  def approve_access_request_project_member_path(project_member, *args)
118
    approve_access_request_project_project_member_path(project_member.source, project_member)
119 120 121
  end

  def resend_invite_project_member_path(project_member, *args)
122
    resend_invite_project_project_member_path(project_member.source, project_member)
123 124
  end

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

  # Artifacts

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

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

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

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

  def edit_pipeline_schedule_path(schedule)
    project = schedule.project
182
    edit_project_pipeline_schedule_path(project, schedule)
183 184
  end

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

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