Permalink
Browse files

DeployKey moved to Key model

  • Loading branch information...
1 parent 5b4382e commit 99b8b577e92831d9cfe4f98fca4c6b8017c95a7a @miks miks committed Dec 31, 2011
@@ -12,28 +12,28 @@ def project
end
def index
- @keys = @project.deploy_keys.all
+ @keys = @project.keys.all
end
def show
- @key = @project.deploy_keys.find(params[:id])
+ @key = @project.keys.find(params[:id])
end
def new
- @key = @project.deploy_keys.new
+ @key = @project.keys.new
respond_with(@key)
end
def create
- @key = @project.deploy_keys.new(params[:deploy_key])
+ @key = @project.keys.new(params[:key])
@key.save
respond_with(@key)
end
def destroy
- @key = @project.deploy_keys.find(params[:id])
+ @key = @project.keys.find(params[:id])
@key.destroy
respond_to do |format|
View
@@ -1,53 +0,0 @@
-require 'unique_public_key_validator'
-
-class DeployKey < ActiveRecord::Base
- belongs_to :project
-
- validates :title,
- :presence => true,
- :length => { :within => 0..255 }
-
- validates :key,
- :presence => true,
- :uniqueness => true,
- :length => { :within => 0..5000 }
-
- validates_with UniquePublicKeyValidator
-
- before_save :set_identifier
- after_save :update_repository
- after_destroy :repository_delete_key
-
- def set_identifier
- self.identifier = "deploy_#{project.code}_#{Time.now.to_i}"
- end
-
- def update_repository
- Gitlabhq::GitHost.system.new.configure do |c|
- c.update_keys(identifier, key)
- c.update_project(project.path, project)
- end
- end
-
- def repository_delete_key
- Gitlabhq::GitHost.system.new.configure do |c|
- c.delete_key(identifier)
- c.update_project(project.path, project)
- end
- end
-
-end
-# == Schema Information
-#
-# Table name: keys
-#
-# id :integer not null, primary key
-# project_id :integer not null
-# created_at :datetime
-# updated_at :datetime
-# key :text
-# title :string(255)
-# identifier :string(255)
-#
-
-
View
@@ -1,7 +1,6 @@
-require 'unique_public_key_validator'
-
class Key < ActiveRecord::Base
belongs_to :user
+ belongs_to :project
validates :title,
:presence => true,
@@ -12,14 +11,16 @@ class Key < ActiveRecord::Base
:uniqueness => true,
:length => { :within => 0..5000 }
- validates_with UniquePublicKeyValidator
-
before_save :set_identifier
after_save :update_repository
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
@@ -35,10 +36,18 @@ def repository_delete_key
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
@@ -14,7 +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
+ has_many :keys, :dependent => :destroy
has_many :web_hooks, :dependent => :destroy
acts_as_taggable
@@ -189,15 +189,15 @@ def reset_access(user)
end
def repository_readers
- keys = Key.joins({:user => :users_projects}).
+ read_keys = Key.joins({:user => :users_projects}).
where("users_projects.project_id = ? AND users_projects.repo_access = ?", id, Repository::REPO_R)
- keys.map(&:identifier) + deploy_keys.map(&:identifier)
+ read_keys.map(&:identifier) + keys.map(&:identifier)
end
def repository_writers
- keys = Key.joins({:user => :users_projects}).
+ write_keys = Key.joins({:user => :users_projects}).
where("users_projects.project_id = ? AND users_projects.repo_access = ?", id, Repository::REPO_RW)
- keys.map(&:identifier)
+ write_keys.map(&:identifier)
end
def readers
@@ -1,5 +1,5 @@
%div
- = form_for [@project, @key], :remote => true do |f|
+ = form_for [@project, @key], :url => project_deploy_keys_path, :remote => true do |f|
-if @key.errors.any?
%ul
- @key.errors.full_messages.each do |msg|
@@ -1,12 +0,0 @@
-class CreateDeployKeys < ActiveRecord::Migration
- def change
- create_table :deploy_keys do |t|
- t.integer "project_id", :null => false
- t.datetime "created_at"
- t.datetime "updated_at"
- t.text "key"
- t.string "title"
- t.string "identifier"
- end
- end
-end
@@ -0,0 +1,6 @@
+class AddProjectIdToKey < ActiveRecord::Migration
+ def change
+ add_column :keys, :project_id, :integer, :null => true
+ change_column :keys, :user_id, :integer, :null => true
+ end
+end
View
@@ -11,16 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20111225202855) do
-
- create_table "deploy_keys", :force => true do |t|
- t.integer "project_id", :null => false
- t.datetime "created_at"
- t.datetime "updated_at"
- t.text "key"
- t.string "title"
- t.string "identifier"
- end
+ActiveRecord::Schema.define(:version => 20111231111825) do
create_table "issues", :force => true do |t|
t.string "title"
@@ -36,12 +27,13 @@
end
create_table "keys", :force => true do |t|
- t.integer "user_id", :null => false
+ t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
t.text "key"
t.string "title"
t.string "identifier"
+ t.integer "project_id"
end
create_table "merge_requests", :force => true do |t|

0 comments on commit 99b8b57

Please sign in to comment.