Commit e292d7c1 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Make transfer action in project controller

parent ff35b37f
module Projects
class UpdateContext < BaseContext
def execute(role = :default)
namespace_id = params[:project].delete(:namespace_id)
params[:project].delete(:namespace_id)
params[:project].delete(:public) unless can?(current_user, :change_public_mode, project)
allowed_transfer = can?(current_user, :change_namespace, project) || role == :admin
if allowed_transfer && namespace_id.present?
if namespace_id == Namespace.global_id
if project.namespace.present?
# Transfer to global namespace from anyone
project.transfer(nil)
end
elsif namespace_id.to_i != project.namespace_id
# Transfer to someone namespace
namespace = Namespace.find(namespace_id)
project.transfer(namespace)
end
end
project.update_attributes(params[:project], as: role)
end
end
......
......@@ -4,7 +4,7 @@ class ProjectsController < ProjectResourceController
# Authorize
before_filter :authorize_read_project!, except: [:index, :new, :create]
before_filter :authorize_admin_project!, only: [:edit, :update, :destroy]
before_filter :authorize_admin_project!, only: [:edit, :update, :destroy, :transfer]
before_filter :require_non_empty_project, only: [:blob, :tree, :graph]
layout 'application', only: [:new, :create]
......@@ -45,10 +45,10 @@ class ProjectsController < ProjectResourceController
format.js
end
end
end
rescue Project::TransferError => ex
@error = ex
render :update_failed
def transfer
::Projects::TransferContext.new(project, current_user, params).execute
end
def show
......
......@@ -26,8 +26,6 @@ class Project < ActiveRecord::Base
include Gitlab::ShellAdapter
extend Enumerize
class TransferError < StandardError; end
attr_accessible :name, :path, :description, :default_branch, :issues_tracker,
:issues_enabled, :wall_enabled, :merge_requests_enabled, :snippets_enabled, :issues_tracker_id,
:wiki_enabled, :public, :import_url, as: [:default, :admin]
......
......@@ -107,8 +107,9 @@
- if can?(current_user, :change_namespace, @project)
.ui-box.ui-box-danger
%h5.title Transfer project
.errors-holder
.form-holder
= form_for(@project, remote: true, html: { class: 'transfer-project' }) do |f|
= form_for(@project, url: transfer_project_path(@project), remote: true, html: { class: 'transfer-project' }) do |f|
.control-group
= f.label :namespace_id do
%span Namespace
......
:plain
$(".save-project-loader").replaceWith(errorMessage('#{escape_javascript(@error.message)}'));
......@@ -167,6 +167,10 @@ Gitlab::Application.routes.draw do
# Project Area
#
resources :projects, constraints: { id: /(?:[a-zA-Z.0-9_\-]+\/)?[a-zA-Z.0-9_\-]+/ }, except: [:new, :create, :index], path: "/" do
member do
put :transfer
end
resources :blob, only: [:show], constraints: {id: /.+/}
resources :tree, only: [:show], constraints: {id: /.+/, format: /(html|js)/ }
resources :edit_tree, only: [:show, :update], constraints: {id: /.+/}, path: 'edit'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment