Move user key manipulation in admin section to a separate controller.

This commit is contained in:
Marin Jankovski 2014-12-30 10:15:11 +01:00
parent c1e57b47b8
commit 82829ed49e
6 changed files with 41 additions and 29 deletions

View file

@ -0,0 +1,34 @@
class Admin::KeysController < Admin::ApplicationController
before_filter :user, only: [:show, :destroy]
def show
@key = user.keys.find(params[:id])
respond_to do |format|
format.html
format.js { render nothing: true }
end
end
def destroy
key = user.keys.find(params[:id])
respond_to do |format|
if key.destroy
format.html { redirect_to [:admin, user], notice: 'User key was successfully removed.' }
else
format.html { redirect_to [:admin, user], alert: 'Failed to remove user key.' }
end
end
end
protected
def user
@user ||= User.find_by!(username: params[:user_id])
end
def key_params
params.require(:user_id, :id)
end
end

View file

@ -108,27 +108,6 @@ class Admin::UsersController < Admin::ApplicationController
end
end
def show_key
@key = user.keys.find(params[:key_id])
respond_to do |format|
format.html { render 'key' }
format.js { render nothing: true }
end
end
def remove_key
key = user.keys.find(params[:key_id])
respond_to do |format|
if key.destroy
format.html { redirect_to [:admin, user], notice: 'User key was successfully removed.' }
else
format.html { redirect_to [:admin, user], alert: 'Failed to remove user key.' }
end
end
end
protected
def user

View file

@ -0,0 +1,4 @@
= render "profiles/keys/key_details"
.pull-right
= link_to 'Remove', admin_user_key_path(@user, @key), data: {confirm: 'Are you sure?'}, method: :delete, class: "btn btn-remove delete-key"

View file

@ -1,4 +0,0 @@
= render "profiles/keys/key_details"
.pull-right
= link_to 'Remove', remove_user_key_admin_user_path(@user, @key), data: {confirm: 'Are you sure?'}, method: :delete, class: "btn btn-remove delete-key"

View file

@ -232,7 +232,7 @@
- @ssh_keys.each do |key|
%tr
%td
= link_to user_key_admin_user_path(@user, key) do
= link_to admin_user_key_path(@user, key) do
%strong= key.title
%td
%span
@ -240,7 +240,7 @@
%span.cgray
added #{time_ago_with_tooltip(key.created_at)}
%td
= link_to 'Remove', remove_user_key_admin_user_path(@user, key), data: { confirm: 'Are you sure?'}, method: :delete, class: "btn btn-small btn-remove delete-key pull-right"
= link_to 'Remove', admin_user_key_path(@user, key), data: { confirm: 'Are you sure?'}, method: :delete, class: "btn btn-small btn-remove delete-key pull-right"
- else
.nothing-here-block User has no ssh keys

View file

@ -80,12 +80,11 @@ Gitlab::Application.routes.draw do
#
namespace :admin do
resources :users, constraints: { id: /[a-zA-Z.\/0-9_\-]+/ } do
resources :keys, only: [:show, :destroy]
member do
put :team_update
put :block
put :unblock
get 'key/:key_id', action: 'show_key', as: 'user_key'
delete 'key/:key_id', action: 'remove_key', as: 'remove_user_key'
delete 'remove/:email_id', action: 'remove_email', as: 'remove_email'
end
end