Skip to content

Commit

Permalink
Update to controller variables
Browse files Browse the repository at this point in the history
  • Loading branch information
ErinClaudio committed Jul 2, 2024
1 parent dfb6d0c commit 7d72b16
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 13 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
12 changes: 0 additions & 12 deletions app/policies/checklist/task_template_policy.rb

This file was deleted.

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
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
end

namespace :checklist do
resources :task_templates
resources :task_templates # here erin
end
resources :faqs
resources :dashboard, only: [:index] do
Expand Down

0 comments on commit 7d72b16

Please sign in to comment.