Prevent people to remove columns that contains tasks

This commit is contained in:
Frederic Guillot 2017-02-08 18:36:13 -05:00
parent d3650eaa25
commit 73dce12797
33 changed files with 80 additions and 35 deletions

View File

@ -3,6 +3,7 @@ Version 1.0.39 (unreleased)
Improvements:
* Prevent people to remove columns that contains tasks
* Improve LDAP error reporting
* Add configuration parameter to disable email configuration from user interface
* Add email address field for projects

View File

@ -4,6 +4,7 @@ namespace Kanboard\Api\Procedure;
use Kanboard\Api\Authorization\ColumnAuthorization;
use Kanboard\Api\Authorization\ProjectAuthorization;
use Kanboard\Model\TaskModel;
/**
* Column API controller
@ -40,6 +41,15 @@ class ColumnProcedure extends BaseProcedure
public function removeColumn($column_id)
{
ColumnAuthorization::getInstance($this->container)->check($this->getClassName(), 'removeColumn', $column_id);
$projectId = $this->columnModel->getProjectId($column_id);
$nbTasks = $this->taskFinderModel->countByColumnId($projectId, $column_id, array(TaskModel::STATUS_OPEN, TaskModel::STATUS_CLOSED));
if ($nbTasks > 0) {
$this->logger->error(__METHOD__.': This column cannot be removed because it contains '.$nbTasks.' tasks');
return false;
}
return $this->columnModel->remove($column_id);
}

View File

@ -20,7 +20,7 @@ class ColumnController extends BaseController
public function index()
{
$project = $this->getProject();
$columns = $this->columnModel->getAll($project['id']);
$columns = $this->columnModel->getAllWithTasksCount($project['id']);
$this->response->html($this->helper->layout->project('column/index', array(
'columns' => $columns,

View File

@ -73,7 +73,6 @@ return array(
'Remove a column' => 'Ukloni kolonu',
'Unable to remove this column.' => 'Nemoguće uklanjanje kolone.',
'Do you really want to remove this column: "%s"?' => 'Da li zaista želiš da ukoniš ovu kolonu: "%s"?',
'This action will REMOVE ALL TASKS associated to this column!' => 'Ova akcija BRIŠE SVE ZADATKE vezane za ovu kolonu!',
'Settings' => 'Podešavanja',
'Application settings' => 'Podešavanja aplikacije',
'Language' => 'Jezik',

View File

@ -73,7 +73,6 @@ return array(
'Remove a column' => 'Vyjmout sloupec',
'Unable to remove this column.' => 'Tento sloupec nelze odstranit',
'Do you really want to remove this column: "%s"?' => 'Opravdu chcete vyjmout tento sloupec: "%s"?',
'This action will REMOVE ALL TASKS associated to this column!' => 'Tato akce vyjme všechny úkoly přiřazený k tomuto sloupci!',
'Settings' => 'Nastavení',
'Application settings' => 'Nastavení aplikace',
'Language' => 'Čeština',

View File

@ -73,7 +73,6 @@ return array(
'Remove a column' => 'Fjern en kolonne',
'Unable to remove this column.' => 'Ikke muligt at fjerne denne kolonne',
'Do you really want to remove this column: "%s"?' => 'Vil du virkelig fjerne denne kolonne: "%s"?',
'This action will REMOVE ALL TASKS associated to this column!' => 'Denne handling vil SLETTE ALLE OPGAVER tilknyttet denne kolonne',
'Settings' => 'Indstillinger',
'Application settings' => 'Applikationsindstillinger',
'Language' => 'Sprog',

View File

@ -73,7 +73,6 @@ return array(
'Remove a column' => 'Spalte löschen',
'Unable to remove this column.' => 'Löschen dieser Spalte nicht möglich.',
'Do you really want to remove this column: "%s"?' => 'Soll diese Spalte wirklich gelöscht werden: "%s"?',
'This action will REMOVE ALL TASKS associated to this column!' => 'ALLE AUFGABEN dieser Spalte werden GELÖSCHT!',
'Settings' => 'Einstellungen',
'Application settings' => 'Anwendungskonfiguration',
'Language' => 'Sprache',

View File

@ -73,7 +73,6 @@ return array(
'Remove a column' => 'Αφαίρεση στήλης',
'Unable to remove this column.' => 'Αδύνατη η αφαίρεση της στήλης',
'Do you really want to remove this column: "%s"?' => 'Θέλετε να αφαιρέσετε τη στήλη: « %s » ?',
'This action will REMOVE ALL TASKS associated to this column!' => 'Αυτή η ενέργεια θα ΑΦΑΙΡΕΣΕΙ ΟΛΕΣ ΤΙΣ ΕΡΓΑΣΙΕΣ που είναι σχετικές με τη στήλη!!',
'Settings' => 'Προτιμήσεις',
'Application settings' => 'Παραμετροποίηση εφαρμογής',
'Language' => 'Γλώσσα',

View File

@ -73,7 +73,6 @@ return array(
'Remove a column' => 'Eliminar esta columna',
'Unable to remove this column.' => 'No se puede eliminar esta columna.',
'Do you really want to remove this column: "%s"?' => '¿De vedad que desea eliminar esta columna: «%s»?',
'This action will REMOVE ALL TASKS associated to this column!' => '¡Esta acción ELIMINARÁ TODAS LAS TAREAS asociadas a esta columna!',
'Settings' => 'Preferencias',
'Application settings' => 'Preferencias de la aplicación',
'Language' => 'Idioma',

View File

@ -73,7 +73,6 @@ return array(
'Remove a column' => 'Poista sarake',
'Unable to remove this column.' => 'Sarakkeen poistaminen ei onnistunut.',
'Do you really want to remove this column: "%s"?' => 'Haluatko varmasti poistaa sarakkeen "%s"?',
'This action will REMOVE ALL TASKS associated to this column!' => 'Tämä toiminto POISTAA KAIKKI TEHTÄVÄT tästä sarakkeesta!',
'Settings' => 'Asetukset',
'Application settings' => 'Ohjelman asetukset',
'Language' => 'Kieli',

View File

@ -73,7 +73,6 @@ return array(
'Remove a column' => 'Supprimer une colonne',
'Unable to remove this column.' => 'Impossible de supprimer cette colonne.',
'Do you really want to remove this column: "%s"?' => 'Voulez vraiment supprimer cette colonne : « %s » ?',
'This action will REMOVE ALL TASKS associated to this column!' => 'Cette action va supprimer toutes les tâches associées à cette colonne !',
'Settings' => 'Préférences',
'Application settings' => 'Paramètres de l\'application',
'Language' => 'Langue',

View File

@ -73,7 +73,6 @@ return array(
'Remove a column' => 'Oszlop törlése',
'Unable to remove this column.' => 'Az oszlop törlése nem lehetséges.',
'Do you really want to remove this column: "%s"?' => 'Valóban törölni akarja ezt az oszlopot: "%s"?',
'This action will REMOVE ALL TASKS associated to this column!' => 'Az oszlophoz rendelt ÖSSZES FELADAT TÖRLŐDNI FOG!',
'Settings' => 'Beállítások',
'Application settings' => 'Alkalmazás beállítások',
'Language' => 'Nyelv',

View File

@ -73,7 +73,6 @@ return array(
'Remove a column' => 'Hapus kolom',
'Unable to remove this column.' => 'Tidak dapat menghapus kolom ini.',
'Do you really want to remove this column: "%s"?' => 'Apakah Anda yakin mau menghapus kolom ini: "%s"?',
'This action will REMOVE ALL TASKS associated to this column!' => 'Tindakan ini akan MENGHAPUS SEMUA TUGAS yang berkaitan dengan kolom ini!',
'Settings' => 'Pengaturan',
'Application settings' => 'Pengaturan aplikasi',
'Language' => 'Bahasa',

View File

@ -73,7 +73,6 @@ return array(
'Remove a column' => 'Cancella questa colonna',
'Unable to remove this column.' => 'Impossibile cancellare questa colonna.',
'Do you really want to remove this column: "%s"?' => 'Desideri davvero cancellare questa colonna: "%s" ?',
'This action will REMOVE ALL TASKS associated to this column!' => 'Questa azione cancellerà TUTTI I TASK legati a questa colonna!',
'Settings' => 'Impostazioni',
'Application settings' => 'Impostazioni dell\'applicazione',
'Language' => 'Lingua',

View File

@ -73,7 +73,6 @@ return array(
'Remove a column' => 'カラムの削除',
'Unable to remove this column.' => 'カラムを削除できませんでした。',
'Do you really want to remove this column: "%s"?' => 'カラム「%s」を削除しますか',
'This action will REMOVE ALL TASKS associated to this column!' => 'この操作はこのカラムに割当てられた『全てのタスクを削除』します!',
'Settings' => '設定',
'Application settings' => 'アプリケーションの設定',
'Language' => '言語',

View File

@ -73,7 +73,6 @@ return array(
'Remove a column' => '컬럼 삭제',
'Unable to remove this column.' => '(※)컬럼을 삭제할 수 없었습니다.',
'Do you really want to remove this column: "%s"?' => '컬럼을 삭제하시겠습니까: "%s"?',
'This action will REMOVE ALL TASKS associated to this column!' => '이 조작은 이 컬럼에 할당된 『 모든 할일을 삭제 』합니다!',
'Settings' => '설정',
'Application settings' => '애플리케이션의 설정',
'Language' => '언어',

View File

@ -73,7 +73,6 @@ return array(
'Remove a column' => 'Hapus kolom',
'Unable to remove this column.' => 'Tidak dapat menghapus kolom ini.',
'Do you really want to remove this column: "%s"?' => 'Apakah anda yakin akan menghapus kolom ini : « %s » ?',
'This action will REMOVE ALL TASKS associated to this column!' => 'tindakan ini akan MENGHAPUS SEMUA TUGAS yang terkait dengan kolom ini!',
'Settings' => 'Penetapan',
'Application settings' => 'Penetapan aplikasi',
'Language' => 'Bahasa',

View File

@ -73,7 +73,6 @@ return array(
'Remove a column' => 'Fjern en kolonne',
'Unable to remove this column.' => 'Ikke mulig ø fjerne denne kolonnen',
'Do you really want to remove this column: "%s"?' => 'Vil du fjerne denne kolonnen: "%s"?',
'This action will REMOVE ALL TASKS associated to this column!' => 'Denne handlingen vil SLETTE ALLE OPPGAVER tilknyttet denne kolonnen',
'Settings' => 'Innstillinger',
'Application settings' => 'Applikasjonsinnstillinger',
'Language' => 'Språk',

View File

@ -73,7 +73,6 @@ return array(
'Remove a column' => 'Kolom verwijderen',
'Unable to remove this column.' => 'Verwijderen van deze kolom niet mogelijk.',
'Do you really want to remove this column: "%s"?' => 'Weet u zeker dat u deze kolom wil verwijderen : « %s » ?',
'This action will REMOVE ALL TASKS associated to this column!' => 'Deze actie zal ALLE TAKEN VERWIJDEREN die zijn geassocieerd met deze kolom!',
'Settings' => 'Instellingen',
'Application settings' => 'Applicatie instellingen',
'Language' => 'Taal',

View File

@ -73,7 +73,6 @@ return array(
'Remove a column' => 'Usuń kolumnę',
'Unable to remove this column.' => 'Nie udało się usunąć kolumny.',
'Do you really want to remove this column: "%s"?' => 'Na pewno chcesz usunąć kolumnę: "%s"?',
'This action will REMOVE ALL TASKS associated to this column!' => 'Wszystkie zadania w kolumnie zostaną usunięte!',
'Settings' => 'Ustawienia',
'Application settings' => 'Ustawienia aplikacji',
'Language' => 'Język',

View File

@ -73,7 +73,6 @@ return array(
'Remove a column' => 'Remover uma coluna',
'Unable to remove this column.' => 'Não foi possível remover esta coluna.',
'Do you really want to remove this column: "%s"?' => 'Você realmente deseja remover esta coluna: "%s"?',
'This action will REMOVE ALL TASKS associated to this column!' => 'Esta ação irá REMOVER TODAS AS TAREFAS associadas a esta coluna!',
'Settings' => 'Configurações',
'Application settings' => 'Configurações da aplicação',
'Language' => 'Idioma',

View File

@ -73,7 +73,6 @@ return array(
'Remove a column' => 'Remover uma coluna',
'Unable to remove this column.' => 'Não foi possível remover esta coluna.',
'Do you really want to remove this column: "%s"?' => 'Tem a certeza que quer remover esta coluna: "%s"?',
'This action will REMOVE ALL TASKS associated to this column!' => 'Esta acção irá REMOVER TODAS AS TAREFAS associadas a esta coluna!',
'Settings' => 'Configurações',
'Application settings' => 'Configurações da aplicação',
'Language' => 'Idioma',

View File

@ -73,7 +73,6 @@ return array(
'Remove a column' => 'Удалить колонку',
'Unable to remove this column.' => 'Не удалось удалить эту колонку.',
'Do you really want to remove this column: "%s"?' => 'Вы точно хотите удалить эту колонку: "%s" ?',
'This action will REMOVE ALL TASKS associated to this column!' => 'Вы УДАЛИТЕ ВСЕ ЗАДАЧИ находящиеся в этой колонке!',
'Settings' => 'Настройки',
'Application settings' => 'Настройки приложения',
'Language' => 'Язык',

View File

@ -73,7 +73,6 @@ return array(
'Remove a column' => 'Ukloni kolonu',
'Unable to remove this column.' => 'Nemoguće uklanjanje kolone.',
'Do you really want to remove this column: "%s"?' => 'Da li zaista želiš da ukoniš ovu kolonu: "%s"?',
'This action will REMOVE ALL TASKS associated to this column!' => 'Ova akcija BRIŠE SVE ZADATKE vezane za ovu kolonu!',
'Settings' => 'Podešavanja',
'Application settings' => 'Podešavanja aplikacije',
'Language' => 'Jezik',

View File

@ -73,7 +73,6 @@ return array(
'Remove a column' => 'Ta bort en kolumn',
'Unable to remove this column.' => 'Kunde inte ta bort kolumnen.',
'Do you really want to remove this column: "%s"?' => 'Vill du verkligen ta bort kolumnen: "%s"?',
'This action will REMOVE ALL TASKS associated to this column!' => 'Denna åtgärd kommer att TA BORT ALLA uppgifter kopplade till kolumnen!',
'Settings' => 'Inställningar',
'Application settings' => 'Applikationsinställningar',
'Language' => 'Språk',

View File

@ -73,7 +73,6 @@ return array(
'Remove a column' => 'ลบคอลัมน์',
'Unable to remove this column.' => 'ไม่สามารถลบคอลัมน์นี้',
'Do you really want to remove this column: "%s"?' => 'คุณต้องการลบคอลัมน์ « %s » ออกใช่หรือไม่?',
'This action will REMOVE ALL TASKS associated to this column!' => 'การกระทำนี้จะลบงานที่เกี่ยวข้องกับคอลัมน์นี้',
'Settings' => 'ตั้งค่า',
'Application settings' => 'ตั้งค่าการทำงาน',
'Language' => 'ภาษา',

View File

@ -73,7 +73,6 @@ return array(
'Remove a column' => 'Bir sütunu sil',
'Unable to remove this column.' => 'Bu sütun silinemiyor.',
'Do you really want to remove this column: "%s"?' => 'Bu sütunu gerçekten silmek istiyor musunuz: "%s"?',
'This action will REMOVE ALL TASKS associated to this column!' => 'Bu komut sütun içindeki TÜM GÖREVLERİ silecek!',
'Settings' => 'Ayarlar',
'Application settings' => 'Uygulama ayarları',
'Language' => 'Dil',

View File

@ -73,7 +73,6 @@ return array(
'Remove a column' => '移除一个栏目',
'Unable to remove this column.' => '无法移除该栏目。',
'Do you really want to remove this column: "%s"?' => '确定要移除栏目"%s"吗?',
'This action will REMOVE ALL TASKS associated to this column!' => '该动作将移除与该栏目相关的所有项目!',
'Settings' => '设置',
'Application settings' => '应用设置',
'Language' => '语言',

View File

@ -120,6 +120,24 @@ class ColumnModel extends Base
return $this->db->table(self::TABLE)->eq('project_id', $project_id)->asc('position')->findAll();
}
/**
* Get all columns with tasks count
*
* @access public
* @param integer $project_id Project id
* @return array
*/
public function getAllWithTasksCount($project_id)
{
return $this->db->table(self::TABLE)
->columns('id', 'title', 'position', 'task_limit', 'description', 'hide_in_dashboard', 'project_id')
->subquery('SELECT COUNT(*) FROM '.TaskModel::TABLE.' WHERE column_id='.self::TABLE.'.id AND is_active=1', 'nb_open_tasks')
->subquery('SELECT COUNT(*) FROM '.TaskModel::TABLE.' WHERE column_id='.self::TABLE.'.id AND is_active=0', 'nb_closed_tasks')
->eq('project_id', $project_id)
->asc('position')
->findAll();
}
/**
* Get the list of columns sorted by position [ column_id => title ]
*

View File

@ -367,17 +367,18 @@ class TaskFinderModel extends Base
* Count the number of tasks for a given column and status
*
* @access public
* @param integer $project_id Project id
* @param integer $column_id Column id
* @return integer
* @param integer $project_id Project id
* @param integer $column_id Column id
* @param array $status
* @return int
*/
public function countByColumnId($project_id, $column_id)
public function countByColumnId($project_id, $column_id, array $status = array(TaskModel::STATUS_OPEN))
{
return $this->db
->table(TaskModel::TABLE)
->eq('project_id', $project_id)
->eq('column_id', $column_id)
->eq('is_active', 1)
->in('is_active', $status)
->count();
}

