From e292d7c17b48182f7f8df20d93b92e8ba9e98ce6 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 25 Mar 2013 10:48:30 +0200 Subject: [PATCH] Make transfer action in project controller --- app/contexts/projects/update_context.rb | 18 +----------------- app/controllers/projects_controller.rb | 8 ++++---- app/models/project.rb | 2 -- app/views/projects/_form.html.haml | 3 ++- app/views/projects/update_failed.js.haml | 2 -- config/routes.rb | 4 ++++ 6 files changed, 11 insertions(+), 26 deletions(-) delete mode 100644 app/views/projects/update_failed.js.haml diff --git a/app/contexts/projects/update_context.rb b/app/contexts/projects/update_context.rb index e5d09b7d..40385fa6 100644 --- a/app/contexts/projects/update_context.rb +++ b/app/contexts/projects/update_context.rb @@ -1,24 +1,8 @@ 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 diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index f2718344..5b17e1ab 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -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 diff --git a/app/models/project.rb b/app/models/project.rb index 23eb7f90..0bb1003a 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -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] diff --git a/app/views/projects/_form.html.haml b/app/views/projects/_form.html.haml index 6d547c94..01fb6a67 100644 --- a/app/views/projects/_form.html.haml +++ b/app/views/projects/_form.html.haml @@ -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 diff --git a/app/views/projects/update_failed.js.haml b/app/views/projects/update_failed.js.haml deleted file mode 100644 index a3ac5f40..00000000 --- a/app/views/projects/update_failed.js.haml +++ /dev/null @@ -1,2 +0,0 @@ -:plain - $(".save-project-loader").replaceWith(errorMessage('#{escape_javascript(@error.message)}')); diff --git a/config/routes.rb b/config/routes.rb index fafaef84..505538fc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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'