From 33e8e490072620af49c1312540db1bc5ad871e5e Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Wed, 2 Nov 2011 16:30:47 +0400 Subject: [PATCH] Changed platform clone --- app/controllers/platforms_controller.rb | 2 +- app/models/platform.rb | 5 +++-- app/models/repository.rb | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/controllers/platforms_controller.rb b/app/controllers/platforms_controller.rb index 0873ce4c1..6f16e44f4 100644 --- a/app/controllers/platforms_controller.rb +++ b/app/controllers/platforms_controller.rb @@ -84,7 +84,7 @@ class PlatformsController < ApplicationController def clone can_perform? @platform if @platform if request.post? - cloned = @platform.clone(params[:platform]['name'], params[:platform]['unixname']) + cloned = @platform.clone(params[:platform]['name'], params[:platform]['unixname'], current_user) if cloned flash[:notice] = 'Клонирование успешно' redirect_to cloned diff --git a/app/models/platform.rb b/app/models/platform.rb index 75722b4d8..b059d0d95 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -63,13 +63,14 @@ class Platform < ActiveRecord::Base platform_type == 'personal' end - def clone(new_name, new_unixname) + def clone(new_name, new_unixname, cowner) # TODO * make it Delayed Job * p = Platform.new p.name = new_name p.unixname = new_unixname p.parent = self - p.repositories = repositories.map(&:clone) + p.owner = cowner + p.repositories = repositories.map{|r| r.clone(cowner)} result = p.save p.products = products.map do |pr| pr_cloned = Product.new diff --git a/app/models/repository.rb b/app/models/repository.rb index 8495c534a..97cf344ec 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -32,11 +32,12 @@ class Repository < ActiveRecord::Base # build_path(unixname) # end - def clone + def clone(cowner) r = Repository.new r.name = name r.unixname = unixname r.projects = projects + r.owner = cowner r.save return r end