Skip to content
Snippets Groups Projects
Commit fe13f110 authored by Douwe Maan's avatar Douwe Maan
Browse files

Create and use project path helpers that only need a project, no namespace

parent dc793933
No related branches found
No related tags found
No related merge requests found
Showing
with 54 additions and 119 deletions
class Notify < BaseMailer
include ActionDispatch::Routing::PolymorphicRoutes
include GitlabRoutingHelper
 
include Emails::Issues
include Emails::MergeRequests
Loading
Loading
Loading
Loading
@@ -218,8 +218,7 @@ class Environment < ActiveRecord::Base
end
 
def etag_cache_key
Gitlab::Routing.url_helpers.namespace_project_environments_path(
project.namespace,
Gitlab::Routing.url_helpers.project_environments_path(
project,
format: :json)
end
Loading
Loading
Loading
Loading
@@ -295,11 +295,7 @@ class Issue < ActiveRecord::Base
end
 
def expire_etag_cache
key = Gitlab::Routing.url_helpers.realtime_changes_namespace_project_issue_path(
project.namespace,
project,
self
)
key = Gitlab::Routing.url_helpers.realtime_changes_project_issue_path(project, self)
Gitlab::EtagCaching::Store.new.touch(key)
end
end
Loading
Loading
@@ -330,8 +330,7 @@ class Note < ActiveRecord::Base
def expire_etag_cache
return unless for_issue?
 
key = Gitlab::Routing.url_helpers.namespace_project_noteable_notes_path(
noteable.project.namespace,
key = Gitlab::Routing.url_helpers.project_noteable_notes_path(
noteable.project,
target_type: noteable_type.underscore,
target_id: noteable.id
Loading
Loading
Loading
Loading
@@ -675,7 +675,7 @@ class Project < ActiveRecord::Base
end
 
def web_url
Gitlab::Routing.url_helpers.namespace_project_url(self.namespace, self)
Gitlab::Routing.url_helpers.project_url(self)
end
 
def new_issue_address(author)
Loading
Loading
@@ -851,7 +851,7 @@ class Project < ActiveRecord::Base
def avatar_url(**args)
# We use avatar_path instead of overriding avatar_url because of carrierwave.
# See https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/11001/diffs#note_28659864
avatar_path(args) || (Gitlab::Routing.url_helpers.namespace_project_avatar_url(namespace, self) if avatar_in_git)
avatar_path(args) || (Gitlab::Routing.url_helpers.project_avatar_url(self) if avatar_in_git)
end
 
# For compatibility with old code
Loading
Loading
Loading
Loading
@@ -12,26 +12,26 @@ class GitlabIssueTrackerService < IssueTrackerService
end
 
def project_url
namespace_project_issues_url(project.namespace, project)
project_issues_url(project)
end
 
def new_issue_url
new_namespace_project_issue_url(namespace_id: project.namespace, project_id: project)
new_project_issue_url(project)
end
 
def issue_url(iid)
namespace_project_issue_url(namespace_id: project.namespace, project_id: project, id: iid)
project_issue_url(project, id: iid)
end
 
def project_path
namespace_project_issues_path(project.namespace, project)
project_issues_path(project)
end
 
def new_issue_path
new_namespace_project_issue_path(namespace_id: project.namespace, project_id: project)
new_project_issue_path(project)
end
 
def issue_path(iid)
namespace_project_issue_path(namespace_id: project.namespace, project_id: project, id: iid)
project_issue_path(project, id: iid)
end
end
Loading
Loading
@@ -21,7 +21,7 @@ class IssueTrackerService < Service
end
 
def project_path
project_url
read_attribute(:project_url)
end
 
def new_issue_path
Loading
Loading
Loading
Loading
@@ -152,8 +152,8 @@ class JiraService < IssueTrackerService
url: resource_url(user_path(author))
},
project: {
name: self.project.path_with_namespace,
url: resource_url(namespace_project_path(project.namespace, self.project))
name: project.path_with_namespace,
url: resource_url(namespace_project_path(project.namespace, project)) # rubocop:disable Cop/ProjectPathHelper
},
entity: {
name: noteable_type.humanize.downcase,
Loading
Loading
Loading
Loading
@@ -31,7 +31,7 @@ class ProjectWiki
end
 
def web_url
Gitlab::Routing.url_helpers.namespace_project_wiki_url(@project.namespace, @project, :home)
Gitlab::Routing.url_helpers.project_wiki_url(@project, :home)
end
 
def url_to_repo
Loading
Loading
Loading
Loading
@@ -20,30 +20,25 @@ class MergeRequestPresenter < Gitlab::View::Presenter::Delegated
 
def cancel_merge_when_pipeline_succeeds_path
if can_cancel_merge_when_pipeline_succeeds?(current_user)
cancel_merge_when_pipeline_succeeds_namespace_project_merge_request_path(
project.namespace,
project,
merge_request)
cancel_merge_when_pipeline_succeeds_project_merge_request_path(project, merge_request)
end
end
 
def create_issue_to_resolve_discussions_path
if can?(current_user, :create_issue, project) && project.issues_enabled?
new_namespace_project_issue_path(project.namespace,
project,
merge_request_to_resolve_discussions_of: iid)
new_project_issue_path(project, merge_request_to_resolve_discussions_of: iid)
end
end
 
def remove_wip_path
if can?(current_user, :update_merge_request, merge_request.project)
remove_wip_namespace_project_merge_request_path(project.namespace, project, merge_request)
remove_wip_project_merge_request_path(project, merge_request)
end
end
 
def merge_path
if can_be_merged_by?(current_user)
merge_namespace_project_merge_request_path(project.namespace, project, merge_request)
merge_project_merge_request_path(project, merge_request)
end
end
 
Loading
Loading
@@ -55,7 +50,7 @@ class MergeRequestPresenter < Gitlab::View::Presenter::Delegated
notice_now: edit_in_new_fork_notice_now
}
 
namespace_project_forks_path(merge_request.project.namespace, merge_request.project,
project_forks_path(merge_request.project,
namespace_key: current_user.namespace.id,
continue: continue_params)
end
Loading
Loading
@@ -69,7 +64,7 @@ class MergeRequestPresenter < Gitlab::View::Presenter::Delegated
notice_now: edit_in_new_fork_notice_now
}
 
namespace_project_forks_path(project.namespace, project,
project_forks_path(project,
namespace_key: current_user.namespace.id,
continue: continue_params)
end
Loading
Loading
@@ -77,19 +72,19 @@ class MergeRequestPresenter < Gitlab::View::Presenter::Delegated
 
def conflict_resolution_path
if conflicts.can_be_resolved_in_ui? && conflicts.can_be_resolved_by?(current_user)
conflicts_namespace_project_merge_request_path(project.namespace, project, merge_request)
conflicts_project_merge_request_path(project, merge_request)
end
end
 
def target_branch_commits_path
if target_branch_exists?
namespace_project_commits_path(project.namespace, project, target_branch)
project_commits_path(project, target_branch)
end
end
 
def source_branch_path
if source_branch_exists?
namespace_project_branch_path(source_project.namespace, source_project, source_branch)
project_branch_path(source_project, source_branch)
end
end
 
Loading
Loading
@@ -99,7 +94,7 @@ class MergeRequestPresenter < Gitlab::View::Presenter::Delegated
 
if source_branch_exists?
namespace = link_to(namespace, project_path(source_project))
branch = link_to(branch, namespace_project_commits_path(source_project.namespace, source_project, source_branch))
branch = link_to(branch, project_commits_path(source_project, source_branch))
end
 
if for_fork?
Loading
Loading
@@ -136,7 +131,7 @@ class MergeRequestPresenter < Gitlab::View::Presenter::Delegated
merge_request: merge_request,
closes_issues: closing_issues
).assignable_issues
path = assign_related_issues_namespace_project_merge_request_path(project.namespace, project, merge_request)
path = assign_related_issues_project_merge_request_path(project, merge_request)
if issues.present?
pluralize_this_issue = issues.count > 1 ? "these issues" : "this issue"
link_to "Assign yourself to #{pluralize_this_issue}", path, method: :post
Loading
Loading
Loading
Loading
@@ -6,10 +6,7 @@ class BuildActionEntity < Grape::Entity
end
 
expose :path do |build|
play_namespace_project_job_path(
build.project.namespace,
build.project,
build)
play_project_job_path(build.project, build)
end
 
expose :playable?, as: :playable
Loading
Loading
Loading
Loading
@@ -9,24 +9,15 @@ class BuildArtifactEntity < Grape::Entity
expose :artifacts_expire_at, as: :expire_at
 
expose :path do |job|
download_namespace_project_job_artifacts_path(
project.namespace,
project,
job)
download_project_job_artifacts_path(project, job)
end
 
expose :keep_path, if: -> (*) { job.has_expiring_artifacts? } do |job|
keep_namespace_project_job_artifacts_path(
project.namespace,
project,
job)
keep_project_job_artifacts_path(project, job)
end
 
expose :browse_path do |job|
browse_namespace_project_job_artifacts_path(
project.namespace,
project,
job)
browse_project_job_artifacts_path(project, job)
end
 
private
Loading
Loading
Loading
Loading
@@ -7,7 +7,7 @@ class BuildDetailsEntity < JobEntity
 
expose :erased_by, if: -> (*) { build.erased? }, using: UserEntity
expose :erase_path, if: -> (*) { build.erasable? && can?(current_user, :update_build, project) } do |build|
erase_namespace_project_job_path(project.namespace, project, build)
erase_project_job_path(project, build)
end
 
expose :merge_request, if: -> (*) { can?(current_user, :read_merge_request, build.merge_request) } do
Loading
Loading
@@ -16,23 +16,23 @@ class BuildDetailsEntity < JobEntity
end
 
expose :path do |build|
namespace_project_merge_request_path(project.namespace, project, build.merge_request)
project_merge_request_path(project, build.merge_request)
end
end
 
expose :new_issue_path, if: -> (*) { can?(request.current_user, :create_issue, project) && build.failed? } do |build|
new_namespace_project_issue_path(project.namespace, project, issue: build_failed_issue_options)
new_project_issue_path(project, issue: build_failed_issue_options)
end
 
expose :raw_path do |build|
raw_namespace_project_job_path(project.namespace, project, build)
raw_project_job_path(project, build)
end
 
private
 
def build_failed_issue_options
{ title: "Build Failed ##{build.id}",
description: namespace_project_job_path(project.namespace, project, build) }
description: project_job_path(project, build) }
end
 
def current_user
Loading
Loading
Loading
Loading
@@ -8,16 +8,10 @@ class CommitEntity < API::Entities::RepoCommit
end
 
expose :commit_url do |commit|
namespace_project_commit_url(
request.project.namespace,
request.project,
commit)
project_commit_url(request.project, commit)
end
 
expose :commit_path do |commit|
namespace_project_commit_path(
request.project.namespace,
request.project,
commit)
project_commit_path(request.project, commit)
end
end
Loading
Loading
@@ -11,10 +11,7 @@ class DeploymentEntity < Grape::Entity
end
 
expose :ref_path do |deployment|
namespace_project_tree_path(
deployment.project.namespace,
deployment.project,
id: deployment.ref)
project_tree_path(deployment.project, id: deployment.ref)
end
end
 
Loading
Loading
Loading
Loading
@@ -10,32 +10,20 @@ class EnvironmentEntity < Grape::Entity
expose :stop_action?
 
expose :metrics_path, if: -> (environment, _) { environment.has_metrics? } do |environment|
metrics_namespace_project_environment_path(
environment.project.namespace,
environment.project,
environment)
metrics_project_environment_path(environment.project, environment)
end
 
expose :environment_path do |environment|
namespace_project_environment_path(
environment.project.namespace,
environment.project,
environment)
project_environment_path(environment.project, environment)
end
 
expose :stop_path do |environment|
stop_namespace_project_environment_path(
environment.project.namespace,
environment.project,
environment)
stop_project_environment_path(environment.project, environment)
end
 
expose :terminal_path, if: ->(environment, _) { environment.has_terminals? } do |environment|
can?(request.current_user, :admin_environment, environment.project) &&
terminal_namespace_project_environment_path(
environment.project.namespace,
environment.project,
environment)
terminal_project_environment_path(environment.project, environment)
end
 
expose :created_at, :updated_at
Loading
Loading
Loading
Loading
@@ -11,6 +11,6 @@ class IssueEntity < IssuableEntity
expose :labels, using: LabelEntity
 
expose :web_url do |issue|
namespace_project_issue_path(issue.project.namespace, issue.project, issue)
project_issue_path(issue.project, issue)
end
end
Loading
Loading
@@ -99,9 +99,7 @@ class MergeRequestEntity < IssuableEntity
 
expose :new_blob_path do |merge_request|
if can?(current_user, :push_code, merge_request.project)
namespace_project_new_blob_path(merge_request.project.namespace,
merge_request.project,
merge_request.source_branch)
project_new_blob_path(merge_request.project, merge_request.source_branch)
end
end
 
Loading
Loading
@@ -134,30 +132,19 @@ class MergeRequestEntity < IssuableEntity
end
 
expose :email_patches_path do |merge_request|
namespace_project_merge_request_path(merge_request.project.namespace,
merge_request.project,
merge_request,
format: :patch)
project_merge_request_path(merge_request.project, merge_request, format: :patch)
end
 
expose :plain_diff_path do |merge_request|
namespace_project_merge_request_path(merge_request.project.namespace,
merge_request.project,
merge_request,
format: :diff)
project_merge_request_path(merge_request.project, merge_request, format: :diff)
end
 
expose :status_path do |merge_request|
namespace_project_merge_request_path(merge_request.target_project.namespace,
merge_request.target_project,
merge_request,
format: :json)
project_merge_request_path(merge_request.target_project, merge_request, format: :json)
end
 
expose :ci_environments_status_path do |merge_request|
ci_environments_status_namespace_project_merge_request_path(merge_request.project.namespace,
merge_request.project,
merge_request)
ci_environments_status_project_merge_request_path(merge_request.project, merge_request)
end
 
expose :merge_commit_message_with_description do |merge_request|
Loading
Loading
@@ -173,9 +160,7 @@ class MergeRequestEntity < IssuableEntity
end
 
expose :commit_change_content_path do |merge_request|
commit_change_content_namespace_project_merge_request_path(merge_request.project.namespace,
merge_request.project,
merge_request)
commit_change_content_project_merge_request_path(merge_request.project, merge_request)
end
 
private
Loading
Loading
Loading
Loading
@@ -10,10 +10,7 @@ class PipelineEntity < Grape::Entity
expose :created_at, :updated_at
 
expose :path do |pipeline|
namespace_project_pipeline_path(
pipeline.project.namespace,
pipeline.project,
pipeline)
project_pipeline_path(pipeline.project, pipeline)
end
 
expose :flags do
Loading
Loading
@@ -48,15 +45,11 @@ class PipelineEntity < Grape::Entity
expose :commit, using: CommitEntity
 
expose :retry_path, if: -> (*) { can_retry? } do |pipeline|
retry_namespace_project_pipeline_path(pipeline.project.namespace,
pipeline.project,
pipeline.id)
retry_project_pipeline_path(pipeline.project, pipeline)
end
 
expose :cancel_path, if: -> (*) { can_cancel? } do |pipeline|
cancel_namespace_project_pipeline_path(pipeline.project.namespace,
pipeline.project,
pipeline.id)
cancel_project_pipeline_path(pipeline.project, pipeline)
end
 
expose :yaml_errors, if: -> (pipeline, _) { pipeline.has_yaml_errors? }
Loading
Loading
Loading
Loading
@@ -5,7 +5,7 @@ class ProjectEntity < Grape::Entity
expose :name
 
expose :full_path do |project|
namespace_project_path(project.namespace, project)
project_path(project)
end
 
expose :full_name do |project|
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment