diff --git a/app/models/deploy_key.rb b/app/models/deploy_key.rb new file mode 100644 index 0000000000000000000000000000000000000000..6d9ec9a47e48c4c7b288de8a272c41cacdeaf501 --- /dev/null +++ b/app/models/deploy_key.rb @@ -0,0 +1,4 @@ +class DeployKey < Key + has_many :deploy_keys_projects, dependent: :destroy + has_many :projects, through: :deploy_keys_projects +end diff --git a/app/models/deploy_keys_project.rb b/app/models/deploy_keys_project.rb new file mode 100644 index 0000000000000000000000000000000000000000..48350a3e4d9656d04f7d73b06c9fef348f043304 --- /dev/null +++ b/app/models/deploy_keys_project.rb @@ -0,0 +1,11 @@ +class DeployKeysProject < ActiveRecord::Base + attr_accessible :key_id, :project_id + + belongs_to :project + belongs_to :deploy_key + + validates :deploy_key_id, presence: true + validates :deploy_key_id, uniqueness: { scope: [:project_id], message: "already exists in project" } + + validates :project_id, presence: true +end diff --git a/app/models/key.rb b/app/models/key.rb index ce62b802c0d99637c98db500f0d84762743e132b..31fb522f3ff6a50fcbffba79d741ff8195b88130 100644 --- a/app/models/key.rb +++ b/app/models/key.rb @@ -16,7 +16,6 @@ require 'digest/md5' class Key < ActiveRecord::Base belongs_to :user - belongs_to :project attr_accessible :key, :title @@ -29,7 +28,7 @@ class Key < ActiveRecord::Base delegate :name, :email, to: :user, prefix: true def strip_white_space - self.key = self.key.strip unless self.key.blank? + self.key = key.strip unless key.blank? end def fingerprintable_key @@ -53,14 +52,10 @@ class Key < ActiveRecord::Base # projects that has this key def projects - if is_deploy_key - [project] - else - user.authorized_projects - end + user.authorized_projects end def shell_id - "key-#{self.id}" + "key-#{id}" end end