diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-05-06 16:10:55 +0400 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-05-06 16:10:55 +0400 |
commit | 1882baa1aaa1c195cce55678b2b8a12e1b59db34 (patch) | |
tree | 9df49c181609531a474046aca2b205bba45e2c05 /app | |
parent | 8e4625af614b58df97d60031c2b5c72f37f1a692 (diff) |
Feature: Deploy keys between projects
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/deploy_keys_controller.rb | 26 | ||||
-rw-r--r-- | app/models/deploy_key.rb | 2 | ||||
-rw-r--r-- | app/models/key.rb | 4 | ||||
-rw-r--r-- | app/models/project.rb | 4 | ||||
-rw-r--r-- | app/models/user.rb | 2 | ||||
-rw-r--r-- | app/views/deploy_keys/_deploy_key.html.haml | 25 | ||||
-rw-r--r-- | app/views/deploy_keys/_form.html.haml | 2 | ||||
-rw-r--r-- | app/views/deploy_keys/_show.html.haml | 12 | ||||
-rw-r--r-- | app/views/deploy_keys/index.html.haml | 35 | ||||
-rw-r--r-- | app/views/deploy_keys/show.html.haml | 2 | ||||
-rw-r--r-- | app/views/refs/logs_tree.js.haml | 2 |
11 files changed, 79 insertions, 37 deletions
diff --git a/app/controllers/deploy_keys_controller.rb b/app/controllers/deploy_keys_controller.rb index a89ebbcb8d5..ca5c605aa7a 100644 --- a/app/controllers/deploy_keys_controller.rb +++ b/app/controllers/deploy_keys_controller.rb @@ -5,7 +5,8 @@ class DeployKeysController < ProjectResourceController before_filter :authorize_admin_project! def index - @keys = @project.deploy_keys.all + @enabled_keys = @project.deploy_keys.all + @available_keys = available_keys - @enabled_keys end def show @@ -19,8 +20,9 @@ class DeployKeysController < ProjectResourceController end def create - @key = @project.deploy_keys.new(params[:key]) - if @key.save + @key = DeployKey.new(params[:deploy_key]) + + if @key.valid? && @project.deploy_keys << @key redirect_to project_deploy_keys_path(@project) else render "new" @@ -36,4 +38,22 @@ class DeployKeysController < ProjectResourceController format.js { render nothing: true } end end + + def enable + project.deploy_keys << available_keys.find(params[:id]) + + redirect_to project_deploy_keys_path(@project) + end + + def disable + @project.deploy_keys_projects.where(deploy_key_id: params[:id]).last.destroy + + redirect_to project_deploy_keys_path(@project) + end + + protected + + def available_keys + @available_keys ||= DeployKey.in_projects(current_user.owned_projects) + end end diff --git a/app/models/deploy_key.rb b/app/models/deploy_key.rb index 6d9ec9a47e4..548ef4f9a27 100644 --- a/app/models/deploy_key.rb +++ b/app/models/deploy_key.rb @@ -1,4 +1,6 @@ class DeployKey < Key has_many :deploy_keys_projects, dependent: :destroy has_many :projects, through: :deploy_keys_projects + + scope :in_projects, ->(projects) { joins(:deploy_keys_projects).where('deploy_keys_projects.project_id in (?)', projects) } end diff --git a/app/models/key.rb b/app/models/key.rb index 31fb522f3ff..a72357a6d01 100644 --- a/app/models/key.rb +++ b/app/models/key.rb @@ -46,10 +46,6 @@ class Key < ActiveRecord::Base errors.add(:key, "can't be fingerprinted") if $?.exitstatus != 0 end - def is_deploy_key - project.present? - end - # projects that has this key def projects user.authorized_projects diff --git a/app/models/project.rb b/app/models/project.rb index 291316f3088..203ccb8e290 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -55,7 +55,6 @@ class Project < ActiveRecord::Base has_many :users_projects, dependent: :destroy has_many :notes, dependent: :destroy has_many :snippets, dependent: :destroy - has_many :deploy_keys, dependent: :destroy, class_name: "Key", foreign_key: "project_id" has_many :hooks, dependent: :destroy, class_name: "ProjectHook" has_many :protected_branches, dependent: :destroy has_many :user_team_project_relationships, dependent: :destroy @@ -65,6 +64,9 @@ class Project < ActiveRecord::Base has_many :user_team_user_relationships, through: :user_teams has_many :user_teams_members, through: :user_team_user_relationships + has_many :deploy_keys_projects, dependent: :destroy + has_many :deploy_keys, through: :deploy_keys_projects + delegate :name, to: :owner, allow_nil: true, prefix: true # Validations diff --git a/app/models/user.rb b/app/models/user.rb index fb2e62279a5..1d90ec3b37a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -89,7 +89,7 @@ class User < ActiveRecord::Base has_many :personal_projects, through: :namespace, source: :projects has_many :projects, through: :users_projects - has_many :own_projects, foreign_key: :creator_id + has_many :own_projects, foreign_key: :creator_id, class_name: 'Project' has_many :owned_projects, through: :namespaces, source: :projects # diff --git a/app/views/deploy_keys/_deploy_key.html.haml b/app/views/deploy_keys/_deploy_key.html.haml new file mode 100644 index 00000000000..274015cb529 --- /dev/null +++ b/app/views/deploy_keys/_deploy_key.html.haml @@ -0,0 +1,25 @@ +%li + .pull-right + - if @available_keys.include?(deploy_key) + = link_to enable_project_deploy_key_path(@project, deploy_key), class: 'btn btn-small', method: :put do + %i.icon-plus + Enable + - else + - if deploy_key.projects.count > 1 + = link_to disable_project_deploy_key_path(@project, deploy_key), class: 'btn btn-small', method: :put do + %i.icon-off + Disable + - else + = link_to 'Remove', project_deploy_key_path(@project, deploy_key), confirm: 'Are you sure?', method: :delete, class: "btn btn-remove delete-key btn-small pull-right" + + + = link_to project_deploy_key_path(@project, deploy_key) do + %i.icon-key + %strong= deploy_key.title + + %p.light.prepend-top-10 + - deploy_key.projects.map(&:name_with_namespace).each do |project_name| + %span.label= project_name + %small.pull-right + Created #{time_ago_in_words(deploy_key.created_at)} ago + diff --git a/app/views/deploy_keys/_form.html.haml b/app/views/deploy_keys/_form.html.haml index 5fb83021dc0..71bf309dd8b 100644 --- a/app/views/deploy_keys/_form.html.haml +++ b/app/views/deploy_keys/_form.html.haml @@ -18,6 +18,6 @@ = link_to "here", help_ssh_path .actions - = f.submit 'Save', class: "btn-save btn" + = f.submit 'Create', class: "btn-create btn" = link_to "Cancel", project_deploy_keys_path(@project), class: "btn btn-cancel" diff --git a/app/views/deploy_keys/_show.html.haml b/app/views/deploy_keys/_show.html.haml deleted file mode 100644 index 635054350ec..00000000000 --- a/app/views/deploy_keys/_show.html.haml +++ /dev/null @@ -1,12 +0,0 @@ -%tr - %td - %a{href: project_deploy_key_path(key.project, key)} - %strong= key.title - %td - %span.update-author - Added - = time_ago_in_words(key.created_at) - ago - %td - = link_to 'Remove', project_deploy_key_path(key.project, key), confirm: 'Are you sure?', method: :delete, class: "btn btn-remove delete-key btn-small pull-right" - diff --git a/app/views/deploy_keys/index.html.haml b/app/views/deploy_keys/index.html.haml index 8fa9d5f3bca..3e8a8730a7a 100644 --- a/app/views/deploy_keys/index.html.haml +++ b/app/views/deploy_keys/index.html.haml @@ -1,17 +1,26 @@ = render "projects/settings_nav" %p.slead - Deploy keys allow read-only access to repository. They can be used for CI, staging or production servers. A deploy key can be added to only one project. If you need to add the same key to multiple projects you can create a deploy user and add that user to multiple projects. + Deploy keys allow read-only access to repository. They can be used for CI, staging or production servers - - if can? current_user, :admin_project, @project - = link_to new_project_deploy_key_path(@project), class: "btn btn-small", title: "New Deploy Key" do - Add Deploy Key -- if @keys.any? - %table - %thead - %tr - %th Keys - %th - %th - - @keys.each do |key| - = render(partial: 'show', locals: {key: key}) +%p + You can create a deploy key or add existing one + = link_to new_project_deploy_key_path(@project), class: "btn btn-primary pull-right", title: "New Deploy Key" do + %i.icon-plus + New Deploy Key + +%hr.clearfix + +.row + .span6.enabled-keys + %h5.cgreen + Enabled deploy keys + %small for this project + %ul.bordered-list + = render @enabled_keys + .span6.available-keys + %h5 + Available deploy keys + %small from projects you are able to manage + %ul.bordered-list + = render @available_keys diff --git a/app/views/deploy_keys/show.html.haml b/app/views/deploy_keys/show.html.haml index 0a9f376d046..5b59d322343 100644 --- a/app/views/deploy_keys/show.html.haml +++ b/app/views/deploy_keys/show.html.haml @@ -12,4 +12,4 @@ %hr %pre= @key.key .pull-right - = link_to 'Remove', project_deploy_key_path(@key.project, @key), confirm: 'Are you sure?', method: :delete, class: "btn-remove btn delete-key" + = link_to 'Remove', project_deploy_key_path(@project, @key), confirm: 'Are you sure?', method: :delete, class: "btn-remove btn delete-key" diff --git a/app/views/refs/logs_tree.js.haml b/app/views/refs/logs_tree.js.haml index 23a6dae7810..0b517327139 100644 --- a/app/views/refs/logs_tree.js.haml +++ b/app/views/refs/logs_tree.js.haml @@ -1,4 +1,4 @@ -- @logs.each do |content_data| +- @logs.each do |content_data| - file_name = content_data[:file_name] - commit = content_data[:commit] |