Various fixes and improvements

This commit is contained in:
Frédéric Guillot 2015-01-02 21:11:19 -05:00
parent 3076ba22dd
commit 45c95d74fc
15 changed files with 100 additions and 46 deletions

View File

@ -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()
{

View File

@ -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);
}
/**

View File

@ -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.'));

View File

@ -14,6 +14,7 @@ use Parsedown;
* @property \Core\Session $session
* @property \Model\Acl $acl
* @property \Model\User $user
* @property \Model\UserSession $userSession
*/
class Helper
{

View File

@ -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);
$rows = $this->db
->table(self::TABLE)
->columns('project_id', 'user_id', 'is_owner')
->eq('project_id', $project_src)
->findAll();
foreach ($users as $user_id => $name) {
if (! $this->addMember($project_to, $user_id)) { // TODO: Duplicate managers
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;
}
}

View File

@ -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'];

View File

@ -39,7 +39,7 @@
'controller' => 'task',
'action' => 'show',
'params' => array(
'project_id' => $project['id']
'project_id' => $task['project_id']
)
)
) ?>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

8
composer.lock generated
View File

@ -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",

View File

@ -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;
}

View File

@ -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));
}
}

View File

@ -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()