Commit 543d86f3 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Create DeployKey & DeployKeysProject models. Bulding many to many relation...

Create DeployKey & DeployKeysProject models. Bulding many to many relation between deploy keys and projects
parent 53413f12
class DeployKey < Key
has_many :deploy_keys_projects, dependent: :destroy
has_many :projects, through: :deploy_keys_projects
end
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
......@@ -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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment