From b48e4af930aaf2202b5b1944e5bc9af9308b7e18 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Mon, 31 Oct 2011 05:02:12 +0400 Subject: [PATCH] Fixed owner links in projects & groups --- app/models/group.rb | 15 ++++++++++++++- app/models/project.rb | 17 ++++++++++++++++- app/models/repository.rb | 1 + 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/app/models/group.rb b/app/models/group.rb index 18ee277e5..f3f209ae4 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -28,7 +28,9 @@ class Group < ActiveRecord::Base include PersonalRepository before_create :add_default_role - before_save :add_owner_rel + #before_save :add_owner_rel + after_create :make_owner_rel + before_save :check_owner_rel def roles_of(user) objects.where(:object_id => user.id, :object_type => user.class).map {|rel| rel.role}.reject {|r| r.nil?} @@ -55,4 +57,15 @@ class Group < ActiveRecord::Base end end + def make_owner_rel + add_owner owner + end + + def check_owner_rel + if !new_record? and owner_id_changed? + remove_owner owner_type_was.classify.find(owner_id_was) if owner_type_was + add_owner owner if owner + end + end + end diff --git a/app/models/project.rb b/app/models/project.rb index 3d3b95739..925dbeea8 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -31,7 +31,10 @@ class Project < ActiveRecord::Base scope :addable_to_repository, lambda { |repository_id| where("projects.id NOT IN (SELECT project_to_repositories.project_id FROM project_to_repositories WHERE (project_to_repositories.repository_id != #{ repository_id }))") } scope :automateable, where("projects.id NOT IN (SELECT auto_build_lists.project_id FROM auto_build_lists)") - before_save :add_owner_rel + # before_save :add_owner_rel + after_create :make_owner_rel + before_save :check_owner_rel + after_create :attach_to_personal_repository after_create :create_git_repo before_update :update_git_repo @@ -153,4 +156,16 @@ class Project < ActiveRecord::Base add_owner owner end end + + def make_owner_rel + add_owner owner + end + + def check_owner_rel + if !new_record? and owner_id_changed? + remove_owner owner_type_was.classify.find(owner_id_was) if owner_type_was + add_owner owner if owner + end + end + end diff --git a/app/models/repository.rb b/app/models/repository.rb index 61717fd28..54442b09f 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -22,6 +22,7 @@ class Repository < ActiveRecord::Base #before_save :create_directory #before_save :add_owner_rel #after_destroy :remove_directory + before_create :xml_rpc_create before_destroy :xml_rpc_destroy