Commit 543d86f351780ebfd9bdd945e6cc247da4919602
1 parent
53413f12
Exists in
master
and in
4 other branches
Create DeployKey & DeployKeysProject models. Bulding many to many relation betwe…
…en deploy keys and projects
Showing
3 changed files
with
18 additions
and
8 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | +class DeployKeysProject < ActiveRecord::Base | |
| 2 | + attr_accessible :key_id, :project_id | |
| 3 | + | |
| 4 | + belongs_to :project | |
| 5 | + belongs_to :deploy_key | |
| 6 | + | |
| 7 | + validates :deploy_key_id, presence: true | |
| 8 | + validates :deploy_key_id, uniqueness: { scope: [:project_id], message: "already exists in project" } | |
| 9 | + | |
| 10 | + validates :project_id, presence: true | |
| 11 | +end | ... | ... |
app/models/key.rb
| ... | ... | @@ -16,7 +16,6 @@ require 'digest/md5' |
| 16 | 16 | |
| 17 | 17 | class Key < ActiveRecord::Base |
| 18 | 18 | belongs_to :user |
| 19 | - belongs_to :project | |
| 20 | 19 | |
| 21 | 20 | attr_accessible :key, :title |
| 22 | 21 | |
| ... | ... | @@ -29,7 +28,7 @@ class Key < ActiveRecord::Base |
| 29 | 28 | delegate :name, :email, to: :user, prefix: true |
| 30 | 29 | |
| 31 | 30 | def strip_white_space |
| 32 | - self.key = self.key.strip unless self.key.blank? | |
| 31 | + self.key = key.strip unless key.blank? | |
| 33 | 32 | end |
| 34 | 33 | |
| 35 | 34 | def fingerprintable_key |
| ... | ... | @@ -53,14 +52,10 @@ class Key < ActiveRecord::Base |
| 53 | 52 | |
| 54 | 53 | # projects that has this key |
| 55 | 54 | def projects |
| 56 | - if is_deploy_key | |
| 57 | - [project] | |
| 58 | - else | |
| 59 | - user.authorized_projects | |
| 60 | - end | |
| 55 | + user.authorized_projects | |
| 61 | 56 | end |
| 62 | 57 | |
| 63 | 58 | def shell_id |
| 64 | - "key-#{self.id}" | |
| 59 | + "key-#{id}" | |
| 65 | 60 | end |
| 66 | 61 | end | ... | ... |