summaryrefslogtreecommitdiff
path: root/app/helpers/gitlab_routing_helper.rb
blob: 61e12b0f31e5bf06b9164e743adfae19336b97b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# Shorter routing method for some project items
module GitlabRoutingHelper
  extend ActiveSupport::Concern

  included do
    Gitlab::Routing.includes_helpers(self)
  end

  # 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
  end

  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
  end

  def project_ref_path(project, ref_name, *args)
    project_commits_path(project, ref_name, *args)
  end

  def environment_path(environment, *args)
    project_environment_path(environment.project, environment, *args)
  end

  def environment_metrics_path(environment, *args)
    metrics_project_environment_path(environment.project, environment, *args)
  end

  def issue_path(entity, *args)
    project_issue_path(entity.project, entity, *args)
  end

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

  def pipeline_path(pipeline, *args)
    project_pipeline_path(pipeline.project, pipeline.id, *args)
  end

  def issue_url(entity, *args)
    project_issue_url(entity.project, entity, *args)
  end

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

  def pipeline_url(pipeline, *args)
    project_pipeline_url(pipeline.project, pipeline.id, *args)
  end

  def pipeline_job_url(pipeline, build, *args)
    project_job_url(pipeline.project, build.id, *args)
  end

  def commits_url(entity, *args)
    project_commits_url(entity.project, entity.ref, *args)
  end

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

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

    if @snippet.is_a?(PersonalSnippet)
      preview_markdown_snippets_path
    else
      preview_markdown_project_path(parent, *args)
    end
  end

  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

  def toggle_subscription_path(entity, *args)
    if entity.is_a?(Issue)
      toggle_subscription_project_issue_path(entity.project, entity)
    else
      toggle_subscription_project_merge_request_path(entity.project, entity)
    end
  end

  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)
    project_project_members_url(project, *args)
  end

  def project_member_path(project_member, *args)
    project_project_member_path(project_member.source, project_member)
  end

  def request_access_project_members_path(project, *args)
    request_access_project_project_members_path(project)
  end

  def leave_project_members_path(project, *args)
    leave_project_project_members_path(project)
  end

  def approve_access_request_project_member_path(project_member, *args)
    approve_access_request_project_project_member_path(project_member.source, project_member)
  end

  def resend_invite_project_member_path(project_member, *args)
    resend_invite_project_project_member_path(project_member.source, project_member)
  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

  # Artifacts

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

    case action
    when 'download'
      download_project_job_artifacts_path(*args)
    when 'browse'
      browse_project_job_artifacts_path(*args)
    when 'file'
      file_project_job_artifacts_path(*args)
    when 'raw'
      raw_project_job_artifacts_path(*args)
    end
  end

  # Pipeline Schedules
  def pipeline_schedules_path(project, *args)
    project_pipeline_schedules_path(project, *args)
  end

  def pipeline_schedule_path(schedule, *args)
    project = schedule.project
    project_pipeline_schedule_path(project, schedule, *args)
  end

  def edit_pipeline_schedule_path(schedule)
    project = schedule.project
    edit_project_pipeline_schedule_path(project, schedule)
  end

  def play_pipeline_schedule_path(schedule, *args)
    project = schedule.project
    play_project_pipeline_schedule_path(project, schedule, *args)
  end

  def take_ownership_pipeline_schedule_path(schedule, *args)
    project = schedule.project
    take_ownership_project_pipeline_schedule_path(project, schedule, *args)
  end
end