diff --git a/app/models/group.rb b/app/models/group.rb index 703476676..18ee277e5 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -54,4 +54,5 @@ class Group < ActiveRecord::Base add_owner owner end end + end diff --git a/app/models/platform.rb b/app/models/platform.rb index 9d29f5e06..e9360220a 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -19,9 +19,9 @@ class Platform < ActiveRecord::Base validates :unixname, :uniqueness => true, :presence => true, :format => { :with => /^[a-zA-Z0-9_]+$/ }, :allow_nil => false, :allow_blank => false validates :distrib_type, :presence => true, :allow_nil => :false, :allow_blank => false, :inclusion => {:in => APP_CONFIG['distr_types']} - after_create :make_owner_rel +# after_create :make_owner_rel # before_save :create_directory - before_save :make_owner_rel + before_save :add_owner_rel # after_destroy :remove_directory before_create :xml_rpc_create before_destroy :xml_rpc_destroy @@ -113,13 +113,16 @@ class Platform < ActiveRecord::Base FileUtils.rm_rf(path) end - def make_owner_rel - unless members.include? owner or groups.include? owner - members << owner if owner.instance_of? User - groups << owner if owner.instance_of? Group + def add_owner_rel + if new_record? and owner + add_owner owner + elsif owner_id_changed? + remove_owner owner_type_was.classify.find(owner_id_was) + add_owner owner end end + def xml_rpc_create # return true result = BuildServer.add_platform unixname, APP_CONFIG['root_path'] + '/platforms' , distrib_type @@ -172,4 +175,13 @@ class Platform < ActiveRecord::Base FileUtils.rm_rf symlink_downloads_path end + def add_owner_rel + if new_record? and owner + add_owner owner + elsif owner_id_changed? + remove_owner owner_type_was.classify.find(owner_id_was) + add_owner owner + end + end + end diff --git a/app/models/project.rb b/app/models/project.rb index b2cf0b65a..f4f107aa0 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -29,7 +29,7 @@ class Project < ActiveRecord::Base scope :by_visibilities, lambda {|v| {:conditions => ['visibility in (?)', v.join(',')]}} 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 }))") } - before_create :make_owner_rel + before_save :add_owner_rel after_create :attach_to_personal_repository after_create :create_git_repo before_update :update_git_repo @@ -108,13 +108,6 @@ class Project < ActiveRecord::Base repositories << self.owner.personal_repository if !repositories.exists?(:id => self.owner.personal_repository) end - def make_owner_rel - unless groups.include? owner or collaborators.include? owner - collaborators << owner if owner.instance_of? User - groups << owner if owner.instance_of? Group - end - end - def create_git_repo with_ga do |ga| repo = ga.add_repo git_repo_name @@ -140,4 +133,13 @@ class Project < ActiveRecord::Base ga.save_and_release end end + + def add_owner_rel + if new_record? and owner + add_owner owner + elsif owner_id_changed? + remove_owner owner_type_was.classify.find(owner_id_was) + add_owner owner + end + end end diff --git a/app/models/repository.rb b/app/models/repository.rb index e0df070f0..fb7981492 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -18,7 +18,7 @@ class Repository < ActiveRecord::Base scope :recent, order("name ASC") #before_save :create_directory - before_save :make_owner_rel + before_save :add_owner_rel #after_destroy :remove_directory before_create :xml_rpc_create @@ -40,13 +40,6 @@ class Repository < ActiveRecord::Base protected - def make_owner_rel - unless members.include? owner - members << owner if owner.instance_of? User - groups << owner if owner.instance_of? Group - end - end - # def build_path(dir) # File.join(platform.path, dir) # end @@ -86,4 +79,13 @@ class Repository < ActiveRecord::Base end end + def add_owner_rel + if new_record? and owner + add_owner owner + elsif owner_id_changed? + remove_owner owner_type_was.classify.find(owner_id_was) + add_owner owner + end + end + end