View File

@ -15,10 +15,12 @@
data-save-position-url="<?= $this->url->href('ColumnController', 'move', array('project_id' => $project['id'])) ?>">
<thead>
<tr>
<th class="column-70"><?= t('Column title') ?></th>
<th class="column-40"><?= t('Column title') ?></th>
<th class="column-10"><?= t('Task limit') ?></th>
<th class="column-20"><?= t('Visible on dashboard') ?></th>
<th class="column-5"><?= t('Actions') ?></th>
<th class="column-10"><?= t('Open tasks') ?></th>
<th class="column-10"><?= t('Closed tasks') ?></th>
<th><?= t('Actions') ?></th>
</tr>
</thead>
<tbody>
@ -39,6 +41,12 @@
<td>
<?= $column['hide_in_dashboard'] == 1 ? t('Yes') : t('No') ?>
</td>
<td>
<?= $column['nb_open_tasks'] ?>
</td>
<td>
<?= $column['nb_closed_tasks'] ?>
</td>
<td>
<div class="dropdown">
<a href="#" class="dropdown-menu dropdown-menu-link-icon"><i class="fa fa-cog fa-fw"></i><i class="fa fa-caret-down"></i></a>
@ -46,9 +54,11 @@
<li>
<?= $this->modal->medium('edit', t('Edit'), 'ColumnController', 'edit', array('project_id' => $project['id'], 'column_id' => $column['id'])) ?>
</li>
<?php if ($column['nb_open_tasks'] == 0 && $column['nb_closed_tasks'] == 0): ?>
<li>
<?= $this->modal->confirm('trash-o', t('Remove'), 'ColumnController', 'confirm', array('project_id' => $project['id'], 'column_id' => $column['id'])) ?>
</li>
<?php endif ?>
</ul>
</div>
</td>

