-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dfb6d0c
commit 7d72b16
Showing
4 changed files
with
82 additions
and
13 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
app/controllers/organizations/staff/checklist/task_template_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
app/policies/organizations/checklist/task_template_policy.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters