Commit fe13f110 authored by Douwe Maan's avatar Douwe Maan

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

parent dc793933
......@@ -40,14 +40,14 @@ class Admin::ProjectsController < Admin::ApplicationController
::Projects::TransferService.new(@project, current_user, params.dup).execute(namespace)
@project.reload
redirect_to admin_namespace_project_path(@project.namespace, @project)
redirect_to admin_project_path(@project)
end
def repository_check
RepositoryCheck::SingleRepositoryWorker.perform_async(@project.id)
redirect_to(
admin_namespace_project_path(@project.namespace, @project),
admin_project_path(@project),
notice: 'Repository check was triggered.'
)
end
......
......@@ -78,8 +78,7 @@ module CreatesCommit
end
def new_merge_request_path
namespace_project_new_merge_request_path(
@project_to_commit_into.namespace,
project_new_merge_request_path(
@project_to_commit_into,
merge_request: {
source_project_id: @project_to_commit_into.id,
......@@ -91,7 +90,7 @@ module CreatesCommit
end
def existing_merge_request_path
namespace_project_merge_request_path(@project.namespace, @project, @merge_request)
project_merge_request_path(@project, @merge_request)
end
def merge_request_exists?
......
......@@ -45,7 +45,7 @@ module MilestoneActions
def milestone_redirect_path
if @project
namespace_project_milestone_path(@project.namespace, @project, @milestone)
project_milestone_path(@project, @milestone)
elsif @group
group_milestone_path(@group, @milestone.safe_title, title: @milestone.title)
else
......
......@@ -2,6 +2,6 @@ module RepositorySettingsRedirect
extend ActiveSupport::Concern
def redirect_to_repository_settings(project)
redirect_to namespace_project_settings_repository_path(project.namespace, project)
redirect_to project_settings_repository_path(project)
end
end
......@@ -9,9 +9,9 @@ module SpammableActions
def mark_as_spam
if SpamService.new(spammable).mark_as_spam!
redirect_to spammable, notice: "#{spammable.spammable_entity_type.titlecase} was submitted to Akismet successfully."
redirect_to spammable_path, notice: "#{spammable.spammable_entity_type.titlecase} was submitted to Akismet successfully."
else
redirect_to spammable, alert: 'Error with Akismet. Please check the logs for more info.'
redirect_to spammable_path, alert: 'Error with Akismet. Please check the logs for more info.'
end
end
......@@ -25,7 +25,7 @@ module SpammableActions
def recaptcha_check_with_fallback(&fallback)
if spammable.valid?
redirect_to spammable
redirect_to spammable_path
elsif render_recaptcha?
ensure_spam_config_loaded!
......@@ -56,6 +56,10 @@ module SpammableActions
raise NotImplementedError, "#{self.class} does not implement #{__method__}"
end
def spammable_path
raise NotImplementedError, "#{self.class} does not implement #{__method__}"
end
def authorize_submit_spammable!
access_denied! unless current_user.admin?
end
......
......@@ -63,7 +63,7 @@ class InvitesController < ApplicationController
when Project
project = member.source
label = "project #{project.name_with_namespace}"
path = namespace_project_path(project.namespace, project)
path = project_path(project)
when Group
group = member.source
label = "group #{group.name}"
......
......@@ -76,13 +76,13 @@ class Projects::ApplicationController < ApplicationController
def require_non_empty_project
# Be sure to return status code 303 to avoid a double DELETE:
# http://api.rubyonrails.org/classes/ActionController/Redirecting.html
redirect_to namespace_project_path(@project.namespace, @project), status: 303 if @project.empty_repo?
redirect_to project_path(@project), status: 303 if @project.empty_repo?
end
def require_branch_head
unless @repository.branch_exists?(@ref)
redirect_to(
namespace_project_tree_path(@project.namespace, @project, @ref),
project_tree_path(@project, @ref),
notice: "This action is not allowed unless you are on a branch"
)
end
......
......@@ -46,7 +46,7 @@ class Projects::ArtifactsController < Projects::ApplicationController
def keep
build.keep_artifacts!
redirect_to namespace_project_job_path(project.namespace, project, build)
redirect_to project_job_path(project, build)
end
def latest_succeeded
......
......@@ -27,9 +27,9 @@ class Projects::BlobController < Projects::ApplicationController
def create
create_commit(Files::CreateService, success_notice: "The file has been successfully created.",
success_path: -> { namespace_project_blob_path(@project.namespace, @project, File.join(@branch_name, @file_path)) },
success_path: -> { project_blob_path(@project, File.join(@branch_name, @file_path)) },
failure_view: :new,
failure_path: namespace_project_new_blob_path(@project.namespace, @project, @ref))
failure_path: project_new_blob_path(@project, @ref))
end
def show
......@@ -63,7 +63,7 @@ class Projects::BlobController < Projects::ApplicationController
@path = params[:file_path] if params[:file_path].present?
create_commit(Files::UpdateService, success_path: -> { after_edit_path },
failure_view: :edit,
failure_path: namespace_project_blob_path(@project.namespace, @project, @id))
failure_path: project_blob_path(@project, @id))
rescue Files::UpdateService::FileChangedError
@conflict = true
......@@ -83,9 +83,9 @@ class Projects::BlobController < Projects::ApplicationController
def destroy
create_commit(Files::DeleteService, success_notice: "The file has been successfully deleted.",
success_path: -> { namespace_project_tree_path(@project.namespace, @project, @branch_name) },
success_path: -> { project_tree_path(@project, @branch_name) },
failure_view: :show,
failure_path: namespace_project_blob_path(@project.namespace, @project, @id))
failure_path: project_blob_path(@project, @id))
end
def diff
......@@ -118,7 +118,7 @@ class Projects::BlobController < Projects::ApplicationController
else
if tree = @repository.tree(@commit.id, @path)
if tree.entries.any?
return redirect_to namespace_project_tree_path(@project.namespace, @project, File.join(@ref, @path))
return redirect_to project_tree_path(@project, File.join(@ref, @path))
end
end
......@@ -143,10 +143,10 @@ class Projects::BlobController < Projects::ApplicationController
def after_edit_path
from_merge_request = MergeRequestsFinder.new(current_user, project_id: @project.id).execute.find_by(iid: params[:from_merge_request_iid])
if from_merge_request && @branch_name == @ref
diffs_namespace_project_merge_request_path(from_merge_request.target_project.namespace, from_merge_request.target_project, from_merge_request) +
diffs_project_merge_request_path(from_merge_request.target_project, from_merge_request) +
"##{hexdigest(@path)}"
else
namespace_project_blob_path(@project.namespace, @project, File.join(@branch_name, @path))
project_blob_path(@project, File.join(@branch_name, @path))
end
end
......
......@@ -52,7 +52,7 @@ class Projects::BranchesController < Projects::ApplicationController
redirect_to url_to_autodeploy_setup(project, branch_name),
notice: view_context.autodeploy_flash_notice(branch_name)
else
redirect_to namespace_project_tree_path(@project.namespace, @project, branch_name)
redirect_to project_tree_path(@project, branch_name)
end
else
@error = result[:message]
......@@ -62,7 +62,7 @@ class Projects::BranchesController < Projects::ApplicationController
format.json do
if result[:status] == :success
render json: { name: branch_name, url: namespace_project_tree_url(@project.namespace, @project, branch_name) }
render json: { name: branch_name, url: project_tree_url(@project, branch_name) }
else
render json: result[:messsage], status: :unprocessable_entity
end
......@@ -79,7 +79,7 @@ class Projects::BranchesController < Projects::ApplicationController
flash_type = result[:status] == :error ? :alert : :notice
flash[flash_type] = result[:message]
redirect_to namespace_project_branches_path(@project.namespace, @project), status: 303
redirect_to project_branches_path(@project), status: 303
end
format.js { render nothing: true, status: result[:return_code] }
......@@ -90,7 +90,7 @@ class Projects::BranchesController < Projects::ApplicationController
def destroy_all_merged
DeleteMergedBranchesService.new(@project, current_user).async_execute
redirect_to namespace_project_branches_path(@project.namespace, @project),
redirect_to project_branches_path(@project),
notice: 'Merged branches are being deleted. This can take some time depending on the number of branches. Please refresh the page to see changes.'
end
......@@ -106,8 +106,7 @@ class Projects::BranchesController < Projects::ApplicationController
end
def url_to_autodeploy_setup(project, branch_name)
namespace_project_new_blob_path(
project.namespace,
project_new_blob_path(
project,
branch_name,
file_name: '.gitlab-ci.yml',
......
......@@ -7,23 +7,23 @@ class Projects::BuildArtifactsController < Projects::ApplicationController
before_action :validate_artifacts!
def download
redirect_to download_namespace_project_job_artifacts_path(project.namespace, project, job)
redirect_to download_project_job_artifacts_path(project, job)
end
def browse
redirect_to browse_namespace_project_job_artifacts_path(project.namespace, project, job, path: params[:path])
redirect_to browse_project_job_artifacts_path(project, job, path: params[:path])
end
def file
redirect_to file_namespace_project_job_artifacts_path(project.namespace, project, job, path: params[:path])
redirect_to file_project_job_artifacts_path(project, job, path: params[:path])
end
def raw
redirect_to raw_namespace_project_job_artifacts_path(project.namespace, project, job, path: params[:path])
redirect_to raw_project_job_artifacts_path(project, job, path: params[:path])
end
def latest_succeeded
redirect_to latest_succeeded_namespace_project_artifacts_path(project.namespace, project, job, ref_name_and_path: params[:ref_name_and_path], job: params[:job])
redirect_to latest_succeeded_project_artifacts_path(project, job, ref_name_and_path: params[:ref_name_and_path], job: params[:job])
end
private
......
......@@ -2,15 +2,15 @@ class Projects::BuildsController < Projects::ApplicationController
before_action :authorize_read_build!
def index
redirect_to namespace_project_jobs_path(project.namespace, project)
redirect_to project_jobs_path(project)
end
def show
redirect_to namespace_project_job_path(project.namespace, project, job)
redirect_to project_job_path(project, job)
end
def raw
redirect_to raw_namespace_project_job_path(project.namespace, project, job)
redirect_to raw_project_job_path(project, job)
end
private
......
......@@ -80,16 +80,16 @@ class Projects::CommitController < Projects::ApplicationController
end
def successful_change_path
referenced_merge_request_url || namespace_project_commits_url(@project.namespace, @project, @branch_name)
referenced_merge_request_url || project_commits_url(@project, @branch_name)
end
def failed_change_path
referenced_merge_request_url || namespace_project_commit_url(@project.namespace, @project, params[:id])
referenced_merge_request_url || project_commit_url(@project, params[:id])
end
def referenced_merge_request_url
if merge_request = @commit.merged_merge_request(current_user)
namespace_project_merge_request_url(merge_request.target_project.namespace, merge_request.target_project, merge_request)
project_merge_request_url(merge_request.target_project, merge_request)
end
end
......
......@@ -31,9 +31,9 @@ class Projects::CompareController < Projects::ApplicationController
from: params[:from].presence,
to: params[:to].presence
}
redirect_to namespace_project_compare_index_path(@project.namespace, @project, from_to_vars)
redirect_to project_compare_index_path(@project, from_to_vars)
else
redirect_to namespace_project_compare_path(@project.namespace, @project,
redirect_to project_compare_path(@project,
params[:from], params[:to])
end
end
......
......@@ -63,7 +63,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController
@environment = project.environments.create(environment_params)
if @environment.persisted?
redirect_to namespace_project_environment_path(project.namespace, project, @environment)
redirect_to project_environment_path(project, @environment)
else
render :new
end
......@@ -71,7 +71,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController
def update
if @environment.update(environment_params)
redirect_to namespace_project_environment_path(project.namespace, project, @environment)
redirect_to project_environment_path(project, @environment)
else
render :edit
end
......@@ -86,7 +86,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController
if stop_action
polymorphic_url([project.namespace.becomes(Namespace), project, stop_action])
else
namespace_project_environment_url(project.namespace, project, @environment)
project_environment_url(project, @environment)
end
respond_to do |format|
......
......@@ -44,12 +44,12 @@ class Projects::ForksController < Projects::ApplicationController
if @forked_project.saved? && @forked_project.forked?
if @forked_project.import_in_progress?
redirect_to namespace_project_import_path(@forked_project.namespace, @forked_project, continue: continue_params)
redirect_to project_import_path(@forked_project, continue: continue_params)
else
if continue_params
redirect_to continue_params[:to], notice: continue_params[:notice]
else
redirect_to namespace_project_path(@forked_project.namespace, @forked_project), notice: "The project '#{@forked_project.name}' was successfully forked."
redirect_to project_path(@forked_project), notice: "The project '#{@forked_project.name}' was successfully forked."
end
end
else
......
......@@ -29,7 +29,7 @@ class Projects::GraphsController < Projects::ApplicationController
end
def ci
redirect_to charts_namespace_project_pipelines_path(@project.namespace, @project)
redirect_to charts_project_pipelines_path(@project)
end
private
......
......@@ -22,7 +22,7 @@ class Projects::GroupLinksController < Projects::ApplicationController
flash[:alert] = 'Please select a group.'
end
redirect_to namespace_project_settings_members_path(project.namespace, project)
redirect_to project_settings_members_path(project)
end
def update
......@@ -36,7 +36,7 @@ class Projects::GroupLinksController < Projects::ApplicationController
respond_to do |format|
format.html do