summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/deploy_keys_controller.rb42
-rw-r--r--app/models/deploy_key.rb49
-rw-r--r--app/models/project.rb1
-rw-r--r--app/views/deploy_keys/_form.html.haml16
-rw-r--r--app/views/deploy_keys/_show.html.haml7
-rw-r--r--app/views/deploy_keys/create.js.haml9
-rw-r--r--app/views/deploy_keys/edit.html.haml7
-rw-r--r--app/views/deploy_keys/index.html.haml16
-rw-r--r--app/views/deploy_keys/new.html.haml5
-rw-r--r--app/views/deploy_keys/new.js.haml11
-rw-r--r--app/views/deploy_keys/show.html.haml10
-rw-r--r--app/views/layouts/project.html.haml1
-rw-r--r--config/routes.rb2
-rw-r--r--db/migrate/20111225202855_create_deploy_keys.rb12
-rw-r--r--lib/gitlabhq/gitolite.rb2
-rw-r--r--spec/models/deploy_key_spec.rb33
16 files changed, 222 insertions, 1 deletions
diff --git a/app/controllers/deploy_keys_controller.rb b/app/controllers/deploy_keys_controller.rb
new file mode 100644
index 00000000000..ea8b4c5fcc1
--- /dev/null
+++ b/app/controllers/deploy_keys_controller.rb
@@ -0,0 +1,42 @@
+class DeployKeysController < ApplicationController
+ respond_to :js
+ layout "project"
+ before_filter :project
+ # before_filter :authorize_admin_project!
+ # before_filter :require_non_empty_project
+
+ def project
+ @project ||= Project.find_by_code(params[:project_id])
+ end
+
+ def index
+ @keys = @project.deploy_keys.all
+ end
+
+ def show
+ @key = @project.deploy_keys.find(params[:id])
+ end
+
+ def new
+ @key = @project.deploy_keys.new
+
+ respond_with(@key)
+ end
+
+ def create
+ @key = @project.deploy_keys.new(params[:key])
+ @key.save
+
+ respond_with(@key)
+ end
+
+ def destroy
+ @key = @project.deploy_keys.find(params[:id])
+ @key.destroy
+
+ respond_to do |format|
+ format.html { redirect_to deploy_keys_url }
+ format.js { render :nothing => true }
+ end
+ end
+end
diff --git a/app/models/deploy_key.rb b/app/models/deploy_key.rb
new file mode 100644
index 00000000000..cbfe211c071
--- /dev/null
+++ b/app/models/deploy_key.rb
@@ -0,0 +1,49 @@
+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 }
+
+ 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)
+ end
+ end
+
+ def repository_delete_key
+ Gitlabhq::GitHost.system.new.configure do |c|
+ c.delete_key(identifier)
+ c.update_project(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)
+#
+
+
diff --git a/app/models/project.rb b/app/models/project.rb
index 4ffb9c4c7cf..67320f6e576 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -14,6 +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
acts_as_taggable
diff --git a/app/views/deploy_keys/_form.html.haml b/app/views/deploy_keys/_form.html.haml
new file mode 100644
index 00000000000..8d38535bca9
--- /dev/null
+++ b/app/views/deploy_keys/_form.html.haml
@@ -0,0 +1,16 @@
+%div
+ = form_for [@project, @key], :remote => true do |f|
+ -if @key.errors.any?
+ %ul
+ - @key.errors.full_messages.each do |msg|
+ %li= msg
+
+ .form-row
+ = f.label :title
+ = f.text_field :title, :style => "width:300px"
+ .form-row
+ = f.label :key
+ = f.text_area :key, :style => "width:300px; height:130px"
+ .form-row
+ = f.submit 'Save', :class => "grey-button"
+
diff --git a/app/views/deploy_keys/_show.html.haml b/app/views/deploy_keys/_show.html.haml
new file mode 100644
index 00000000000..26372cf9216
--- /dev/null
+++ b/app/views/deploy_keys/_show.html.haml
@@ -0,0 +1,7 @@
+%a.update-item{:href => project_deploy_key_path(key)}
+ %span.update-title
+ = key.title
+ %span.update-author
+ Added
+ = time_ago_in_words(key.created_at)
+ ago
diff --git a/app/views/deploy_keys/create.js.haml b/app/views/deploy_keys/create.js.haml
new file mode 100644
index 00000000000..0e8757f880f
--- /dev/null
+++ b/app/views/deploy_keys/create.js.haml
@@ -0,0 +1,9 @@
+- if @key.valid?
+ :plain
+ $("#new_key_dialog").dialog("close");
+ $("#keys-table .data").append("#{escape_javascript(render(:partial => 'show', :locals => {:key => @key} ))}");
+ $("#no_ssh_key_defined").hide();
+- else
+ :plain
+ $("#new_key_dialog").empty();
+ $("#new_key_dialog").append("#{escape_javascript(render('form'))}");
diff --git a/app/views/deploy_keys/edit.html.haml b/app/views/deploy_keys/edit.html.haml
new file mode 100644
index 00000000000..9b1b9aac221
--- /dev/null
+++ b/app/views/deploy_keys/edit.html.haml
@@ -0,0 +1,7 @@
+%h1 Editing key
+
+= render 'form'
+
+= link_to 'Show', @key
+\|
+= link_to 'Back', project_deploy_keys_path
diff --git a/app/views/deploy_keys/index.html.haml b/app/views/deploy_keys/index.html.haml
new file mode 100644
index 00000000000..9cd28de90ee
--- /dev/null
+++ b/app/views/deploy_keys/index.html.haml
@@ -0,0 +1,16 @@
+%h2.icon
+ %span>
+ SSH Keys
+%div#new-key-holder.right
+ = link_to "Add new", new_project_deploy_key_path, :remote => true, :class => "grey-button"
+%br
+
+%div#keys-table{ :class => "update-data ui-box ui-box-small ui-box-big" }
+ .data
+ - @keys.each do |key|
+ = render(:partial => 'show', :locals => {:key => key})
+
+:javascript
+ $('.delete-key').live('ajax:success', function() {
+ $(this).closest('.update-item').fadeOut(); });
+
diff --git a/app/views/deploy_keys/new.html.haml b/app/views/deploy_keys/new.html.haml
new file mode 100644
index 00000000000..9be37204567
--- /dev/null
+++ b/app/views/deploy_keys/new.html.haml
@@ -0,0 +1,5 @@
+%h1 New key
+
+= render 'form'
+
+= link_to 'Back', project_deploy_keys_path
diff --git a/app/views/deploy_keys/new.js.haml b/app/views/deploy_keys/new.js.haml
new file mode 100644
index 00000000000..86e9db030c5
--- /dev/null
+++ b/app/views/deploy_keys/new.js.haml
@@ -0,0 +1,11 @@
+:plain
+ var new_key_dialog = $("<div id='new_key_dialog'></div>");
+ new_key_dialog.html("#{escape_javascript(render('form'))}");
+ $(new_key_dialog).dialog({
+ width: 350,
+ resizable: false,
+ draggable: false,
+ title: "Add new public key",
+ close: function(event, ui) { $("#new_key_dialog").remove();},
+ modal: true
+ });
diff --git a/app/views/deploy_keys/show.html.haml b/app/views/deploy_keys/show.html.haml
new file mode 100644
index 00000000000..9dcaa093ce5
--- /dev/null
+++ b/app/views/deploy_keys/show.html.haml
@@ -0,0 +1,10 @@
+.ui-box.width-100p
+ %h3= @key.title
+ .data
+ %pre= @key.key
+ .clear
+ .buttons
+ = link_to 'Remove', @key, :confirm => 'Are you sure?', :method => :delete, :class => "red-button delete-key right"
+ .clear
+
+
diff --git a/app/views/layouts/project.html.haml b/app/views/layouts/project.html.haml
index 3dbb69c4ea9..a5ea76d3698 100644
--- a/app/views/layouts/project.html.haml
+++ b/app/views/layouts/project.html.haml
@@ -49,6 +49,7 @@
- if can? current_user, :admin_project, @project
= link_to "Admin", edit_project_path(@project), :class => (current_page?(edit_project_path(@project))) ? "current" : nil
+ = link_to "Deploy keys", project_deploy_keys_path(@project), :class => (current_page?(project_deploy_keys_path(@project))) ? "current" : nil
.medium-tags{:style => 'padding: 10px 0 0 10px; width: 210px;'}= tag_list @project
diff --git a/config/routes.rb b/config/routes.rb
index 882ba00a6b2..20890b76c7c 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -41,6 +41,8 @@ Gitlab::Application.routes.draw do
get "graph"
end
+ resources :deploy_keys
+
resources :refs, :only => [], :path => "/" do
collection do
get "switch"
diff --git a/db/migrate/20111225202855_create_deploy_keys.rb b/db/migrate/20111225202855_create_deploy_keys.rb
new file mode 100644
index 00000000000..60e7337504e
--- /dev/null
+++ b/db/migrate/20111225202855_create_deploy_keys.rb
@@ -0,0 +1,12 @@
+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
diff --git a/lib/gitlabhq/gitolite.rb b/lib/gitlabhq/gitolite.rb
index 0822c25e621..930008764a6 100644
--- a/lib/gitlabhq/gitolite.rb
+++ b/lib/gitlabhq/gitolite.rb
@@ -71,7 +71,7 @@ module Gitlabhq
::Gitolite::Config::Repo.new(repo_name)
end
- name_readers = project.repository_readers
+ name_readers = project.repository_readers + project.deploy_keys
name_writers = project.repository_writers
repo.clean_permissions
diff --git a/spec/models/deploy_key_spec.rb b/spec/models/deploy_key_spec.rb
new file mode 100644
index 00000000000..c20d0030b59
--- /dev/null
+++ b/spec/models/deploy_key_spec.rb
@@ -0,0 +1,33 @@
+require 'spec_helper'
+
+describe DeployKey do
+ describe "Associations" do
+ it { should belong_to(:project) }
+ end
+
+ describe "Validation" do
+ it { should validate_presence_of(:title) }
+ it { should validate_presence_of(:key) }
+ end
+
+ describe "Methods" do
+ it { should respond_to :projects }
+ end
+
+ it { Factory.create(:key,
+ :project => Factory(:project)).should be_valid }
+end
+# == Schema Information
+#
+# Table name: deploy_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)
+#
+
+