diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-05-06 13:26:36 +0400 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-05-06 13:26:36 +0400 |
commit | 543d86f351780ebfd9bdd945e6cc247da4919602 (patch) | |
tree | 2327dcbd43fe84813c50dcc581e14ccb0b38223c /app | |
parent | 53413f128d049a7f45e4b3daf3dd0c3408a777e9 (diff) |
Create DeployKey & DeployKeysProject models. Bulding many to many relation between deploy keys and projects
Diffstat (limited to 'app')
-rw-r--r-- | app/models/deploy_key.rb | 4 | ||||
-rw-r--r-- | app/models/deploy_keys_project.rb | 11 | ||||
-rw-r--r-- | app/models/key.rb | 11 |
3 files changed, 18 insertions, 8 deletions
diff --git a/app/models/deploy_key.rb b/app/models/deploy_key.rb new file mode 100644 index 00000000000..6d9ec9a47e4 --- /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 00000000000..48350a3e4d9 --- /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 ce62b802c0d..31fb522f3ff 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 |