BigW Consortium Gitlab

gitlab_routing_helper.rb 8.37 KB
Newer Older
1
# Shorter routing method for project and project items
2 3 4 5 6 7 8
# Since update to rails 4.1.9 we are now allowed to use `/` in project routing
# so we use nested routing for project resources which include project and
# project namespace. To avoid writing long methods every time we define shortcuts for
# some of routing.
#
# For example instead of this:
#
9
#   namespace_project_merge_request_path(merge_request.project.namespace, merge_request.project, merge_request)
10 11 12 13 14
#
# We can simply use shortcut:
#
#   merge_request_path(merge_request)
#
15
module GitlabRoutingHelper
16
  # Project
17 18 19 20
  def project_path(project, *args)
    namespace_project_path(project.namespace, project, *args)
  end

21 22 23 24 25 26 27 28 29 30 31 32
  def project_url(project, *args)
    namespace_project_url(project.namespace, project, *args)
  end

  def edit_project_path(project, *args)
    edit_namespace_project_path(project.namespace, project, *args)
  end

  def edit_project_url(project, *args)
    edit_namespace_project_url(project.namespace, project, *args)
  end

33 34 35 36 37 38 39 40
  def project_files_path(project, *args)
    namespace_project_tree_path(project.namespace, project, @ref || project.repository.root_ref)
  end

  def project_commits_path(project, *args)
    namespace_project_commits_path(project.namespace, project, @ref || project.repository.root_ref)
  end

41 42 43 44
  def project_pipelines_path(project, *args)
    namespace_project_pipelines_path(project.namespace, project, *args)
  end

Kamil Trzcinski committed
45 46 47 48
  def project_environments_path(project, *args)
    namespace_project_environments_path(project.namespace, project, *args)
  end

49 50 51 52
  def project_cycle_analytics_path(project, *args)
    namespace_project_cycle_analytics_path(project.namespace, project, *args)
  end

Kamil Trzcinski committed
53 54 55 56
  def project_builds_path(project, *args)
    namespace_project_builds_path(project.namespace, project, *args)
  end

57 58 59 60
  def project_ref_path(project, ref_name, *args)
    namespace_project_commits_path(project.namespace, project, ref_name, *args)
  end

Kamil Trzcinski committed
61
  def project_container_registry_path(project, *args)
Kamil Trzcinski committed
62
    namespace_project_container_registry_index_path(project.namespace, project, *args)
63 64
  end

65 66 67 68
  def activity_project_path(project, *args)
    activity_namespace_project_path(project.namespace, project, *args)
  end

69 70 71 72 73 74 75 76
  def runners_path(project, *args)
    namespace_project_runners_path(project.namespace, project, *args)
  end

  def runner_path(runner, *args)
    namespace_project_runner_path(@project.namespace, @project, runner, *args)
  end

77 78 79 80
  def environment_path(environment, *args)
    namespace_project_environment_path(environment.project.namespace, environment.project, environment, *args)
  end

81 82 83 84
  def environment_metrics_path(environment, *args)
    metrics_namespace_project_environment_path(environment.project.namespace, environment.project, environment, *args)
  end

85 86 87 88 89 90 91
  def issue_path(entity, *args)
    namespace_project_issue_path(entity.project.namespace, entity.project, entity, *args)
  end

  def merge_request_path(entity, *args)
    namespace_project_merge_request_path(entity.project.namespace, entity.project, entity, *args)
  end
92

93 94 95 96
  def pipeline_path(pipeline, *args)
    namespace_project_pipeline_path(pipeline.project.namespace, pipeline.project, pipeline.id, *args)
  end

97 98 99 100
  def milestone_path(entity, *args)
    namespace_project_milestone_path(entity.project.namespace, entity.project, entity, *args)
  end

101 102 103 104 105 106 107
  def issue_url(entity, *args)
    namespace_project_issue_url(entity.project.namespace, entity.project, entity, *args)
  end

  def merge_request_url(entity, *args)
    namespace_project_merge_request_url(entity.project.namespace, entity.project, entity, *args)
  end
