diff --git a/app/controllers/admin/clients_controller.rb b/app/controllers/admin/clients_controller.rb
index 06b1f50..dc1b184 100644
--- a/app/controllers/admin/clients_controller.rb
+++ b/app/controllers/admin/clients_controller.rb
@@ -1,57 +1,68 @@
class Admin::ClientsController < Admin::BaseController
- before_action :fetch_client, only: [:show, :jobs, :logs, :stats, :configuration]
+ before_action :fetch_client, only: [:show, :jobs, :logs, :stats, :configuration, :disable]
before_action :fetch_logs, only: [:logs]
# Shows all available clients
#
# GET /admin/clients
def index
@clients = Client.includes(:jobs).all
@client_ids = @clients.map(&:id)
fetch_jobs_info
end
# Shows a specific client
#
# GET /admin/clients/1
def show
get_charts
end
# GET /admin/clients/1/jobs
def jobs
@jobs = @client.recent_jobs.page(params[:page])
end
# GET /admin/clients/1/logs
def logs
end
# GET /admin/clients/1/stats
# POST /admin/clients/1/stats
def stats
get_charts
end
# GET /admin/clients/1/configuration
def configuration
end
+ # POST /admin/clients/1/disable
+ def disable
+ if @client.host.disable_jobs_and_update
+ flash[:success] = 'Client disabled'
+ else
+ flash[:error] = 'Something went wrong, try again later'
+ end
+
+ redirect_to admin_client_path(@client)
+ end
+
private
# Fetches the client based on the given id
def fetch_client
@client = Client.find(params[:id])
@client_ids = [@client.id]
end
def fetch_jobs_info
@stats = JobStats.new
end
def get_charts
days_ago = params.fetch(:days_back, 7).to_i rescue 7
@job_status = ChartGenerator.job_statuses(@client_ids, days_ago)
@job_stats = ChartGenerator.job_stats(@client_ids, days_ago - 1)
end
end
diff --git a/app/views/admin/clients/show.html.erb b/app/views/admin/clients/show.html.erb
index 97d3079..98a7ae8 100644
--- a/app/views/admin/clients/show.html.erb
+++ b/app/views/admin/clients/show.html.erb
@@ -1,21 +1,30 @@
<%= render partial: 'header' %>
+
+ <% if !@client.host.inactive? %>
+ <%= link_to 'Disable client', disable_admin_client_path(@client), method: :post,
+ data: { confirm: 'This will disable the client. Are you sure?' },
+ class: "btn btn-warning", role: "button" %>
+ <% end %>
+
+
+
Client Details
Bacula Jobs
<%= render partial: 'client_details' %>
<% if @client.host %>
<%= render partial: 'jobs' %>
<% end %>
diff --git a/config/routes.rb b/config/routes.rb
index a948b20..4ef5d91 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,77 +1,78 @@
Rails.application.routes.draw do
root 'application#index'
post 'login' => 'application#login'
match 'vima', to: 'application#vima', :via => [:get, :post]
get 'logout' => 'application#logout'
resources :clients, only: [:index, :show] do
member do
get :jobs
get :logs
get :stats
post :stats
get :users
end
collection do
post :index
end
end
resources :hosts, only: [:new, :create, :show, :edit, :update, :destroy] do
member do
post :submit_config
get :restore
post :run_restore
post :disable
delete :revoke
end
resources :jobs, only: [:new, :create, :show, :edit, :update, :destroy] do
member do
patch :toggle_enable
post :backup_now
end
end
resources :filesets, only: [:show, :new, :create, :destroy]
resources :schedules, only: [:show, :new, :edit, :create, :update, :destroy]
end
namespace :admin do
match '/', to: 'base#index', via: [:get, :post]
resources :settings, only: [:index, :new, :create, :edit, :update] do
member do
delete :reset
end
end
resources :clients, only: [:index, :show] do
member do
get :jobs
get :logs
get :stats
post :stats
get :configuration
+ post :disable
end
end
resources :hosts, only: [:show] do
collection do
get :unverified
end
member do
post :verify
end
end
resources :users, only: [:index] do
member do
patch :ban
patch :unban
end
end
end
end
diff --git a/spec/routing/admin/clients_routing_spec.rb b/spec/routing/admin/clients_routing_spec.rb
new file mode 100644
index 0000000..ebe022d
--- /dev/null
+++ b/spec/routing/admin/clients_routing_spec.rb
@@ -0,0 +1,42 @@
+require 'spec_helper'
+
+describe Admin::ClientsController do
+ it 'routes GET /admin/clients' do
+ expect(get('/admin/clients')).to route_to(controller: 'admin/clients', action: 'index')
+ end
+
+ it 'routes GET /admin/clients/1' do
+ expect(get('/admin/clients/1')).
+ to route_to(controller: 'admin/clients', action: 'show', id: '1')
+ end
+
+ it 'routes GET /admin/clients/1/stats' do
+ expect(get('/admin/clients/1/stats')).
+ to route_to(controller: 'admin/clients', action: 'stats', id: '1')
+ end
+
+ it 'routes POST /admin/clients/1/stats' do
+ expect(post('/admin/clients/1/stats')).
+ to route_to(controller: 'admin/clients', action: 'stats', id: '1')
+ end
+
+ it 'routes GET /admin/clients/1/logs' do
+ expect(get('/admin/clients/1/logs')).
+ to route_to(controller: 'admin/clients', action: 'logs', id: '1')
+ end
+
+ it 'routes GET /admin/clients/1/jobs' do
+ expect(get('/admin/clients/1/jobs')).
+ to route_to(controller: 'admin/clients', action: 'jobs', id: '1')
+ end
+
+ it 'routes GET /admin/clients/1/configuration' do
+ expect(get('/admin/clients/1/configuration')).
+ to route_to(controller: 'admin/clients', action: 'configuration', id: '1')
+ end
+
+ it 'routes POST /admin/clients/1/disable' do
+ expect(post('/admin/clients/1/disable')).
+ to route_to(controller: 'admin/clients', action: 'disable', id: '1')
+ end
+end