Initial deploy_key feature commit
This commit is contained in:
parent
53ce00f74a
commit
723104c45f
42
app/controllers/deploy_keys_controller.rb
Normal file
42
app/controllers/deploy_keys_controller.rb
Normal file
|
@ -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
|
49
app/models/deploy_key.rb
Normal file
49
app/models/deploy_key.rb
Normal file
|
@ -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)
|
||||||
|
#
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ class Project < ActiveRecord::Base
|
||||||
has_many :users, :through => :users_projects
|
has_many :users, :through => :users_projects
|
||||||
has_many :notes, :dependent => :destroy
|
has_many :notes, :dependent => :destroy
|
||||||
has_many :snippets, :dependent => :destroy
|
has_many :snippets, :dependent => :destroy
|
||||||
|
has_many :deploy_keys, :dependent => :destroy
|
||||||
|
|
||||||
acts_as_taggable
|
acts_as_taggable
|
||||||
|
|
||||||
|
|
16
app/views/deploy_keys/_form.html.haml
Normal file
16
app/views/deploy_keys/_form.html.haml
Normal file
|
@ -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"
|
||||||
|
|
7
app/views/deploy_keys/_show.html.haml
Normal file
7
app/views/deploy_keys/_show.html.haml
Normal file
|
@ -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
|
9
app/views/deploy_keys/create.js.haml
Normal file
9
app/views/deploy_keys/create.js.haml
Normal file
|
@ -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'))}");
|
7
app/views/deploy_keys/edit.html.haml
Normal file
7
app/views/deploy_keys/edit.html.haml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
%h1 Editing key
|
||||||
|
|
||||||
|
= render 'form'
|
||||||
|
|
||||||
|
= link_to 'Show', @key
|
||||||
|
\|
|
||||||
|
= link_to 'Back', project_deploy_keys_path
|
16
app/views/deploy_keys/index.html.haml
Normal file
16
app/views/deploy_keys/index.html.haml
Normal file
|
@ -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(); });
|
||||||
|
|
5
app/views/deploy_keys/new.html.haml
Normal file
5
app/views/deploy_keys/new.html.haml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
%h1 New key
|
||||||
|
|
||||||
|
= render 'form'
|
||||||
|
|
||||||
|
= link_to 'Back', project_deploy_keys_path
|
11
app/views/deploy_keys/new.js.haml
Normal file
11
app/views/deploy_keys/new.js.haml
Normal file
|
@ -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
|
||||||
|
});
|
10
app/views/deploy_keys/show.html.haml
Normal file
10
app/views/deploy_keys/show.html.haml
Normal file
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,7 @@
|
||||||
|
|
||||||
- if can? current_user, :admin_project, @project
|
- 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 "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
|
.medium-tags{:style => 'padding: 10px 0 0 10px; width: 210px;'}= tag_list @project
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,8 @@ Gitlab::Application.routes.draw do
|
||||||
get "graph"
|
get "graph"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
resources :deploy_keys
|
||||||
|
|
||||||
resources :refs, :only => [], :path => "/" do
|
resources :refs, :only => [], :path => "/" do
|
||||||
collection do
|
collection do
|
||||||
get "switch"
|
get "switch"
|
||||||
|
|
12
db/migrate/20111225202855_create_deploy_keys.rb
Normal file
12
db/migrate/20111225202855_create_deploy_keys.rb
Normal file
|
@ -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
|
|
@ -71,7 +71,7 @@ module Gitlabhq
|
||||||
::Gitolite::Config::Repo.new(repo_name)
|
::Gitolite::Config::Repo.new(repo_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
name_readers = project.repository_readers
|
name_readers = project.repository_readers + project.deploy_keys
|
||||||
name_writers = project.repository_writers
|
name_writers = project.repository_writers
|
||||||
|
|
||||||
repo.clean_permissions
|
repo.clean_permissions
|
||||||
|
|
33
spec/models/deploy_key_spec.rb
Normal file
33
spec/models/deploy_key_spec.rb
Normal file
|
@ -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)
|
||||||
|
#
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue