Automatic Action: change the assignee if Category change

Hi,

i noticed that there is no existing rule, letting create a new rule: if the Task category changes, then changes as well the assignee.

is it possible to “program it”? i have few php knowledge, but i may try, knowing where i have to start.

Could you please give me some hints?

Thank you

Out of the box:

  • Create an event for category change.
  • Find out where the category_id of a task changes.
  • Fire that event whenever a change occurs.
  • Create an action that is listening to your event.
  • Within that action, do whatever you want.

Sidenote: This topic might be too heavy for starting. Just my opinion.

You don’t need a new event, since there is already TaskModel::EVENT_CREATE_UPDATE

but you would need a new action, one where the hasRequiredCondition is looking for the catergory

public function hasRequiredCondition(array $data)
    {
        return $data['task']['category_id'] == $this->getParam('category_id');
    }

and then the doAction sets the new assignee.

edit:
This is the cloest action available, if the task category changes, then color changes

this would be very simple to convert into an action that does exactly what you want, in fact, here I’ll do it for you.

<?php

namespace Kanboard\Action;

use Kanboard\Model\TaskModel;

/**
 * Assign a user to a specific category
 *
 * @package Kanboard\Action
 * @author  Craig Crosby
 */
class TaskAssigneeByCategory extends Base
{
    /**
     * Get automatic action description
     *
     * @access public
     * @return string
     */
    public function getDescription()
    {
        return t('Assign automatically a tasks assignee based on a category');
    }

    /**
     * Get the list of compatible events
     *
     * @access public
     * @return array
     */
    public function getCompatibleEvents()
    {
        return array(
            TaskModel::EVENT_CREATE_UPDATE,
        );
    }

    /**
     * Get the required parameter for the action (defined by the user)
     *
     * @access public
     * @return array
     */
    public function getActionRequiredParameters()
    {
        return array(
            'user_id' => t('Assignee'),
            'category_id' => t('Category'),
        );
    }

    /**
     * Get the required parameter for the event
     *
     * @access public
     * @return string[]
     */
    public function getEventRequiredParameters()
    {
        return array(
            'task_id',
            'task' => array(
                'project_id',
                'category_id',
            ),
        );
    }

    /**
     * Execute the action (change the task color)
     *
     * @access public
     * @param  array   $data   Event data dictionary
     * @return bool            True if the action was executed or false when not executed
     */
    public function doAction(array $data)
    {
        $values = array(
            'id' => $data['task_id'],
            'owner_id' => $this->getParam('user_id'),
        );

        return $this->taskModificationModel->update($values, false);
    }

    /**
     * Check if the event data meet the action condition
     *
     * @access public
     * @param  array   $data   Event data dictionary
     * @return bool
     */
    public function hasRequiredCondition(array $data)
    {
        return $data['task']['category_id'] == $this->getParam('category_id');
    }
}

now, how you add this action is up to you, if via plugin, you will need to change the namespace.