View File

@ -5,7 +5,6 @@
<div class="confirm">
<p class="alert alert-info">
<?= t('Do you really want to remove this column: "%s"?', $column['title']) ?>
<?= t('This action will REMOVE ALL TASKS associated to this column!') ?>
</p>
<?= $this->modal->confirmButtons(

View File

@ -4,8 +4,9 @@ require_once __DIR__.'/../Base.php';
use Kanboard\Model\ProjectModel;
use Kanboard\Model\ColumnModel;
use Kanboard\Model\TaskCreationModel;
class ColumnTest extends Base
class ColumnModelTest extends Base
{
public function testGetColumn()
{
@ -94,6 +95,36 @@ class ColumnTest extends Base
$this->assertEquals('Done', $columns[3]['title']);
}
public function testGetAllWithTasksCount()
{
$projectModel = new ProjectModel($this->container);
$columnModel = new ColumnModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest')));
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'UnitTest', 'project_id' => 1, 'column_id' => 1)));
$this->assertEquals(2, $taskCreationModel->create(array('title' => 'UnitTest', 'project_id' => 1, 'column_id' => 2, 'is_active' => 0)));
$columns = $columnModel->getAllWithTasksCount(1);
$this->assertCount(4, $columns);
$this->assertEquals(1, $columns[0]['id']);
$this->assertEquals(1, $columns[0]['position']);
$this->assertEquals(1, $columns[0]['project_id']);
$this->assertEquals(0, $columns[0]['task_limit']);
$this->assertEquals(0, $columns[0]['hide_in_dashboard']);
$this->assertEquals('', $columns[0]['description']);
$this->assertEquals('Backlog', $columns[0]['title']);
$this->assertEquals(1, $columns[0]['nb_open_tasks']);
$this->assertEquals(0, $columns[0]['nb_closed_tasks']);
$this->assertEquals(2, $columns[1]['id']);
$this->assertEquals(2, $columns[1]['position']);
$this->assertEquals('Ready', $columns[1]['title']);
$this->assertEquals(0, $columns[1]['nb_open_tasks']);
$this->assertEquals(1, $columns[1]['nb_closed_tasks']);
}
public function testGetList()
{
$projectModel = new ProjectModel($this->container);