Changed owner_relations in models group, platform, project, repository.

This commit is contained in:
George Vinogradov 2011-10-29 19:56:01 +04:00
parent 2acc098b08
commit 6f256a40eb
4 changed files with 39 additions and 22 deletions

View File

@ -54,4 +54,5 @@ class Group < ActiveRecord::Base
add_owner owner
end
end
end

View File

@ -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

View File

@ -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

View File

@ -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