Commit 82829ed4 authored by Marin Jankovski's avatar Marin Jankovski
Browse files

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

parent c1e57b47
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
......@@ -108,27 +108,6 @@ def remove_email
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
......
= 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"
= 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"
......@@ -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
......@@ -80,12 +80,11 @@
#
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
......
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