BigW Consortium Gitlab

Commit 723104c4 by miks

Initial deploy_key feature commit

parent 53ce00f7
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
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 :notes, :dependent => :destroy
has_many :snippets, :dependent => :destroy
has_many :deploy_keys, :dependent => :destroy
acts_as_taggable
......
%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"
%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
- 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'))}");
%h1 Editing key
= render 'form'
= link_to 'Show', @key
\|
= link_to 'Back', project_deploy_keys_path
%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(); });
%h1 New key
= render 'form'
= link_to 'Back', project_deploy_keys_path
: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
});
.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
= 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
......
......@@ -41,6 +41,8 @@ Gitlab::Application.routes.draw do
get "graph"
end
resources :deploy_keys
resources :refs, :only => [], :path => "/" do
collection do
get "switch"
......
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)
end
name_readers = project.repository_readers
name_readers = project.repository_readers + project.deploy_keys
name_writers = project.repository_writers
repo.clean_permissions
......
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)
#
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment