diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d981ca7..0b63664 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,104 +1,105 @@ 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 # 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/controllers/filesets_controller.rb b/app/controllers/filesets_controller.rb index 77c6c0c..6437c9d 100644 --- a/app/controllers/filesets_controller.rb +++ b/app/controllers/filesets_controller.rb @@ -1,82 +1,86 @@ class FilesetsController < ApplicationController before_action :require_logged_in before_action :fetch_host, only: [:new, :create, :show, :edit, :update] before_action :fetch_job_id, only: [:new, :create, :edit, :update] before_action :fetch_fileset, only: [:show, :edit, :update] + # GET /hosts/:host_id/filesets/new def new @fileset = @host.filesets.new @fileset.include_directions = { 'file' => [nil] } end + # GET /hosts/:host_id/filesets/:id def show @fileset = @host.filesets.find(params[:id]) respond_to do |format| format.js {} end end # GET /hosts/:host_id/filesets/:id/edit def edit @fileset.include_files = @fileset.include_directions['file'] end # PATCH /hosts/:host_id/filesets/:id/ def update if @fileset.update(fetch_params) flash[:success] = 'Fileset updated successfully' participating_hosts = @fileset.participating_hosts if participating_hosts.size.nonzero? participating_hosts.each(&:recalculate) flash[:alert] = 'You will need to redeploy the afffected clients: ' + participating_hosts.map(&:name).join(', ') end if @job_id redirect_to edit_host_job_path(@host, @job_id, fileset_id: @fileset.id) else redirect_to new_host_job_path(@host, fileset_id: @fileset.id) end else render :edit end end + # POST /hosts/:host_id/filesets def create @fileset = @host.filesets.new(fetch_params) if @fileset.save flash[:success] = 'Fileset created' if @job_id.present? redirect_to edit_host_job_path(@host, @job_id, fileset_id: @fileset.id) else redirect_to new_host_job_path(@host, fileset_id: @fileset.id) end else @fileset.include_files = nil @fileset.exclude_directions = nil render :new end end + # DELETE /hosts/:host_id/filesets/:id def destroy end private def fetch_host @host = current_user.hosts.find(params[:host_id]) end def fetch_job_id @job_id = @host.job_templates.find(params[:job_id]).id if params[:job_id].present? end def fetch_fileset @fileset = @host.filesets.find(params[:id]) end def fetch_params params.require(:fileset).permit(:name, exclude_directions: [], include_files: []) end end diff --git a/app/controllers/schedules_controller.rb b/app/controllers/schedules_controller.rb index de052ce..67fb13a 100644 --- a/app/controllers/schedules_controller.rb +++ b/app/controllers/schedules_controller.rb @@ -1,78 +1,84 @@ class SchedulesController < ApplicationController before_action :require_logged_in before_action :fetch_host, only: [:new, :create, :show, :edit, :update] before_action :fetch_job_id, only: [:new, :create, :show, :edit, :update] before_action :fetch_schedule, only: [:show, :edit, :update] + # GET /hosts/:host_id/schedules/new def new @schedule = @host.schedules.new @schedule.schedule_runs.build.default_run end + # GET /hosts/:host_id/schedules/:id def show respond_to do |format| format.js {} end end + # GET /hosts/:host_id/schedules/:id/edit def edit end + # PATCH /hosts/:host_id/schedules/:id def update if @schedule.update(fetch_params) flash[:success] = 'Schedule updated successfully' participating_hosts = @schedule.participating_hosts if participating_hosts.size.nonzero? participating_hosts.each(&:recalculate) flash[:alert] = "You will need to redeploy the afffected clients: " + participating_hosts.map(&:name).join(', ') end if @job_id redirect_to edit_host_job_path(@host, @job_id, schedule_id: @schedule.id) else redirect_to new_host_job_path(@host, schedule_id: @schedule.id) end else render :edit end end + # POST /hosts/:host_id/schedules def create @schedule = @host.schedules.new(fetch_params) @schedule.runtime = params[:schedule][:runtime] if params[:schedule][:runtime] if @schedule.save flash[:success] = 'Schedule created successfully' if @job_id.present? redirect_to edit_host_job_path(@host, @job_id, schedule_id: @schedule.id) else redirect_to new_host_job_path(@host, schedule_id: @schedule.id) end else render :new end end + # DELETE /hosts/:host_id/schedules/:id def destroy end private def fetch_schedule @schedule = @host.schedules.find(params[:id]) end def fetch_host @host = current_user.hosts.find(params[:host_id]) end def fetch_job_id @job_id = @host.job_templates.find(params[:job_id]).id if params[:job_id].present? end def fetch_params params.require(:schedule). permit(:name, { schedule_runs_attributes: [[:id, :level, :month, :day, :time, :_destroy]] }) end end