diff options
author | Frederic Guillot <fred@kanboard.net> | 2015-02-07 23:28:17 -0500 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2015-02-07 23:28:17 -0500 |
commit | 00b9508d8178bae016b2a25a81282dbe9ae0a9d2 (patch) | |
tree | 488397b9830b9ee56ff3eb4752958ea7a44eec04 | |
parent | 607d9dc79429cefa51dfe1739564922cc9a2ab89 (diff) |
Be able to disable the login form for specific users
25 files changed, 148 insertions, 69 deletions
diff --git a/app/Auth/Database.php b/app/Auth/Database.php index 2804b9a8..e69f18a9 100644 --- a/app/Auth/Database.php +++ b/app/Auth/Database.php @@ -30,9 +30,14 @@ class Database extends Base */ public function authenticate($username, $password) { - $user = $this->db->table(User::TABLE)->eq('username', $username)->eq('is_ldap_user', 0)->findOne(); + $user = $this->db + ->table(User::TABLE) + ->eq('username', $username) + ->eq('disable_login_form', 0) + ->eq('is_ldap_user', 0) + ->findOne(); - if ($user && password_verify($password, $user['password'])) { + if (is_array($user) && password_verify($password, $user['password'])) { $this->userSession->refresh($user); $this->container['dispatcher']->dispatch('auth.success', new AuthEvent(self::AUTH_NAME, $user['id'])); return true; diff --git a/app/Auth/ReverseProxy.php b/app/Auth/ReverseProxy.php index b84550cf..6cd01b28 100644 --- a/app/Auth/ReverseProxy.php +++ b/app/Auth/ReverseProxy.php @@ -66,6 +66,7 @@ class ReverseProxy extends Base 'username' => $login, 'is_admin' => REVERSE_PROXY_DEFAULT_ADMIN === $login, 'is_ldap_user' => 1, + 'disable_login_form' => 1, )); } } diff --git a/app/Controller/User.php b/app/Controller/User.php index 3d44f226..91141241 100644 --- a/app/Controller/User.php +++ b/app/Controller/User.php @@ -341,7 +341,7 @@ class User extends Base if ($this->request->isPost()) { - $values = $this->request->getValues(); + $values = $this->request->getValues() + array('disable_login_form' => 0); if ($this->userSession->isAdmin()) { $values += array('is_admin' => 0); diff --git a/app/Locale/da_DK/translations.php b/app/Locale/da_DK/translations.php index 7e2d03a0..45611dcd 100644 --- a/app/Locale/da_DK/translations.php +++ b/app/Locale/da_DK/translations.php @@ -713,4 +713,5 @@ return array( // 'Show/hide projects' => '', // 'Show/hide subtasks' => '', // 'Show/hide tasks' => '', + // 'Disable login form' => '', ); diff --git a/app/Locale/de_DE/translations.php b/app/Locale/de_DE/translations.php index e4838ba4..6570f154 100644 --- a/app/Locale/de_DE/translations.php +++ b/app/Locale/de_DE/translations.php @@ -713,4 +713,5 @@ return array( // 'Show/hide projects' => '', // 'Show/hide subtasks' => '', // 'Show/hide tasks' => '', + // 'Disable login form' => '', ); diff --git a/app/Locale/es_ES/translations.php b/app/Locale/es_ES/translations.php index 67907e73..91eeab00 100644 --- a/app/Locale/es_ES/translations.php +++ b/app/Locale/es_ES/translations.php @@ -713,4 +713,5 @@ return array( // 'Show/hide projects' => '', // 'Show/hide subtasks' => '', // 'Show/hide tasks' => '', + // 'Disable login form' => '', ); diff --git a/app/Locale/fi_FI/translations.php b/app/Locale/fi_FI/translations.php index 01424a6f..4db578dd 100644 --- a/app/Locale/fi_FI/translations.php +++ b/app/Locale/fi_FI/translations.php @@ -713,4 +713,5 @@ return array( // 'Show/hide projects' => '', // 'Show/hide subtasks' => '', // 'Show/hide tasks' => '', + // 'Disable login form' => '', ); diff --git a/app/Locale/fr_FR/translations.php b/app/Locale/fr_FR/translations.php index dd02cd7f..90eb87af 100644 --- a/app/Locale/fr_FR/translations.php +++ b/app/Locale/fr_FR/translations.php @@ -715,4 +715,5 @@ return array( 'Show/hide projects' => 'Afficher/cacher les projets', 'Show/hide subtasks' => 'Afficher/cacher les sous-tâches', 'Show/hide tasks' => 'Afficher/cacher les tâches', + 'Disable login form' => 'Désactiver le formulaire d\'authentification', ); diff --git a/app/Locale/hu_HU/translations.php b/app/Locale/hu_HU/translations.php index d051be30..252e57ef 100644 --- a/app/Locale/hu_HU/translations.php +++ b/app/Locale/hu_HU/translations.php @@ -713,4 +713,5 @@ return array( // 'Show/hide projects' => '', // 'Show/hide subtasks' => '', // 'Show/hide tasks' => '', + // 'Disable login form' => '', ); diff --git a/app/Locale/it_IT/translations.php b/app/Locale/it_IT/translations.php index 64eb201a..4f0e6bc5 100644 --- a/app/Locale/it_IT/translations.php +++ b/app/Locale/it_IT/translations.php @@ -713,4 +713,5 @@ return array( // 'Show/hide projects' => '', // 'Show/hide subtasks' => '', // 'Show/hide tasks' => '', + // 'Disable login form' => '', ); diff --git a/app/Locale/ja_JP/translations.php b/app/Locale/ja_JP/translations.php index 68f2bbc3..a71bffdd 100644 --- a/app/Locale/ja_JP/translations.php +++ b/app/Locale/ja_JP/translations.php @@ -713,4 +713,5 @@ return array( // 'Show/hide projects' => '', // 'Show/hide subtasks' => '', // 'Show/hide tasks' => '', + // 'Disable login form' => '', ); diff --git a/app/Locale/pl_PL/translations.php b/app/Locale/pl_PL/translations.php index 5ff27109..49fb3272 100644 --- a/app/Locale/pl_PL/translations.php +++ b/app/Locale/pl_PL/translations.php @@ -713,4 +713,5 @@ return array( // 'Show/hide projects' => '', // 'Show/hide subtasks' => '', // 'Show/hide tasks' => '', + // 'Disable login form' => '', ); diff --git a/app/Locale/pt_BR/translations.php b/app/Locale/pt_BR/translations.php index 73966572..bd327f0b 100644 --- a/app/Locale/pt_BR/translations.php +++ b/app/Locale/pt_BR/translations.php @@ -713,4 +713,5 @@ return array( // 'Show/hide projects' => '', // 'Show/hide subtasks' => '', // 'Show/hide tasks' => '', + // 'Disable login form' => '', ); diff --git a/app/Locale/ru_RU/translations.php b/app/Locale/ru_RU/translations.php index e644aa5d..1042830d 100644 --- a/app/Locale/ru_RU/translations.php +++ b/app/Locale/ru_RU/translations.php @@ -713,4 +713,5 @@ return array( // 'Show/hide projects' => '', // 'Show/hide subtasks' => '', // 'Show/hide tasks' => '', + // 'Disable login form' => '', ); diff --git a/app/Locale/sv_SE/translations.php b/app/Locale/sv_SE/translations.php index 8bab7cdf..cdae7fde 100644 --- a/app/Locale/sv_SE/translations.php +++ b/app/Locale/sv_SE/translations.php @@ -713,4 +713,5 @@ return array( // 'Show/hide projects' => '', // 'Show/hide subtasks' => '', // 'Show/hide tasks' => '', + // 'Disable login form' => '', ); diff --git a/app/Locale/th_TH/translations.php b/app/Locale/th_TH/translations.php index ef2df8e8..54d94519 100644 --- a/app/Locale/th_TH/translations.php +++ b/app/Locale/th_TH/translations.php @@ -713,4 +713,5 @@ return array( // 'Show/hide projects' => '', // 'Show/hide subtasks' => '', // 'Show/hide tasks' => '', + // 'Disable login form' => '', ); diff --git a/app/Locale/zh_CN/translations.php b/app/Locale/zh_CN/translations.php index ffea13d4..2a2bc0b8 100644 --- a/app/Locale/zh_CN/translations.php +++ b/app/Locale/zh_CN/translations.php @@ -713,4 +713,5 @@ return array( // 'Show/hide projects' => '', // 'Show/hide subtasks' => '', // 'Show/hide tasks' => '', + // 'Disable login form' => '', ); diff --git a/app/Schema/Mysql.php b/app/Schema/Mysql.php index 5a52288b..9c066625 100644 --- a/app/Schema/Mysql.php +++ b/app/Schema/Mysql.php @@ -5,7 +5,12 @@ namespace Schema; use PDO; use Core\Security; -const VERSION = 43; +const VERSION = 44; + +function version_44($pdo) +{ + $pdo->exec('ALTER TABLE users ADD COLUMN disable_login_form TINYINT(1) DEFAULT 0'); +} function version_43($pdo) { diff --git a/app/Schema/Postgres.php b/app/Schema/Postgres.php index 7aa1c457..52130c96 100644 --- a/app/Schema/Postgres.php +++ b/app/Schema/Postgres.php @@ -5,7 +5,12 @@ namespace Schema; use PDO; use Core\Security; -const VERSION = 24; +const VERSION = 25; + +function version_25($pdo) +{ + $pdo->exec("ALTER TABLE users ADD COLUMN disable_login_form BOOLEAN DEFAULT '1'"); +} function version_24($pdo) { @@ -13,17 +18,17 @@ function version_24($pdo) $rq->execute(array('subtask_restriction', '0')); $rq->execute(array('subtask_time_tracking', '0')); - $pdo->exec(" + $pdo->exec(' CREATE TABLE subtask_time_tracking ( id SERIAL PRIMARY KEY, - user_id INTEGER NOT NULL, - subtask_id INTEGER NOT NULL, - start INTEGER DEFAULT 0, - end INTEGER DEFAULT 0, + "user_id" INTEGER NOT NULL, + "subtask_id" INTEGER NOT NULL, + "start" INTEGER DEFAULT 0, + "end" INTEGER DEFAULT 0, FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE, FOREIGN KEY(subtask_id) REFERENCES task_has_subtasks(id) ON DELETE CASCADE ) - "); + '); } function version_23($pdo) diff --git a/app/Schema/Sqlite.php b/app/Schema/Sqlite.php index 17166e64..37483945 100644 --- a/app/Schema/Sqlite.php +++ b/app/Schema/Sqlite.php @@ -5,7 +5,12 @@ namespace Schema; use Core\Security; use PDO; -const VERSION = 42; +const VERSION = 43; + +function version_43($pdo) +{ + $pdo->exec('ALTER TABLE users ADD COLUMN disable_login_form INTEGER DEFAULT 0'); +} function version_42($pdo) { diff --git a/app/Template/user/edit.php b/app/Template/user/edit.php index 310a1ed0..bd1c4889 100644 --- a/app/Template/user/edit.php +++ b/app/Template/user/edit.php @@ -26,9 +26,13 @@ <?= $this->formLabel(t('Language'), 'language') ?> <?= $this->formSelect('language', $languages, $values, $errors) ?><br/> - <?php if ($this->userSession->isAdmin()): ?> - <?= $this->formCheckbox('is_admin', t('Administrator'), 1, isset($values['is_admin']) && $values['is_admin'] == 1 ? true : false) ?><br/> - <?php endif ?> + <div class="alert alert-error"> + <?= $this->formCheckbox('disable_login_form', t('Disable login form'), 1, isset($values['disable_login_form']) && $values['disable_login_form'] == 1) ?><br/> + + <?php if ($this->userSession->isAdmin()): ?> + <?= $this->formCheckbox('is_admin', t('Administrator'), 1, isset($values['is_admin']) && $values['is_admin'] == 1) ?><br/> + <?php endif ?> + </div> <div class="form-actions"> <input type="submit" value="<?= t('Save') ?>" class="btn btn-blue"/> diff --git a/composer.json b/composer.json index c35d5243..aa9c5dad 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "fguillot/simple-validator": "0.0.1", "swiftmailer/swiftmailer": "@stable", "fguillot/json-rpc": "0.0.1", - "fguillot/picodb": "0.0.2", + "fguillot/picodb": "dev-master", "erusev/parsedown": "1.5.1", "lusitanian/oauth": "0.3.5", "pimple/pimple": "~3.0", diff --git a/composer.lock b/composer.lock index 06e31689..c37550be 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "671bd4694072aed17a542db8f08db217", + "hash": "fdd9fc2aa1f8bdbc3e21d06ff0c7b184", "packages": [ { "name": "erusev/parsedown", @@ -84,7 +84,7 @@ }, { "name": "fguillot/picodb", - "version": "v0.0.2", + "version": "dev-master", "source": { "type": "git", "url": "https://github.com/fguillot/picoDb.git", @@ -393,17 +393,17 @@ }, { "name": "symfony/console", - "version": "v2.6.3", + "version": "v2.6.4", "target-dir": "Symfony/Component/Console", "source": { "type": "git", "url": "https://github.com/symfony/Console.git", - "reference": "6ac6491ff60c0e5a941db3ccdc75a07adbb61476" + "reference": "e44154bfe3e41e8267d7a3794cd9da9a51cfac34" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Console/zipball/6ac6491ff60c0e5a941db3ccdc75a07adbb61476", - "reference": "6ac6491ff60c0e5a941db3ccdc75a07adbb61476", + "url": "https://api.github.com/repos/symfony/Console/zipball/e44154bfe3e41e8267d7a3794cd9da9a51cfac34", + "reference": "e44154bfe3e41e8267d7a3794cd9da9a51cfac34", "shasum": "" }, "require": { @@ -446,21 +446,21 @@ ], "description": "Symfony Console Component", "homepage": "http://symfony.com", - "time": "2015-01-06 17:50:02" + "time": "2015-01-25 04:39:26" }, { "name": "symfony/event-dispatcher", - "version": "v2.6.3", + "version": "v2.6.4", "target-dir": "Symfony/Component/EventDispatcher", "source": { "type": "git", "url": "https://github.com/symfony/EventDispatcher.git", - "reference": "40ff70cadea3785d83cac1c8309514b36113064e" + "reference": "f75989f3ab2743a82fe0b03ded2598a2b1546813" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/40ff70cadea3785d83cac1c8309514b36113064e", - "reference": "40ff70cadea3785d83cac1c8309514b36113064e", + "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/f75989f3ab2743a82fe0b03ded2598a2b1546813", + "reference": "f75989f3ab2743a82fe0b03ded2598a2b1546813", "shasum": "" }, "require": { @@ -504,13 +504,13 @@ ], "description": "Symfony EventDispatcher Component", "homepage": "http://symfony.com", - "time": "2015-01-05 14:28:40" + "time": "2015-02-01 16:10:57" } ], "packages-dev": [ { "name": "symfony/stopwatch", - "version": "v2.6.3", + "version": "v2.6.4", "target-dir": "Symfony/Component/Stopwatch", "source": { "type": "git", @@ -560,6 +560,7 @@ "minimum-stability": "stable", "stability-flags": { "swiftmailer/swiftmailer": 0, + "fguillot/picodb": 20, "symfony/console": 0 }, "prefer-stable": false, diff --git a/tests/units/ProjectDuplicationTest.php b/tests/units/ProjectDuplicationTest.php index bb8e0408..b35575aa 100644 --- a/tests/units/ProjectDuplicationTest.php +++ b/tests/units/ProjectDuplicationTest.php @@ -229,13 +229,13 @@ class ProjectDuplicationTest extends Base $this->assertEquals(2, $tc->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1))); $this->assertEquals(3, $tc->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); - $this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, function() {}); - $this->container['dispatcher']->addListener(Task::EVENT_CREATE, function() {}); - - $this->assertEquals(2, $pd->duplicate(1, array('category', 'action', 'swimlane', 'task'))); + $this->assertNotFalse($pd->duplicate(1, array('category', 'action', 'swimlane', 'task'))); + $project = $p->getByName('P1 (Clone)'); + $this->assertNotFalse($project); + $project_id = $project['id']; // Check if Swimlanes have been duplicated - $swimlanes = $s->getAll(2); + $swimlanes = $s->getAll($project_id); $this->assertCount(3, $swimlanes); $this->assertEquals(4, $swimlanes[0]['id']); @@ -244,37 +244,59 @@ class ProjectDuplicationTest extends Base $this->assertEquals('S2', $swimlanes[1]['name']); $this->assertEquals(6, $swimlanes[2]['id']); $this->assertEquals('S3', $swimlanes[2]['name']); - $new_default = $s->getDefault(2); + $new_default = $s->getDefault($project_id); $this->assertEquals('New Default', $new_default['default_swimlane']); // Check if Tasks have been duplicated - $tasks = $tf->getAll(2); + $tasks = $tf->getAll($project_id); $this->assertCount(3, $tasks); - $this->assertEquals(4, $tasks[0]['id']); + // $this->assertEquals(4, $tasks[0]['id']); $this->assertEquals('T1', $tasks[0]['title']); - $this->assertEquals(5, $tasks[1]['id']); + // $this->assertEquals(5, $tasks[1]['id']); $this->assertEquals('T2', $tasks[1]['title']); - $this->assertEquals(6, $tasks[2]['id']); + // $this->assertEquals(6, $tasks[2]['id']); $this->assertEquals('T3', $tasks[2]['title']); - // Drop project - unset($tasks); - unset($swimlanes); - unset($new_default); + $p->remove($project_id); - $p->remove(2); + $this->assertFalse($p->exists($project_id)); + $this->assertCount(0, $s->getAll($project_id)); + $this->assertCount(0, $tf->getAll($project_id)); + } - $this->assertFalse($p->exists(2)); - $this->assertCount(0, $s->getAll(2)); - $this->assertCount(0, $tf->getAll(2)); + public function testCloneProjectWithSwimlanes() + { + $p = new Project($this->container); + $pd = new ProjectDuplication($this->container); + $s = new Swimlane($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); - // Check duplication with Swimlanes only - $this->assertEquals(2, $pd->duplicate(1, array('category', 'action', 'swimlane'))); + $this->assertEquals(1, $p->create(array('name' => 'P1'))); - // Check if Swimlanes have been duplicated - $swimlanes = $s->getAll(2); + // create initial swimlanes + $this->assertEquals(1, $s->create(1, 'S1')); + $this->assertEquals(2, $s->create(1, 'S2')); + $this->assertEquals(3, $s->create(1, 'S3')); + + $default_swimlane1 = $s->getDefault(1); + $default_swimlane1['default_swimlane'] = 'New Default'; + + $this->assertTrue($s->updateDefault($default_swimlane1)); + + //create initial tasks + $this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1))); + $this->assertEquals(2, $tc->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1))); + $this->assertEquals(3, $tc->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); + + $this->assertNotFalse($pd->duplicate(1, array('category', 'action', 'swimlane'))); + $project = $p->getByName('P1 (Clone)'); + $this->assertNotFalse($project); + $project_id = $project['id']; + + $swimlanes = $s->getAll($project_id); $this->assertCount(3, $swimlanes); $this->assertEquals(4, $swimlanes[0]['id']); @@ -283,38 +305,55 @@ class ProjectDuplicationTest extends Base $this->assertEquals('S2', $swimlanes[1]['name']); $this->assertEquals(6, $swimlanes[2]['id']); $this->assertEquals('S3', $swimlanes[2]['name']); - $new_default = $s->getDefault(2); + $new_default = $s->getDefault($project_id); $this->assertEquals('New Default', $new_default['default_swimlane']); // Check if Tasks have NOT been duplicated - $this->assertCount(0, $tf->getAll(2)); + $this->assertCount(0, $tf->getAll($project_id)); + } + + public function testCloneProjectWithTasks() + { + $p = new Project($this->container); + $pd = new ProjectDuplication($this->container); + $s = new Swimlane($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'P1'))); - // Drop project - unset($tasks); - unset($swimlanes); - unset($new_default); + // create initial swimlanes + $this->assertEquals(1, $s->create(1, 'S1')); + $this->assertEquals(2, $s->create(1, 'S2')); + $this->assertEquals(3, $s->create(1, 'S3')); + + $default_swimlane1 = $s->getDefault(1); + $default_swimlane1['default_swimlane'] = 'New Default'; - $p->remove(2); + $this->assertTrue($s->updateDefault($default_swimlane1)); - $this->assertFalse($p->exists(2)); - $this->assertCount(0, $s->getAll(2)); - $this->assertCount(0, $tf->getAll(2)); + //create initial tasks + $this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1))); + $this->assertEquals(2, $tc->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1))); + $this->assertEquals(3, $tc->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); - // Check duplication with Tasks only - $this->assertEquals(2, $pd->duplicate(1, array('category', 'action', 'task'))); + $this->assertNotFalse($pd->duplicate(1, array('category', 'action', 'task'))); + $project = $p->getByName('P1 (Clone)'); + $this->assertNotFalse($project); + $project_id = $project['id']; // Check if Swimlanes have NOT been duplicated - $this->assertCount(0, $s->getAll(2)); + $this->assertCount(0, $s->getAll($project_id)); // Check if Tasks have been duplicated - $tasks = $tf->getAll(2); + $tasks = $tf->getAll($project_id); $this->assertCount(3, $tasks); - $this->assertEquals(4, $tasks[0]['id']); + //$this->assertEquals(4, $tasks[0]['id']); $this->assertEquals('T1', $tasks[0]['title']); - $this->assertEquals(5, $tasks[1]['id']); + //$this->assertEquals(5, $tasks[1]['id']); $this->assertEquals('T2', $tasks[1]['title']); - $this->assertEquals(6, $tasks[2]['id']); + //$this->assertEquals(6, $tasks[2]['id']); $this->assertEquals('T3', $tasks[2]['title']); } } diff --git a/tests/units/ProjectTest.php b/tests/units/ProjectTest.php index 4553dd3a..4864a3ae 100644 --- a/tests/units/ProjectTest.php +++ b/tests/units/ProjectTest.php @@ -97,7 +97,7 @@ class ProjectTest extends Base $project = $p->getById(1); $this->assertNotEmpty($project); - $this->assertEquals($now, $project['last_modified']); + $this->assertEquals($now, $project['last_modified'], 'Wrong Timestamp', 1); sleep(1); $this->assertTrue($p->updateModificationDate(1)); |