Sha256: 0cc15c002954b926a126d2e9669225e2620d3e12c31b7443da797850152cc35e

Contents?: true

Size: 1.85 KB

Versions: 4

Compression:

Stored size: 1.85 KB

Contents

module ThinkFeelDoEngine
  module Manage
    # User manages task creation, destruction, and assignment for groups
    class TasksController < ApplicationController
      before_action :authenticate_user!
      before_action :set_group, only: [:index, :create]
      before_action :set_task, only: :destroy

      def index
        authorize! :update, @group
        @learning_tasks = @group.learning_tasks
      end

      def create
        @task = current_user.tasks.build(task_params)
        authorize! :create, @task
        if @task.save
          redirect_to arm_manage_tasks_group_path(@group.arm, @group),
                      notice: "Task assigned."
        else
          errors = @task.errors.full_messages.join(", ")
          flash[:alert] = "Unable to assign task: #{ errors }"
          redirect_to arm_manage_tasks_group_path(@group.arm, @group)
        end
      end

      def destroy
        authorize! :destroy, @task
        group = @task.group
        if @task.destroy
          flash.now[:success] = "Task unassigned from group."
          redirect_to arm_manage_tasks_group_path(group.arm, group)
        else
          errors = @task.errors.full_messages.join(", ")
          flash[:error] = "Unable to delete task from group: #{ errors }"
          redirect_to arm_manage_tasks_group_path(group.arm, group)
        end
      end

      private

      def build_task
        current_user
          .tasks
          .build(task_params)
      end

      def set_group
        @group = Group.find(task_params[:group_id])
      end

      def set_task
        @task = Task.find(params[:id])
      end

      def task_params
        params.require(:task).permit(
          :bit_core_content_module_id,
          :group_id,
          :is_recurring,
          :release_day,
          :termination_day,
          :has_didactic_content
        )
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
think_feel_do_engine-3.10.9 app/controllers/think_feel_do_engine/manage/tasks_controller.rb
think_feel_do_engine-3.10.8 app/controllers/think_feel_do_engine/manage/tasks_controller.rb
think_feel_do_engine-3.10.7 app/controllers/think_feel_do_engine/manage/tasks_controller.rb
think_feel_do_engine-3.10.6 app/controllers/think_feel_do_engine/manage/tasks_controller.rb