diff options
-rw-r--r-- | app/Action/CommentCreation.php | 4 | ||||
-rw-r--r-- | app/Controller/Board.php | 21 | ||||
-rw-r--r-- | app/Controller/Task.php | 4 | ||||
-rw-r--r-- | app/Core/Helper.php | 1 | ||||
-rw-r--r-- | app/Model/ProjectPermission.php | 28 | ||||
-rw-r--r-- | app/Model/TaskCreation.php | 8 | ||||
-rw-r--r-- | app/Template/comment/show.php | 2 | ||||
-rw-r--r-- | app/Template/project/sidebar.php | 2 | ||||
-rw-r--r-- | app/Template/project/users.php | 6 | ||||
-rw-r--r-- | app/Template/subtask/remove.php | 2 | ||||
-rw-r--r-- | app/Template/subtask/show.php | 4 | ||||
-rw-r--r-- | composer.lock | 8 | ||||
-rw-r--r-- | tests/functionals/ApiTest.php | 8 | ||||
-rw-r--r-- | tests/units/ProjectDuplicateTest.php | 38 | ||||
-rw-r--r-- | tests/units/TaskCreationTest.php | 12 |
15 files changed, 101 insertions, 47 deletions
diff --git a/app/Action/CommentCreation.php b/app/Action/CommentCreation.php index 27ed011b..54d7be7d 100644 --- a/app/Action/CommentCreation.php +++ b/app/Action/CommentCreation.php @@ -16,7 +16,7 @@ class CommentCreation extends Base * Get the list of compatible events * * @access public - * @return array + * @return string[] */ public function getCompatibleEvents() { @@ -29,7 +29,7 @@ class CommentCreation extends Base * Get the required parameter for the action (defined by the user) * * @access public - * @return array + * @return string[] */ public function getActionRequiredParameters() { diff --git a/app/Controller/Board.php b/app/Controller/Board.php index 128d9215..48f2b518 100644 --- a/app/Controller/Board.php +++ b/app/Controller/Board.php @@ -198,11 +198,10 @@ class Board extends Base * * @access public */ - public function edit() + public function edit(array $values = array(), array $errors = array()) { $project = $this->getProject(); $columns = $this->board->getColumns($project['id']); - $values = array(); foreach ($columns as $column) { $values['title['.$column['id'].']'] = $column['title']; @@ -210,7 +209,7 @@ class Board extends Base } $this->response->html($this->projectLayout('board/edit', array( - 'errors' => array(), + 'errors' => $errors, 'values' => $values + array('project_id' => $project['id']), 'columns' => $columns, 'project' => $project, @@ -249,13 +248,7 @@ class Board extends Base } } - $this->response->html($this->projectLayout('board/edit', array( - 'errors' => $errors, - 'values' => $values + array('project_id' => $project['id']), - 'columns' => $columns, - 'project' => $project, - 'title' => t('Edit board') - ))); + $this->edit($values, $errors); } /** @@ -287,13 +280,7 @@ class Board extends Base } } - $this->response->html($this->projectLayout('board/edit', array( - 'errors' => $errors, - 'values' => $values + $data, - 'columns' => $columns, - 'project' => $project, - 'title' => t('Edit board') - ))); + $this->edit($values, $errors); } /** diff --git a/app/Controller/Task.php b/app/Controller/Task.php index 77ea60d9..773183fe 100644 --- a/app/Controller/Task.php +++ b/app/Controller/Task.php @@ -438,7 +438,7 @@ class Task extends Base if ($this->taskDuplication->moveToProject($task['id'], $values['project_id'])) { $this->session->flash(t('Task updated successfully.')); - $this->response->redirect('?controller=task&action=show&task_id='.$task['id'].'&project_id='.$task['project_id']); + $this->response->redirect('?controller=task&action=show&task_id='.$task['id'].'&project_id='.$values['project_id']); } else { $this->session->flashError(t('Unable to update your task.')); @@ -477,7 +477,7 @@ class Task extends Base $task_id = $this->taskDuplication->duplicateToProject($task['id'], $values['project_id']); if ($task_id) { $this->session->flash(t('Task created successfully.')); - $this->response->redirect('?controller=task&action=show&task_id='.$task_id.'&project_id='.$task['project_id']); + $this->response->redirect('?controller=task&action=show&task_id='.$task_id.'&project_id='.$values['project_id']); } else { $this->session->flashError(t('Unable to create your task.')); diff --git a/app/Core/Helper.php b/app/Core/Helper.php index 1db8afc6..e9fa1868 100644 --- a/app/Core/Helper.php +++ b/app/Core/Helper.php @@ -14,6 +14,7 @@ use Parsedown; * @property \Core\Session $session * @property \Model\Acl $acl * @property \Model\User $user + * @property \Model\UserSession $userSession */ class Helper { diff --git a/app/Model/ProjectPermission.php b/app/Model/ProjectPermission.php index fc7ab0d5..0249b3b1 100644 --- a/app/Model/ProjectPermission.php +++ b/app/Model/ProjectPermission.php @@ -324,17 +324,29 @@ class ProjectPermission extends Base /** * Copy user access from a project to another one * - * @author Antonio Rabelo - * @param integer $project_from Project Template - * @return integer $project_to Project that receives the copy + * @param integer $project_src Project Template + * @return integer $project_dst Project that receives the copy * @return boolean */ - public function duplicate($project_from, $project_to) + public function duplicate($project_src, $project_dst) { - $users = $this->getMembers($project_from); - - foreach ($users as $user_id => $name) { - if (! $this->addMember($project_to, $user_id)) { // TODO: Duplicate managers + $rows = $this->db + ->table(self::TABLE) + ->columns('project_id', 'user_id', 'is_owner') + ->eq('project_id', $project_src) + ->findAll(); + + foreach ($rows as $row) { + + $result = $this->db + ->table(self::TABLE) + ->save(array( + 'project_id' => $project_dst, + 'user_id' => $row['user_id'], + 'is_owner' => (int) $row['is_owner'], // (int) for postgres + )); + + if (! $result) { return false; } } diff --git a/app/Model/TaskCreation.php b/app/Model/TaskCreation.php index e99bf6d2..17e5ff70 100644 --- a/app/Model/TaskCreation.php +++ b/app/Model/TaskCreation.php @@ -21,6 +21,10 @@ class TaskCreation extends Base */ public function create(array $values) { + if (! $this->project->exists($values['project_id'])) { + return 0; + } + $this->prepare($values); $task_id = $this->persist(Task::TABLE, $values); @@ -51,6 +55,10 @@ class TaskCreation extends Base $values['color_id'] = $this->color->getDefaultColor(); } + if (empty($values['title'])) { + $values['title'] = t('Untitled'); + } + $values['swimlane_id'] = empty($values['swimlane_id']) ? 0 : $values['swimlane_id']; $values['date_creation'] = time(); $values['date_modification'] = $values['date_creation']; diff --git a/app/Template/comment/show.php b/app/Template/comment/show.php index 2cf9708b..23389c06 100644 --- a/app/Template/comment/show.php +++ b/app/Template/comment/show.php @@ -39,7 +39,7 @@ 'controller' => 'task', 'action' => 'show', 'params' => array( - 'project_id' => $project['id'] + 'project_id' => $task['project_id'] ) ) ) ?> diff --git a/app/Template/project/sidebar.php b/app/Template/project/sidebar.php index 991a1c73..f28f6b0d 100644 --- a/app/Template/project/sidebar.php +++ b/app/Template/project/sidebar.php @@ -24,7 +24,7 @@ <li> <?= $this->a(t('Swimlanes'), 'swimlane', 'index', array('project_id' => $project['id'])) ?> </li> - <?php if ($project['is_private'] == 0): ?> + <?php if ($this->userSession->isAdmin() || $project['is_private'] == 0): ?> <li> <?= $this->a(t('User management'), 'project', 'users', array('project_id' => $project['id'])) ?> </li> diff --git a/app/Template/project/users.php b/app/Template/project/users.php index 5dc4a7e5..f223b8fa 100644 --- a/app/Template/project/users.php +++ b/app/Template/project/users.php @@ -13,12 +13,15 @@ <tr> <th><?= t('User') ?></th> <th><?= t('Role for this project') ?></th> - <th><?= t('Actions') ?></th> + <?php if ($project['is_private'] == 0): ?> + <th><?= t('Actions') ?></th> + <?php endif ?> </tr> <?php foreach ($users['allowed'] as $user_id => $username): ?> <tr> <td><?= $this->e($username) ?></td> <td><?= isset($users['managers'][$user_id]) ? t('Project manager') : t('Project member') ?></td> + <?php if ($project['is_private'] == 0): ?> <td> <ul> <li><?= $this->a(t('Revoke'), 'project', 'revoke', array('project_id' => $project['id'], 'user_id' => $user_id), true) ?></li> @@ -31,6 +34,7 @@ </li> </ul> </td> + <?php endif ?> </tr> <?php endforeach ?> </table> diff --git a/app/Template/subtask/remove.php b/app/Template/subtask/remove.php index af193c59..c623791d 100644 --- a/app/Template/subtask/remove.php +++ b/app/Template/subtask/remove.php @@ -10,7 +10,7 @@ <p><strong><?= $this->e($subtask['title']) ?></strong></p> <div class="form-actions"> - <?= $this->a(t('Yes'), 'subtask', 'remove', array('task_id' => $task['id'], 'subtask_id' => $subtask['id']), true, 'btn btn-red') ?> + <?= $this->a(t('Yes'), 'subtask', 'remove', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'subtask_id' => $subtask['id']), true, 'btn btn-red') ?> <?= t('or') ?> <?= $this->a(t('cancel'), 'task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])) ?> </div> diff --git a/app/Template/subtask/show.php b/app/Template/subtask/show.php index c0f61f0e..265883b7 100644 --- a/app/Template/subtask/show.php +++ b/app/Template/subtask/show.php @@ -44,10 +44,10 @@ <td> <ul> <li> - <?= $this->a(t('Edit'), 'subtask', 'edit', array('task_id' => $task['id'], 'subtask_id' => $subtask['id'])) ?> + <?= $this->a(t('Edit'), 'subtask', 'edit', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'subtask_id' => $subtask['id'])) ?> </li> <li> - <?= $this->a(t('Remove'), 'subtask', 'confirm', array('task_id' => $task['id'], 'subtask_id' => $subtask['id'])) ?> + <?= $this->a(t('Remove'), 'subtask', 'confirm', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'subtask_id' => $subtask['id'])) ?> </li> </ul> </td> diff --git a/composer.lock b/composer.lock index 58fbb7a0..5ef22913 100644 --- a/composer.lock +++ b/composer.lock @@ -88,12 +88,12 @@ "source": { "type": "git", "url": "https://github.com/fguillot/picoDb.git", - "reference": "3ee555da2e2bda42b5d6aa9b231b534fd69db96c" + "reference": "268b3389d2bc3c92ef749a63440d17bd75e2a628" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/fguillot/picoDb/zipball/3ee555da2e2bda42b5d6aa9b231b534fd69db96c", - "reference": "3ee555da2e2bda42b5d6aa9b231b534fd69db96c", + "url": "https://api.github.com/repos/fguillot/picoDb/zipball/268b3389d2bc3c92ef749a63440d17bd75e2a628", + "reference": "268b3389d2bc3c92ef749a63440d17bd75e2a628", "shasum": "" }, "require": { @@ -117,7 +117,7 @@ ], "description": "Minimalist database query builder", "homepage": "https://github.com/fguillot/picoDb", - "time": "2015-01-02 22:00:06" + "time": "2015-01-03 00:32:58" }, { "name": "fguillot/simple-validator", diff --git a/tests/functionals/ApiTest.php b/tests/functionals/ApiTest.php index eb1e0cd1..f778d1ca 100644 --- a/tests/functionals/ApiTest.php +++ b/tests/functionals/ApiTest.php @@ -26,10 +26,12 @@ class Api extends PHPUnit_Framework_TestCase } $service = new ServiceProvider\DatabaseProvider; - $service->getInstance(); - $pdo->exec("UPDATE settings SET value='".API_KEY."' WHERE option='api_token'"); - $pdo->exec("UPDATE settings SET value='Europe/Paris' WHERE option='application_timezone'"); + $db = $service->getInstance(); + $db->table('settings')->eq('option', 'api_token')->update(array('value' => API_KEY)); + $db->table('settings')->eq('option', 'application_timezone')->update(array('value' => 'Europe/Paris')); + $db->closeConnection(); + $pdo = null; } diff --git a/tests/units/ProjectDuplicateTest.php b/tests/units/ProjectDuplicateTest.php index 973a0c32..161bbe20 100644 --- a/tests/units/ProjectDuplicateTest.php +++ b/tests/units/ProjectDuplicateTest.php @@ -79,6 +79,40 @@ class ProjectDuplicationTest extends Base $this->assertEquals('C3', $categories[2]['name']); } - // TODO: test users - // TODO: test actions + public function testCloneProjectWithUsers() + { + $p = new Project($this->container); + $c = new Category($this->container); + $pp = new ProjectPermission($this->container); + $u = new User($this->container); + + $this->assertEquals(2, $u->create(array('username' => 'unittest1', 'password' => 'unittest'))); + $this->assertEquals(3, $u->create(array('username' => 'unittest2', 'password' => 'unittest'))); + $this->assertEquals(4, $u->create(array('username' => 'unittest3', 'password' => 'unittest'))); + + $this->assertEquals(1, $p->create(array('name' => 'P1'))); + $this->assertTrue($pp->addMember(1, 2)); + $this->assertTrue($pp->addMember(1, 4)); + $this->assertTrue($pp->addManager(1, 3)); + $this->assertTrue($pp->isMember(1, 2)); + $this->assertTrue($pp->isMember(1, 3)); + $this->assertTrue($pp->isMember(1, 4)); + $this->assertFalse($pp->isManager(1, 2)); + $this->assertTrue($pp->isManager(1, 3)); + $this->assertFalse($pp->isManager(1, 4)); + + $this->assertEquals(2, $p->duplicate(1)); + + $project = $p->getById(2); + $this->assertNotEmpty($project); + $this->assertEquals('P1 (Clone)', $project['name']); + + $this->assertEquals(3, count($pp->getMembers(2))); + $this->assertTrue($pp->isMember(2, 2)); + $this->assertTrue($pp->isMember(2, 3)); + $this->assertTrue($pp->isMember(2, 4)); + $this->assertFalse($pp->isManager(2, 2)); + $this->assertTrue($pp->isManager(2, 3)); + $this->assertFalse($pp->isManager(2, 4)); + } } diff --git a/tests/units/TaskCreationTest.php b/tests/units/TaskCreationTest.php index 41a3f276..bdb0a79d 100644 --- a/tests/units/TaskCreationTest.php +++ b/tests/units/TaskCreationTest.php @@ -48,11 +48,17 @@ class TaskCreationTest extends Base $this->container['dispatcher']->addListener(Task::EVENT_CREATE, function() {}); $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(0, $tc->create(array('project_id' => 1))); + $this->assertEquals(1, $tc->create(array('project_id' => 1))); $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayNotHasKey(Task::EVENT_CREATE_UPDATE.'.closure', $called); - $this->assertArrayNotHasKey(Task::EVENT_CREATE.'.closure', $called); + $this->assertArrayHasKey(Task::EVENT_CREATE_UPDATE.'.closure', $called); + $this->assertArrayHasKey(Task::EVENT_CREATE.'.closure', $called); + + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(1, $task['id']); + $this->assertEquals('Untitled', $task['title']); + $this->assertEquals(1, $task['project_id']); } public function testMinimum() |