diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 0b63664..c265ed8 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -1,105 +1,110 @@
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
helper_method :current_user, :warden
# GET /
def index
redirect_to clients_path if current_user
end
+ # GET /faq
+ def faq
+ @faqs = Faq.order(priority: :desc).all
+ end
+
# Warden handler for authentication failure
def unauthenticated
flash[:error] = warden.message || 'There was an error with your login'
if attempted_path == '/grnet'
redirect_to admin_login_path
else
redirect_to root_path
end
end
# POST /grnet
def grnet
if current_user
warden.logout
reset_current_user
end
begin
warden.authenticate!(:admin)
rescue
return unauthenticated
end
current_user
redirect_to admin_path
end
# GET /institutional
def institutional
begin
warden.authenticate!(:institutional)
rescue
return unauthenticated
end
current_user
redirect_to clients_path
end
# POST /vima
def vima
begin
warden.authenticate!(:vima)
rescue
return unauthenticated
end
current_user
redirect_to clients_path
end
def logout
warden.logout
reset_current_user
redirect_to root_path
end
protected
def warden
request.env['warden']
end
def current_user
@current_user ||= warden.user
end
def reset_current_user
@current_user = nil
end
def fetch_logs
days_ago = params.fetch(:days_back, 7).to_i rescue 7
if @client
@logs = Log.includes(:job).joins(job: :client).where(Client: { ClientId: @client.id })
else
@logs = Log.includes(:job).joins(job: { client: { host: :users } }).
where(users: { id: current_user.id })
end
@logs = @logs.where('Time > ?', days_ago.days.ago).
order(Time: :desc, LogId: :desc).page(params[:page])
end
private
def require_logged_in
return if current_user
flash[:alert] = 'You need to log in first'
redirect_to root_path
end
def attempted_path
(request.env['warden.options'] || {})[:attempted_path]
end
end
diff --git a/app/views/application/_faq.html.erb b/app/views/application/_faq.html.erb
new file mode 100644
index 0000000..9b0d470
--- /dev/null
+++ b/app/views/application/_faq.html.erb
@@ -0,0 +1,6 @@
+<%= cache(['faq', 'v1', faq], expires_in: 1.day) do %>
+
+
<%= faq.title %>
+
<%= faq.body %>
+
+<% end %>
diff --git a/app/views/application/faq.html.erb b/app/views/application/faq.html.erb
new file mode 100644
index 0000000..401010b
--- /dev/null
+++ b/app/views/application/faq.html.erb
@@ -0,0 +1,17 @@
+
diff --git a/app/views/shared/_nav.html.erb b/app/views/shared/_nav.html.erb
index 1e24683..c71a7d3 100644
--- a/app/views/shared/_nav.html.erb
+++ b/app/views/shared/_nav.html.erb
@@ -1,40 +1,43 @@
diff --git a/config/routes.rb b/config/routes.rb
index 6c4f625..41a7982 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,105 +1,106 @@
Rails.application.routes.draw do
root 'application#index'
+ get 'faq' => 'application#faq'
post 'grnet' => 'application#grnet'
get 'institutional' => 'application#institutional'
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
get :restore
post :run_restore
post :restore_selected
delete :remove_user
end
collection do
post :index
end
end
resources :clients, only: [], param: :client_id do
member do
get :tree
end
end
resources :invitations, only: [:create]
get '/invitations/:host_id/:verification_code/accept' => 'invitations#accept',
as: :accept_invitation
resources :hosts, only: [:new, :create, :show, :edit, :update, :destroy] do
member do
post :submit_config
post :disable
delete :revoke
end
collection do
get :fetch_vima_hosts, to: 'hosts#fetch_vima_hosts', as: :fetch_vima
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, :edit, :update, :destroy]
resources :schedules, only: [:show, :new, :edit, :create, :update, :destroy]
end
namespace :admin do
match '/', to: 'base#index', via: [:get, :post]
get '/login' => 'base#login', as: :login
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
post :block
post :unblock
delete :revoke
end
end
resources :hosts, only: [] do
collection do
get :unverified
end
member do
post :verify
end
end
resources :users, only: [:index, :new, :create, :show, :edit, :update] do
member do
patch :ban
patch :unban
end
end
resources :pools, only: [:index, :new, :create]
resources :faqs
end
end