Skip to content

Commit

Permalink
Update Controller and routing changes
Browse files Browse the repository at this point in the history
* add: authenticate_user! as a before action in application controller instead of calling it within multiple controllers

* add: skip_before_action authenticate_user! for controllers that don't need user authentication

* remove: commented out 'skip_before_action' from controllers

* fix failing tests: after adding authentication

* add: config for devise
configuration for setting up custom failures through warden in the devise.rb

* add custom failure file

* update: failure app

 Co-authored-by: Paul DobbinSchmaltz <[email protected]>

* add more context to why this authentication failure app is needed.

* update: rails standard fix
  • Loading branch information
ErinClaudio committed Jul 2, 2024
1 parent feb4cb1 commit 46cf248
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 88 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
module Organizations
module Staff
module Checklist
class TaskTemplatesController < Organizations::BaseController
before_action :context_authorize!, only: %i[index new create]
before_action :set_task, only: %i[edit update destroy]

layout "dashboard"

def index
@task_templates = authorized_scope(TaskTemplate.all)
end

def new
@task_template = TaskTemplate.new
end

def create
@task_template = TaskTemplate.new(task_params)

if @task_template
redirect_to staff_task_templates_path, notice: t(".success")
else
flash.now[:alert] = t(".error")
render :new, status: :unprocessable_entity
end
end

def edit
end

def update
if @task_template.update(task_params)
redirect_to staff_task_templates_path, notice: t(".success")
else
render :edit, status: :unprocessable_entity
end
end

def destroy
@task_template.destroy

redirect_to staff_task_templates_path, notice: t(".success")
end

private

def task_params
params.require(:task_template).permit(:name, :description, :due_in_days, :recurring)
end

def set_task
@task_template = TaskTemplate.find(params[:id])

authorize! @task_template
rescue ActiveRecord::RecordNotFound
redirect_to staff_task_templates_path, alert: t(".error")
end

def context_authorize!
authorize! TaskTemplate,
context: {organization: Current.organization}
end
end
end
end
end

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# == Schema Information
#
# Table name: default_pet_tasks
# Table name: task_templates
#
# id :bigint not null, primary key
# description :string
Expand All @@ -13,13 +13,13 @@
#
# Indexes
#
# index_default_pet_tasks_on_organization_id (organization_id)
# index_task_templates_on_organization_id (organization_id)
#
# Foreign Keys
#
# fk_rails_... (organization_id => organizations.id)
#
class DefaultPetTask < ApplicationRecord
class TaskTemplate < ApplicationRecord
acts_as_tenant(:organization)

validates :name, presence: true
Expand Down
14 changes: 14 additions & 0 deletions app/policies/organizations/checklist/task_template_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Organizations
module Checklist
class TaskTemplatePolicy < ApplicationPolicy
pre_check :verify_organization!
pre_check :verify_active_staff!

alias_rule :new?, :create?, :index?, to: :manage?

def manage?
permission?(:manage_task_templates)
end
end
end
end
10 changes: 0 additions & 10 deletions app/policies/organizations/default_pet_task_policy.rb

This file was deleted.

4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
post "attach_files", on: :member, to: "pets#attach_files"
end

resources :default_pet_tasks
namespace :checklist do
resources :task_templates # here erin
end
resources :faqs
resources :dashboard, only: [:index] do
collection do
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RenameDefaultPetTasksToTaskTemplates < ActiveRecord::Migration[7.1]
def change
rename_table :default_pet_tasks, :task_templates
end
end
26 changes: 13 additions & 13 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 46cf248

Please sign in to comment.