Merge branch 'deploy_keys'
Conflicts: app/views/layouts/project.html.haml db/schema.rb
This commit is contained in:
commit
cbd78922ee
19 changed files with 234 additions and 8 deletions
44
app/controllers/deploy_keys_controller.rb
Normal file
44
app/controllers/deploy_keys_controller.rb
Normal file
|
@ -0,0 +1,44 @@
|
|||
class DeployKeysController < ApplicationController
|
||||
respond_to :js, :html
|
||||
layout "project"
|
||||
before_filter :project
|
||||
|
||||
# Authorize
|
||||
before_filter :add_project_abilities
|
||||
before_filter :authorize_admin_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 project_deploy_keys_url }
|
||||
format.js { render :nothing => true }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,5 +1,6 @@
|
|||
class Key < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
belongs_to :project
|
||||
|
||||
validates :title,
|
||||
:presence => true,
|
||||
|
@ -15,7 +16,11 @@ class Key < ActiveRecord::Base
|
|||
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
|
||||
|
@ -31,10 +36,18 @@ class Key < ActiveRecord::Base
|
|||
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
|
||||
|
|
|
@ -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, :foreign_key => "project_id", :class_name => "Key"
|
||||
has_many :web_hooks, :dependent => :destroy
|
||||
|
||||
acts_as_taggable
|
||||
|
@ -199,7 +200,7 @@ class Project < ActiveRecord::Base
|
|||
def repository_readers
|
||||
keys = Key.joins({:user => :users_projects}).
|
||||
where("users_projects.project_id = ? AND users_projects.repo_access = ?", id, Repository::REPO_R)
|
||||
keys.map(&:identifier)
|
||||
keys.map(&:identifier) + deploy_keys.map(&:identifier)
|
||||
end
|
||||
|
||||
def repository_writers
|
||||
|
|
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], :url => project_deploy_keys_path, :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.project, 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
|
11
app/views/deploy_keys/index.html.haml
Normal file
11
app/views/deploy_keys/index.html.haml
Normal file
|
@ -0,0 +1,11 @@
|
|||
= render "repositories/head"
|
||||
|
||||
%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', project_deploy_key_path(@key.project, @key), :confirm => 'Are you sure?', :method => :delete, :class => "red-button delete-key right"
|
||||
.clear
|
||||
|
||||
|
|
@ -44,5 +44,6 @@
|
|||
%span{ :class => "number" }= @project.merge_requests.opened.count
|
||||
|
||||
|
||||
|
||||
.project-content
|
||||
= yield
|
||||
|
|
|
@ -11,13 +11,18 @@
|
|||
= link_to project_hooks_path, :class => "tab #{'active' if controller.controller_name == "hooks" }" do
|
||||
%span
|
||||
Hooks
|
||||
-#= link_to "#", :class => "tab" do
|
||||
%span
|
||||
Deploy Keys
|
||||
- if can? current_user, :admin_project, @project
|
||||
= link_to project_deploy_keys_path(@project), :class => "tab #{'active' if controller.controller_name == "deploy_keys"}" do
|
||||
%span
|
||||
Deploy Keys
|
||||
|
||||
- if current_page?(project_hooks_path(@project))
|
||||
- if can? current_user, :admin_project, @project
|
||||
= link_to new_project_hook_path(@project), :class => "add_new", :title => "New Web Hook" do
|
||||
= image_tag "add_new.png", :width => 14
|
||||
|
||||
- if current_page?(project_deploy_keys_path(@project))
|
||||
- if can? current_user, :admin_project, @project
|
||||
= link_to new_project_deploy_key_path(@project), :class => "add_new", :title => "New Deploy Key", :remote => true do
|
||||
= image_tag "add_new.png", :width => 14
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue