Merge branch 'deploy_keys'

Conflicts:
	app/views/layouts/project.html.haml
	db/schema.rb
This commit is contained in:
Dmitriy Zaporozhets 2012-01-14 21:26:35 +02:00
commit cbd78922ee
19 changed files with 234 additions and 8 deletions

View file

@ -1,5 +1,6 @@
class Key < ActiveRecord::Base
belongs_to :user
belongs_to :project
validates :title,
:presence => true,
@ -15,7 +16,11 @@ class Key < ActiveRecord::Base
after_destroy :repository_delete_key
def set_identifier
self.identifier = "#{user.identifier}_#{Time.now.to_i}"
if is_deploy_key
self.identifier = "deploy_#{project.code}_#{Time.now.to_i}"
else
self.identifier = "#{user.identifier}_#{Time.now.to_i}"
end
end
def update_repository
@ -31,10 +36,18 @@ class Key < ActiveRecord::Base
c.update_projects(projects)
end
end
def is_deploy_key
true if project_id
end
#projects that has this key
def projects
user.projects
if is_deploy_key
[project]
else
user.projects
end
end
end
# == Schema Information

View file

@ -14,6 +14,7 @@ class Project < ActiveRecord::Base
has_many :users, :through => :users_projects
has_many :notes, :dependent => :destroy
has_many :snippets, :dependent => :destroy
has_many :deploy_keys, :dependent => :destroy, :foreign_key => "project_id", :class_name => "Key"
has_many :web_hooks, :dependent => :destroy
acts_as_taggable
@ -199,7 +200,7 @@ class Project < ActiveRecord::Base
def repository_readers
keys = Key.joins({:user => :users_projects}).
where("users_projects.project_id = ? AND users_projects.repo_access = ?", id, Repository::REPO_R)
keys.map(&:identifier)
keys.map(&:identifier) + deploy_keys.map(&:identifier)
end
def repository_writers