108

109
  def pipeline_url(pipeline, *args)
110
    namespace_project_pipeline_url(pipeline.project.namespace, pipeline.project, pipeline.id, *args)
111 112 113
  end

  def pipeline_build_url(pipeline, build, *args)
114
    namespace_project_build_url(pipeline.project.namespace, pipeline.project, build.id, *args)
115 116 117
  end

  def commits_url(entity, *args)
118
    namespace_project_commits_url(entity.project.namespace, entity.project, entity.ref, *args)
119 120 121
  end

  def commit_url(entity, *args)
122
    namespace_project_commit_url(entity.project.namespace, entity.project, entity.sha, *args)
123 124
  end

125
  def project_snippet_url(entity, *args)
126 127
    namespace_project_snippet_url(entity.project.namespace, entity.project, entity, *args)
  end
128

129
  def preview_markdown_path(project, *args)
130 131 132 133 134
    if @snippet.is_a?(PersonalSnippet)
      preview_markdown_snippet_path(@snippet)
    else
      preview_markdown_namespace_project_path(project.namespace, project, *args)
    end
135 136
  end

137 138 139 140 141 142 143
  def toggle_subscription_path(entity, *args)
    if entity.is_a?(Issue)
      toggle_subscription_namespace_project_issue_path(entity.project.namespace, entity.project, entity)
    else
      toggle_subscription_namespace_project_merge_request_path(entity.project.namespace, entity.project, entity)
    end
  end
144

145 146 147 148 149 150 151 152
  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

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
  ## Members
  def project_members_url(project, *args)
    namespace_project_project_members_url(project.namespace, project)
  end

  def project_member_path(project_member, *args)
    namespace_project_project_member_path(project_member.source.namespace, project_member.source, project_member)
  end

  def request_access_project_members_path(project, *args)
    request_access_namespace_project_project_members_path(project.namespace, project)
  end

  def leave_project_members_path(project, *args)
    leave_namespace_project_project_members_path(project.namespace, project)
  end

  def approve_access_request_project_member_path(project_member, *args)
    approve_access_request_namespace_project_project_member_path(project_member.source.namespace, project_member.source, project_member)
  end

  def resend_invite_project_member_path(project_member, *args)
    resend_invite_namespace_project_project_member_path(project_member.source.namespace, project_member.source, project_member)
  end

178 179 180 181 182
  # Snippets
  def personal_snippet_url(snippet, *args)
    snippet_url(snippet)
  end

183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
  # 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
209 210 211

  # Artifacts

212
  def artifacts_action_path(path, project, build)
213 214
    action, path_params = path.split('/', 2)
    args = [project.namespace, project, build, path_params]
215

216
    case action
217
    when 'download'
218
      download_namespace_project_build_artifacts_path(*args)
219
    when 'browse'
220
      browse_namespace_project_build_artifacts_path(*args)
221
    when 'file'
222
      file_namespace_project_build_artifacts_path(*args)
223 224
    when 'raw'
      raw_namespace_project_build_artifacts_path(*args)
225 226
    end
  end
227

228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
  # Pipeline Schedules
  def pipeline_schedules_path(project, *args)
    namespace_project_pipeline_schedules_path(project.namespace, project, *args)
  end

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

  def edit_pipeline_schedule_path(schedule)
    project = schedule.project
    edit_namespace_project_pipeline_schedule_path(project.namespace, project, schedule)
  end

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

248
  # Settings
249 250 251
  def project_settings_integrations_path(project, *args)
    namespace_project_settings_integrations_path(project.namespace, project, *args)
  end
252

253 254 255
  def project_settings_members_path(project, *args)
    namespace_project_settings_members_path(project.namespace, project, *args)
  end
256 257 258 259

  def project_settings_ci_cd_path(project, *args)
    namespace_project_settings_ci_cd_path(project.namespace, project, *args)
  end
260
end