summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog10
-rw-r--r--app/Controller/Group.php255
-rw-r--r--app/Model/Group.php151
-rw-r--r--app/Model/GroupMember.php95
-rw-r--r--app/Schema/Mysql.php24
-rw-r--r--app/Schema/Postgres.php23
-rw-r--r--app/Schema/Sqlite.php37
-rw-r--r--app/ServiceProvider/ClassProvider.php2
-rw-r--r--app/Template/group/associate.php25
-rw-r--r--app/Template/group/create.php19
-rw-r--r--app/Template/group/dissociate.php19
-rw-r--r--app/Template/group/edit.php22
-rw-r--r--app/Template/group/index.php45
-rw-r--r--app/Template/group/remove.php19
-rw-r--r--app/Template/group/users.php44
-rw-r--r--app/Template/user/create_local.php2
-rw-r--r--app/Template/user/index.php1
-rw-r--r--composer.json2
-rw-r--r--composer.lock82
-rw-r--r--tests/units/Model/GroupMemberTest.php76
-rw-r--r--tests/units/Model/GroupTest.php82
21 files changed, 994 insertions, 41 deletions
diff --git a/ChangeLog b/ChangeLog
index 56bbcdf4..ed94807d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+Version 1.0.22 (unreleased)
+---------------------------
+
+New features:
+
+* User groups (Teams)
+* Pluggable authentication and authorization system (Work in progress)
+* Add new project role Viewer (Work in progress)
+* Assign project permissions to a group (Work in progress)
+
Version 1.0.21
--------------
diff --git a/app/Controller/Group.php b/app/Controller/Group.php
new file mode 100644
index 00000000..4e81f6c1
--- /dev/null
+++ b/app/Controller/Group.php
@@ -0,0 +1,255 @@
+<?php
+
+namespace Kanboard\Controller;
+
+/**
+ * Group Controller
+ *
+ * @package controller
+ * @author Frederic Guillot
+ */
+class Group extends Base
+{
+ /**
+ * List all groups
+ *
+ * @access public
+ */
+ public function index()
+ {
+ $paginator = $this->paginator
+ ->setUrl('group', 'index')
+ ->setMax(30)
+ ->setOrder('name')
+ ->setQuery($this->group->getQuery())
+ ->calculate();
+
+ $this->response->html($this->template->layout('group/index', array(
+ 'board_selector' => $this->projectPermission->getAllowedProjects($this->userSession->getId()),
+ 'title' => t('Groups').' ('.$paginator->getTotal().')',
+ 'paginator' => $paginator,
+ )));
+ }
+
+ /**
+ * List all users
+ *
+ * @access public
+ */
+ public function users()
+ {
+ $group_id = $this->request->getIntegerParam('group_id');
+ $group = $this->group->getById($group_id);
+
+ $paginator = $this->paginator
+ ->setUrl('group', 'users')
+ ->setMax(30)
+ ->setOrder('username')
+ ->setQuery($this->groupMember->getQuery($group_id))
+ ->calculate();
+
+ $this->response->html($this->template->layout('group/users', array(
+ 'board_selector' => $this->projectPermission->getAllowedProjects($this->userSession->getId()),
+ 'title' => t('Members of %s', $group['name']).' ('.$paginator->getTotal().')',
+ 'paginator' => $paginator,
+ 'group' => $group,
+ )));
+ }
+
+ /**
+ * Display a form to create a new group
+ *
+ * @access public
+ */
+ public function create(array $values = array(), array $errors = array())
+ {
+ $this->response->html($this->template->layout('group/create', array(
+ 'board_selector' => $this->projectPermission->getAllowedProjects($this->userSession->getId()),
+ 'errors' => $errors,
+ 'values' => $values,
+ 'title' => t('New group')
+ )));
+ }
+
+ /**
+ * Validate and save a new group
+ *
+ * @access public
+ */
+ public function save()
+ {
+ $values = $this->request->getValues();
+ list($valid, $errors) = $this->group->validateCreation($values);
+
+ if ($valid) {
+ if ($this->group->create($values['name']) !== false) {
+ $this->flash->success(t('Group created successfully.'));
+ $this->response->redirect($this->helper->url->to('group', 'index'));
+ } else {
+ $this->flash->failure(t('Unable to create your group.'));
+ }
+ }
+
+ $this->create($values, $errors);
+ }
+
+ /**
+ * Display a form to update a group
+ *
+ * @access public
+ */
+ public function edit(array $values = array(), array $errors = array())
+ {
+ if (empty($values)) {
+ $values = $this->group->getById($this->request->getIntegerParam('group_id'));
+ }
+
+ $this->response->html($this->template->layout('group/edit', array(
+ 'board_selector' => $this->projectPermission->getAllowedProjects($this->userSession->getId()),
+ 'errors' => $errors,
+ 'values' => $values,
+ 'title' => t('Edit group')
+ )));
+ }
+
+ /**
+ * Validate and save a group
+ *
+ * @access public
+ */
+ public function update()
+ {
+ $values = $this->request->getValues();
+ list($valid, $errors) = $this->group->validateModification($values);
+
+ if ($valid) {
+ if ($this->group->update($values) !== false) {
+ $this->flash->success(t('Group updated successfully.'));
+ $this->response->redirect($this->helper->url->to('group', 'index'));
+ } else {
+ $this->flash->failure(t('Unable to update your group.'));
+ }
+ }
+
+ $this->edit($values, $errors);
+ }
+
+ /**
+ * Form to associate a user to a group
+ *
+ * @access public
+ */
+ public function associate(array $values = array(), array $errors = array())
+ {
+ $group_id = $this->request->getIntegerParam('group_id');
+ $group = $this->group->getbyId($group_id);
+
+ if (empty($values)) {
+ $values['group_id'] = $group_id;
+ }
+
+ $this->response->html($this->template->layout('group/associate', array(
+ 'board_selector' => $this->projectPermission->getAllowedProjects($this->userSession->getId()),
+ 'users' => $this->user->prepareList($this->groupMember->getNotMembers($group_id)),
+ 'group' => $group,
+ 'errors' => $errors,
+ 'values' => $values,
+ 'title' => t('Add group member to "%s"', $group['name']),
+ )));
+ }
+
+ /**
+ * Add user to a group
+ *
+ * @access public
+ */
+ public function addUser()
+ {
+ $values = $this->request->getValues();
+
+ if (isset($values['group_id']) && isset($values['user_id'])) {
+ if ($this->groupMember->addUser($values['group_id'], $values['user_id'])) {
+ $this->flash->success(t('Group member added successfully.'));
+ $this->response->redirect($this->helper->url->to('group', 'users', array('group_id' => $values['group_id'])));
+ } else {
+ $this->flash->failure(t('Unable to add group member.'));
+ }
+ }
+
+ $this->associate($values);
+ }
+
+ /**
+ * Confirmation dialog to remove a user from a group
+ *
+ * @access public
+ */
+ public function dissociate()
+ {
+ $group_id = $this->request->getIntegerParam('group_id');
+ $user_id = $this->request->getIntegerParam('user_id');
+ $group = $this->group->getById($group_id);
+ $user = $this->user->getById($user_id);
+
+ $this->response->html($this->template->layout('group/dissociate', array(
+ 'group' => $group,
+ 'user' => $user,
+ 'title' => t('Remove a user from group "%s', $group['name']),
+ )));
+ }
+
+ /**
+ * Remove a user from a group
+ *
+ * @access public
+ */
+ public function removeUser()
+ {
+ $this->checkCSRFParam();
+ $group_id = $this->request->getIntegerParam('group_id');
+ $user_id = $this->request->getIntegerParam('user_id');
+
+ if ($this->groupMember->removeUser($group_id, $user_id)) {
+ $this->flash->success(t('User removed successfully from this group.'));
+ } else {
+ $this->flash->failure(t('Unable to remove this user from the group.'));
+ }
+
+ $this->response->redirect($this->helper->url->to('group', 'users', array('group_id' => $group_id)));
+ }
+
+ /**
+ * Confirmation dialog to remove a group
+ *
+ * @access public
+ */
+ public function confirm()
+ {
+ $group_id = $this->request->getIntegerParam('group_id');
+ $group = $this->group->getById($group_id);
+
+ $this->response->html($this->template->layout('group/remove', array(
+ 'group' => $group,
+ 'title' => t('Remove group'),
+ )));
+ }
+
+ /**
+ * Remove a group
+ *
+ * @access public
+ */
+ public function remove()
+ {
+ $this->checkCSRFParam();
+ $group_id = $this->request->getIntegerParam('group_id');
+
+ if ($this->group->remove($group_id)) {
+ $this->flash->success(t('Group removed successfully.'));
+ } else {
+ $this->flash->failure(t('Unable to remove this group.'));
+ }
+
+ $this->response->redirect($this->helper->url->to('group', 'index'));
+ }
+}
diff --git a/app/Model/Group.php b/app/Model/Group.php
new file mode 100644
index 00000000..82a8887b
--- /dev/null
+++ b/app/Model/Group.php
@@ -0,0 +1,151 @@
+<?php
+
+namespace Kanboard\Model;
+
+use SimpleValidator\Validator;
+use SimpleValidator\Validators;
+
+/**
+ * Group Model
+ *
+ * @package model
+ * @author Frederic Guillot
+ */
+class Group extends Base
+{
+ /**
+ * SQL table name
+ *
+ * @var string
+ */
+ const TABLE = 'groups';
+
+ /**
+ * Get query to fetch all groups
+ *
+ * @access public
+ * @return \PicoDb\Table
+ */
+ public function getQuery()
+ {
+ return $this->db->table(self::TABLE);
+ }
+
+ /**
+ * Get a specific group by id
+ *
+ * @access public
+ * @param integer $group_id
+ * @return array
+ */
+ public function getById($group_id)
+ {
+ return $this->getQuery()->eq('id', $group_id)->findOne();
+ }
+
+ /**
+ * Get all groups
+ *
+ * @access public
+ * @return array
+ */
+ public function getAll()
+ {
+ return $this->getQuery()->asc('name')->findAll();
+ }
+
+ /**
+ * Remove a group
+ *
+ * @access public
+ * @param integer $group_id
+ * @return array
+ */
+ public function remove($group_id)
+ {
+ return $this->db->table(self::TABLE)->eq('id', $group_id)->remove();
+ }
+
+ /**
+ * Create a new group
+ *
+ * @access public
+ * @param string $name
+ * @param string $external_id
+ * @return integer|boolean
+ */
+ public function create($name, $external_id = '')
+ {
+ return $this->persist(self::TABLE, array(
+ 'name' => $name,
+ 'external_id' => $external_id,
+ ));
+ }
+
+ /**
+ * Update existing group
+ *
+ * @access public
+ * @param array $values
+ * @return boolean
+ */
+ public function update(array $values)
+ {
+ return $this->db->table(self::TABLE)->eq('id', $values['id'])->update($values);
+ }
+
+ /**
+ * Validate creation
+ *
+ * @access public
+ * @param array $values Form values
+ * @return array $valid, $errors [0] = Success or not, [1] = List of errors
+ */
+ public function validateCreation(array $values)
+ {
+ $v = new Validator($values, $this->commonValidationRules());
+
+ return array(
+ $v->execute(),
+ $v->getErrors()
+ );
+ }
+
+ /**
+ * Validate modification
+ *
+ * @access public
+ * @param array $values Form values
+ * @return array $valid, $errors [0] = Success or not, [1] = List of errors
+ */
+ public function validateModification(array $values)
+ {
+ $rules = array(
+ new Validators\Required('id', t('The id is required')),
+ );
+
+ $v = new Validator($values, array_merge($rules, $this->commonValidationRules()));
+
+ return array(
+ $v->execute(),
+ $v->getErrors()
+ );
+ }
+
+ /**
+ * Common validation rules
+ *
+ * @access private
+ * @return array
+ */
+ private function commonValidationRules()
+ {
+ return array(
+ new Validators\Required('name', t('The name is required')),
+ new Validators\MaxLength('name', t('The maximum length is %d characters', 100), 100),
+ new Validators\Unique('name', t('The name must be unique'), $this->db->getConnection(), self::TABLE, 'id'),
+ new Validators\MaxLength('external_id', t('The maximum length is %d characters', 255), 255),
+ new Validators\Integer('id', t('This value must be an integer')),
+ );
+ }
+}
diff --git a/app/Model/GroupMember.php b/app/Model/GroupMember.php
new file mode 100644
index 00000000..04e9d495
--- /dev/null
+++ b/app/Model/GroupMember.php
@@ -0,0 +1,95 @@
+<?php
+
+namespace Kanboard\Model;
+
+/**
+ * Group Member Model
+ *
+ * @package model
+ * @author Frederic Guillot
+ */
+class GroupMember extends Base
+{
+ /**
+ * SQL table name
+ *
+ * @var string
+ */
+ const TABLE = 'group_has_users';
+
+ /**
+ * Get query to fetch all users
+ *
+ * @access public
+ * @param integer $group_id
+ * @return \PicoDb\Table
+ */
+ public function getQuery($group_id)
+ {
+ return $this->db->table(self::TABLE)
+ ->join(User::TABLE, 'id', 'user_id')
+ ->eq('group_id', $group_id);
+ }
+
+ /**
+ * Get all users
+ *
+ * @access public
+ * @param integer $group_id
+ * @return array
+ */
+ public function getMembers($group_id)
+ {
+ return $this->getQuery($group_id)->findAll();
+ }
+
+ /**
+ * Get all not members
+ *
+ * @access public
+ * @param integer $group_id
+ * @return array
+ */
+ public function getNotMembers($group_id)
+ {
+ $subquery = $this->db->table(self::TABLE)
+ ->columns('user_id')
+ ->eq('group_id', $group_id);
+
+ return $this->db->table(User::TABLE)
+ ->notInSubquery('id', $subquery)
+ ->findAll();
+ }
+
+ /**
+ * Add user to a group
+ *
+ * @access public
+ * @param integer $group_id
+ * @param integer $user_id
+ * @return boolean
+ */
+ public function addUser($group_id, $user_id)
+ {
+ return $this->db->table(self::TABLE)->insert(array(
+ 'group_id' => $group_id,
+ 'user_id' => $user_id,
+ ));
+ }
+
+ /**
+ * Remove user from a group
+ *
+ * @access public
+ * @param integer $group_id
+ * @param integer $user_id
+ * @return boolean
+ */
+ public function removeUser($group_id, $user_id)
+ {
+ return $this->db->table(self::TABLE)
+ ->eq('group_id', $group_id)
+ ->eq('user_id', $user_id)
+ ->remove();
+ }
+}
diff --git a/app/Schema/Mysql.php b/app/Schema/Mysql.php
index 52a73fb1..5a451c77 100644
--- a/app/Schema/Mysql.php
+++ b/app/Schema/Mysql.php
@@ -5,7 +5,29 @@ namespace Schema;
use PDO;
use Kanboard\Core\Security\Token;
-const VERSION = 94;
+const VERSION = 95;
+
+function version_95(PDO $pdo)
+{
+ $pdo->exec("
+ CREATE TABLE groups (
+ id INT NOT NULL AUTO_INCREMENT,
+ external_id VARCHAR(255) DEFAULT '',
+ name VARCHAR(100) NOT NULL UNIQUE,
+ PRIMARY KEY(id)
+ ) ENGINE=InnoDB CHARSET=utf8
+ ");
+
+ $pdo->exec("
+ CREATE TABLE group_has_users (
+ group_id INT NOT NULL,
+ user_id INT NOT NULL,
+ FOREIGN KEY(group_id) REFERENCES groups(id) ON DELETE CASCADE,
+ FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE,
+ UNIQUE(group_id, user_id)
+ ) ENGINE=InnoDB CHARSET=utf8
+ ");
+}
function version_94(PDO $pdo)
{
diff --git a/app/Schema/Postgres.php b/app/Schema/Postgres.php
index 5cd1a7d0..a3887cfb 100644
--- a/app/Schema/Postgres.php
+++ b/app/Schema/Postgres.php
@@ -5,7 +5,28 @@ namespace Schema;
use PDO;
use Kanboard\Core\Security\Token;
-const VERSION = 74;
+const VERSION = 75;
+
+function version_75(PDO $pdo)
+{
+ $pdo->exec("
+ CREATE TABLE groups (
+ id SERIAL PRIMARY KEY,
+ external_id VARCHAR(255) DEFAULT '',
+ name VARCHAR(100) NOT NULL UNIQUE
+ )
+ ");
+
+ $pdo->exec("
+ CREATE TABLE group_has_users (
+ group_id INTEGER NOT NULL,
+ user_id INTEGER NOT NULL,
+ FOREIGN KEY(group_id) REFERENCES groups(id) ON DELETE CASCADE,
+ FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE,
+ UNIQUE(group_id, user_id)
+ )
+ ");
+}
function version_74(PDO $pdo)
{
diff --git a/app/Schema/Sqlite.php b/app/Schema/Sqlite.php
index fa26b158..f0510cff 100644
--- a/app/Schema/Sqlite.php
+++ b/app/Schema/Sqlite.php
@@ -5,7 +5,42 @@ namespace Schema;
use Kanboard\Core\Security\Token;
use PDO;
-const VERSION = 88;
+const VERSION = 89;
+
+function version_90(PDO $pdo)
+{
+ $pdo->exec("
+ CREATE TABLE project_has_groups (
+ group_id INTEGER NOT NULL,
+ project_id INTEGER NOT NULL,
+ role TEXT NOT NULL,
+ FOREIGN KEY(group_id) REFERENCES groups(id) ON DELETE CASCADE,
+ FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE,
+ UNIQUE(group_id, project_id)
+ )
+ ");
+}
+
+function version_89(PDO $pdo)
+{
+ $pdo->exec("
+ CREATE TABLE groups (
+ id INTEGER PRIMARY KEY,
+ external_id TEXT DEFAULT '',
+ name TEXT NOCASE NOT NULL UNIQUE
+ )
+ ");
+
+ $pdo->exec("
+ CREATE TABLE group_has_users (
+ group_id INTEGER NOT NULL,
+ user_id INTEGER NOT NULL,
+ FOREIGN KEY(group_id) REFERENCES groups(id) ON DELETE CASCADE,
+ FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE,
+ UNIQUE(group_id, user_id)
+ )
+ ");
+}
function version_88(PDO $pdo)
{
diff --git a/app/ServiceProvider/ClassProvider.php b/app/ServiceProvider/ClassProvider.php
index 9c9bc233..9ec81116 100644
--- a/app/ServiceProvider/ClassProvider.php
+++ b/app/ServiceProvider/ClassProvider.php
@@ -32,6 +32,8 @@ class ClassProvider implements ServiceProviderInterface
'Currency',
'CustomFilter',
'File',
+ 'Group',
+ 'GroupMember',
'LastLogin',
'Link',
'Notification',
diff --git a/app/Template/group/associate.php b/app/Template/group/associate.php
new file mode 100644
index 00000000..dc665bb3
--- /dev/null
+++ b/app/Template/group/associate.php
@@ -0,0 +1,25 @@
+<section id="main">
+ <div class="page-header">
+ <ul>
+ <li><i class="fa fa-users fa-fw"></i><?= $this->url->link(t('View all groups'), 'group', 'index') ?></li>
+ <li><i class="fa fa-user fa-fw"></i><?= $this->url->link(t('View group members'), 'group', 'users', array('group_id' => $group['id'])) ?></li>
+ </ul>
+ </div>
+ <?php if (empty($users)): ?>
+ <p class="alert"><?= t('There is no user available.') ?></p>
+ <?php else: ?>
+ <form method="post" action="<?= $this->url->href('group', 'addUser', array('group_id' => $group['id'])) ?>" autocomplete="off">
+ <?= $this->form->csrf() ?>
+ <?= $this->form->hidden('group_id', $values) ?>
+
+ <?= $this->form->label(t('User'), 'user_id') ?>
+ <?= $this->form->select('user_id', $users, $values, $errors, array('required'), 'chosen-select') ?><br/>
+
+ <div class="form-actions">
+ <input type="submit" value="<?= t('Save') ?>" class="btn btn-blue"/>
+ <?= t('or') ?>
+ <?= $this->url->link(t('cancel'), 'group', 'index') ?>
+ </div>
+ </form>
+ <?php endif ?>
+</section>
diff --git a/app/Template/group/create.php b/app/Template/group/create.php
new file mode 100644
index 00000000..696e5013
--- /dev/null
+++ b/app/Template/group/create.php
@@ -0,0 +1,19 @@
+<section id="main">
+ <div class="page-header">
+ <ul>
+ <li><i class="fa fa-users fa-fw"></i><?= $this->url->link(t('View all groups'), 'group', 'index') ?></li>
+ </ul>
+ </div>
+ <form method="post" action="<?= $this->url->href('group', 'save') ?>" autocomplete="off">
+ <?= $this->form->csrf() ?>
+
+ <?= $this->form->label(t('Name'), 'name') ?>
+ <?= $this->form->text('name', $values, $errors, array('autofocus', 'required', 'maxlength="100"')) ?><br/>
+
+ <div class="form-actions">
+ <input type="submit" value="<?= t('Save') ?>" class="btn btn-blue"/>
+ <?= t('or') ?>
+ <?= $this->url->link(t('cancel'), 'group', 'index') ?>
+ </div>
+ </form>
+</section>
diff --git a/app/Template/group/dissociate.php b/app/Template/group/dissociate.php
new file mode 100644
index 00000000..2b0b1af4
--- /dev/null
+++ b/app/Template/group/dissociate.php
@@ -0,0 +1,19 @@
+<section id="main">
+ <div class="page-header">
+ <?php if ($this->user->isAdmin()): ?>
+ <ul>
+ <li><i class="fa fa-users fa-fw"></i><?= $this->url->link(t('View all groups'), 'group', 'index') ?></li>
+ <li><i class="fa fa-user fa-fw"></i><?= $this->url->link(t('View group members'), 'group', 'users', array('group_id' => $group['id'])) ?></li>
+ </ul>
+ <?php endif ?>
+ </div>
+ <div class="confirm">
+ <p class="alert alert-info"><?= t('Do you really want to remove the user "%s" from the group "%s"?', $user['name'] ?: $user['username'], $group['name']) ?></p>
+
+ <div class="form-actions">
+ <?= $this->url->link(t('Yes'), 'group', 'removeUser', array('group_id' => $group['id'], 'user_id' => $user['id']), true, 'btn btn-red') ?>
+ <?= t('or') ?>
+ <?= $this->url->link(t('cancel'), 'group', 'users', array('group_id' => $group['id'])) ?>
+ </div>
+ </div>
+</section>
diff --git a/app/Template/group/edit.php b/app/Template/group/edit.php
new file mode 100644
index 00000000..4d7e5e81
--- /dev/null
+++ b/app/Template/group/edit.php
@@ -0,0 +1,22 @@
+<section id="main">
+ <div class="page-header">
+ <ul>
+ <li><i class="fa fa-users fa-fw"></i><?= $this->url->link(t('View all groups'), 'group', 'index') ?></li>
+ </ul>
+ </div>
+ <form method="post" action="<?= $this->url->href('group', 'update') ?>" autocomplete="off">
+ <?= $this->form->csrf() ?>
+
+ <?= $this->form->hidden('id', $values) ?>
+ <?= $this->form->hidden('external_id', $values) ?>
+
+ <?= $this->form->label(t('Name'), 'name') ?>
+ <?= $this->form->text('name', $values, $errors, array('autofocus', 'required', 'maxlength="100"')) ?><br/>
+
+ <div class="form-actions">
+ <input type="submit" value="<?= t('Save') ?>" class="btn btn-blue"/>
+ <?= t('or') ?>
+ <?= $this->url->link(t('cancel'), 'group', 'index') ?>
+ </div>
+ </form>
+</section>
diff --git a/app/Template/group/index.php b/app/Template/group/index.php
new file mode 100644
index 00000000..24de02a0
--- /dev/null
+++ b/app/Template/group/index.php
@@ -0,0 +1,45 @@
+<section id="main">
+ <div class="page-header">
+ <?php if ($this->user->isAdmin()): ?>
+ <ul>
+ <li><i class="fa fa-user fa-fw"></i><?= $this->url->link(t('All users'), 'user', 'index') ?></li>
+ <li><i class="fa fa-user-plus fa-fw"></i><?= $this->url->link(t('New group'), 'group', 'create') ?></li>
+ </ul>
+ <?php endif ?>
+ </div>
+ <?php if ($paginator->isEmpty()): ?>
+ <p class="alert"><?= t('There is no group.') ?></p>
+ <?php else: ?>
+ <table class="table-small">
+ <tr>
+ <th class="column-5"><?= $paginator->order(t('Id'), 'id') ?></th>
+ <th class="column-20"><?= $paginator->order(t('External Id'), 'external_id') ?></th>
+ <th><?= $paginator->order(t('Name'), 'name') ?></th>
+ <th class="column-20"><?= t('Actions') ?></th>
+ </tr>
+ <?php foreach ($paginator->getCollection() as $group): ?>
+ <tr>
+ <td>
+ #<?= $group['id'] ?>
+ </td>
+ <td>
+ <?= $this->e($group['external_id']) ?>
+ </td>
+ <td>
+ <?= $this->e($group['name']) ?>
+ </td>
+ <td>
+ <ul>
+ <li><?= $this->url->link(t('Add group member'), 'group', 'associate', array('group_id' => $group['id'])) ?></li>
+ <li><?= $this->url->link(t('Users'), 'group', 'users', array('group_id' => $group['id'])) ?></li>
+ <li><?= $this->url->link(t('Edit'), 'group', 'edit', array('group_id' => $group['id'])) ?></li>
+ <li><?= $this->url->link(t('Remove'), 'group', 'confirm', array('group_id' => $group['id'])) ?></li>
+ </ul>
+ </td>
+ </tr>
+ <?php endforeach ?>
+ </table>
+
+ <?= $paginator ?>
+ <?php endif ?>
+</section>
diff --git a/app/Template/group/remove.php b/app/Template/group/remove.php
new file mode 100644
index 00000000..48da91d5
--- /dev/null
+++ b/app/Template/group/remove.php
@@ -0,0 +1,19 @@
+<section id="main">
+ <div class="page-header">
+ <?php if ($this->user->isAdmin()): ?>
+ <ul>
+ <li><i class="fa fa-users fa-fw"></i><?= $this->url->link(t('View all groups'), 'group', 'index') ?></li>
+ <li><i class="fa fa-user fa-fw"></i><?= $this->url->link(t('View group members'), 'group', 'users', array('group_id' => $group['id'])) ?></li>
+ </ul>
+ <?php endif ?>
+ </div>
+ <div class="confirm">
+ <p class="alert alert-info"><?= t('Do you really want to remove this group: "%s"?', $group['name']) ?></p>
+
+ <div class="form-actions">
+ <?= $this->url->link(t('Yes'), 'group', 'remove', array('group_id' => $group['id']), true, 'btn btn-red') ?>
+ <?= t('or') ?>
+ <?= $this->url->link(t('cancel'), 'group', 'index') ?>
+ </div>
+ </div>
+</section>
diff --git a/app/Template/group/users.php b/app/Template/group/users.php
new file mode 100644
index 00000000..56ad82cf
--- /dev/null
+++ b/app/Template/group/users.php
@@ -0,0 +1,44 @@
+<section id="main">
+ <div class="page-header">
+ <?php if ($this->user->isAdmin()): ?>
+ <ul>
+ <li><i class="fa fa-users fa-fw"></i><?= $this->url->link(t('View all groups'), 'group', 'index') ?></li>
+ <li><i class="fa fa-plus fa-fw"></i><?= $this->url->link(t('Add group member'), 'group', 'associate', array('group_id' => $group['id'])) ?></li>
+ </ul>
+ <?php endif ?>
+ </div>
+ <?php if ($paginator->isEmpty()): ?>
+ <p class="alert"><?= t('There is no user in this group.') ?></p>
+ <?php else: ?>
+ <table>
+ <tr>
+ <th><?= $paginator->order(t('Id'), 'id') ?></th>
+ <th><?= $paginator->order(t('Username'), 'username') ?></th>
+ <th><?= $paginator->order(t('Name'), 'name') ?></th>
+ <th><?= $paginator->order(t('Email'), 'email') ?></th>
+ <th><?= t('Actions') ?></th>
+ </tr>
+ <?php foreach ($paginator->getCollection() as $user): ?>
+ <tr>
+ <td>
+ <?= $this->url->link('#'.$user['id'], 'user', 'show', array('user_id' => $user['id'])) ?>
+ </td>
+ <td>
+ <?= $this->url->link($this->e($user['username']), 'user', 'show', array('user_id' => $user['id'])) ?>
+ </td>
+ <td>
+ <?= $this->e($user['name']) ?>
+ </td>
+ <td>
+ <a href="mailto:<?= $this->e($user['email']) ?>"><?= $this->e($user['email']) ?></a>
+ </td>
+ <td>
+ <?= $this->url->link(t('Remove this user'), 'group', 'dissociate', array('group_id' => $group['id'], 'user_id' => $user['id'])) ?>
+ </td>
+ </tr>
+ <?php endforeach ?>
+ </table>
+
+ <?= $paginator ?>
+ <?php endif ?>
+</section>
diff --git a/app/Template/user/create_local.php b/app/Template/user/create_local.php
index 98c38f0d..6e6ca6ac 100644
--- a/app/Template/user/create_local.php
+++ b/app/Template/user/create_local.php
@@ -49,4 +49,4 @@
</div>
</form>
</section>
-</section> \ No newline at end of file
+</section>
diff --git a/app/Template/user/index.php b/app/Template/user/index.php
index 4008b920..7c6ecc1e 100644
--- a/app/Template/user/index.php
+++ b/app/Template/user/index.php
@@ -5,6 +5,7 @@
<li><i class="fa fa-plus fa-fw"></i><?= $this->url->link(t('New local user'), 'user', 'create') ?></li>
<li><i class="fa fa-plus fa-fw"></i><?= $this->url->link(t('New remote user'), 'user', 'create', array('remote' => 1)) ?></li>
<li><i class="fa fa-upload fa-fw"></i><?= $this->url->link(t('Import'), 'userImport', 'step1') ?></li>
+ <li><i class="fa fa-users fa-fw"></i><?= $this->url->link(t('View all groups'), 'group', 'index') ?></li>
</ul>
<?php endif ?>
</div>
diff --git a/composer.json b/composer.json
index e6dcee80..64cf84a4 100644
--- a/composer.json
+++ b/composer.json
@@ -16,7 +16,7 @@
"erusev/parsedown" : "1.5.4",
"fabiang/xmpp" : "0.6.1",
"fguillot/json-rpc" : "1.0.3",
- "fguillot/picodb" : "1.0.2",
+ "fguillot/picodb" : "dev-master",
"fguillot/simpleLogger" : "1.0.0",
"fguillot/simple-validator" : "1.0.0",
"league/html-to-markdown" : "~4.0",
diff --git a/composer.lock b/composer.lock
index 38869985..a7abe89f 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": "dedbdec5041e89f475dd55d5f11a9bd6",
+ "hash": "ccda1534fa372df2c12591d5fe72c6a8",
"packages": [
{
"name": "christian-riesen/base32",
@@ -296,16 +296,16 @@
},
{
"name": "fguillot/picodb",
- "version": "v1.0.2",
+ "version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/fguillot/picoDb.git",
- "reference": "61f492c125d9195ce869447e2b2450adeb3b01d6"
+ "reference": "2db9ce62ac3aa968fbbc24ee4d418cab21b5ed3f"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/fguillot/picoDb/zipball/61f492c125d9195ce869447e2b2450adeb3b01d6",
- "reference": "61f492c125d9195ce869447e2b2450adeb3b01d6",
+ "url": "https://api.github.com/repos/fguillot/picoDb/zipball/2db9ce62ac3aa968fbbc24ee4d418cab21b5ed3f",
+ "reference": "2db9ce62ac3aa968fbbc24ee4d418cab21b5ed3f",
"shasum": ""
},
"require": {
@@ -329,7 +329,7 @@
],
"description": "Minimalist database query builder",
"homepage": "https://github.com/fguillot/picoDb",
- "time": "2015-08-27 23:33:16"
+ "time": "2015-11-26 02:33:54"
},
{
"name": "fguillot/simple-validator",
@@ -454,16 +454,16 @@
},
{
"name": "league/html-to-markdown",
- "version": "4.0.1",
+ "version": "4.1.1",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/html-to-markdown.git",
- "reference": "c496c27e01b9dce310e03afbcdf783347738f67b"
+ "reference": "01bbfe039d9b97526e3f3a3ee32543fc1d8dba00"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/thephpleague/html-to-markdown/zipball/c496c27e01b9dce310e03afbcdf783347738f67b",
- "reference": "c496c27e01b9dce310e03afbcdf783347738f67b",
+ "url": "https://api.github.com/repos/thephpleague/html-to-markdown/zipball/01bbfe039d9b97526e3f3a3ee32543fc1d8dba00",
+ "reference": "01bbfe039d9b97526e3f3a3ee32543fc1d8dba00",
"shasum": ""
},
"require": {
@@ -472,13 +472,17 @@
"php": ">=5.3.3"
},
"require-dev": {
+ "mikehaertl/php-shellcommand": "~1.1.0",
"phpunit/phpunit": "4.*",
"scrutinizer/ocular": "~1.1"
},
+ "bin": [
+ "bin/html-to-markdown"
+ ],
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "4.1-dev"
+ "dev-master": "4.2-dev"
}
},
"autoload": {
@@ -510,7 +514,7 @@
"html",
"markdown"
],
- "time": "2015-09-01 22:39:54"
+ "time": "2015-11-20 16:20:25"
},
{
"name": "pimple/pimple",
@@ -651,16 +655,16 @@
},
{
"name": "symfony/console",
- "version": "v2.7.5",
+ "version": "v2.7.7",
"source": {
"type": "git",
"url": "https://github.com/symfony/console.git",
- "reference": "06cb17c013a82f94a3d840682b49425cd00a2161"
+ "reference": "16bb1cb86df43c90931df65f529e7ebd79636750"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/console/zipball/06cb17c013a82f94a3d840682b49425cd00a2161",
- "reference": "06cb17c013a82f94a3d840682b49425cd00a2161",
+ "url": "https://api.github.com/repos/symfony/console/zipball/16bb1cb86df43c90931df65f529e7ebd79636750",
+ "reference": "16bb1cb86df43c90931df65f529e7ebd79636750",
"shasum": ""
},
"require": {
@@ -669,7 +673,6 @@
"require-dev": {
"psr/log": "~1.0",
"symfony/event-dispatcher": "~2.1",
- "symfony/phpunit-bridge": "~2.7",
"symfony/process": "~2.1"
},
"suggest": {
@@ -686,7 +689,10 @@
"autoload": {
"psr-4": {
"Symfony\\Component\\Console\\": ""
- }
+ },
+ "exclude-from-classmap": [
+ "/Tests/"
+ ]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
@@ -704,20 +710,20 @@
],
"description": "Symfony Console Component",
"homepage": "https://symfony.com",
- "time": "2015-09-25 08:32:23"
+ "time": "2015-11-18 09:54:26"
},
{
"name": "symfony/event-dispatcher",
- "version": "v2.7.5",
+ "version": "v2.7.7",
"source": {
"type": "git",
"url": "https://github.com/symfony/event-dispatcher.git",
- "reference": "ae4dcc2a8d3de98bd794167a3ccda1311597c5d9"
+ "reference": "7e2f9c31645680026c2372edf66f863fc7757af5"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/ae4dcc2a8d3de98bd794167a3ccda1311597c5d9",
- "reference": "ae4dcc2a8d3de98bd794167a3ccda1311597c5d9",
+ "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/7e2f9c31645680026c2372edf66f863fc7757af5",
+ "reference": "7e2f9c31645680026c2372edf66f863fc7757af5",
"shasum": ""
},
"require": {
@@ -728,7 +734,6 @@
"symfony/config": "~2.0,>=2.0.5",
"symfony/dependency-injection": "~2.6",
"symfony/expression-language": "~2.6",
- "symfony/phpunit-bridge": "~2.7",
"symfony/stopwatch": "~2.3"
},
"suggest": {
@@ -744,7 +749,10 @@
"autoload": {
"psr-4": {
"Symfony\\Component\\EventDispatcher\\": ""
- }
+ },
+ "exclude-from-classmap": [
+ "/Tests/"
+ ]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
@@ -762,30 +770,27 @@
],
"description": "Symfony EventDispatcher Component",
"homepage": "https://symfony.com",
- "time": "2015-09-22 13:49:29"
+ "time": "2015-10-30 20:10:21"
}
],
"packages-dev": [
{
"name": "symfony/stopwatch",
- "version": "v2.7.5",
+ "version": "v2.7.7",
"source": {
"type": "git",
"url": "https://github.com/symfony/stopwatch.git",
- "reference": "08dd97b3f22ab9ee658cd16e6758f8c3c404336e"
+ "reference": "9fa59908b0c5575980a1623723a5b5cb38e0a04a"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/stopwatch/zipball/08dd97b3f22ab9ee658cd16e6758f8c3c404336e",
- "reference": "08dd97b3f22ab9ee658cd16e6758f8c3c404336e",
+ "url": "https://api.github.com/repos/symfony/stopwatch/zipball/9fa59908b0c5575980a1623723a5b5cb38e0a04a",
+ "reference": "9fa59908b0c5575980a1623723a5b5cb38e0a04a",
"shasum": ""
},
"require": {
"php": ">=5.3.9"
},
- "require-dev": {
- "symfony/phpunit-bridge": "~2.7"
- },
"type": "library",
"extra": {
"branch-alias": {
@@ -795,7 +800,10 @@
"autoload": {
"psr-4": {
"Symfony\\Component\\Stopwatch\\": ""
- }
+ },
+ "exclude-from-classmap": [
+ "/Tests/"
+ ]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
@@ -813,12 +821,14 @@
],
"description": "Symfony Stopwatch Component",
"homepage": "https://symfony.com",
- "time": "2015-09-22 13:49:29"
+ "time": "2015-10-30 20:10:21"
}
],
"aliases": [],
"minimum-stability": "stable",
- "stability-flags": [],
+ "stability-flags": {
+ "fguillot/picodb": 20
+ },
"prefer-stable": false,
"prefer-lowest": false,
"platform": {
diff --git a/tests/units/Model/GroupMemberTest.php b/tests/units/Model/GroupMemberTest.php
new file mode 100644
index 00000000..16f769e8
--- /dev/null
+++ b/tests/units/Model/GroupMemberTest.php
@@ -0,0 +1,76 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\Group;
+use Kanboard\Model\User;
+use Kanboard\Model\GroupMember;
+
+class GroupMemberTest extends Base
+{
+ public function testAddRemove()
+ {
+ $groupModel = new Group($this->container);
+ $groupMemberModel = new GroupMember($this->container);
+
+ $this->assertEquals(1, $groupModel->create('Test'));
+
+ $this->assertTrue($groupMemberModel->addUser(1, 1));
+ $this->assertFalse($groupMemberModel->addUser(1, 1));
+
+ $users = $groupMemberModel->getMembers(1);
+ $this->assertCount(1, $users);
+ $this->assertEquals('admin', $users[0]['username']);
+
+ $this->assertEmpty($groupMemberModel->getNotMembers(1));
+
+ $this->assertTrue($groupMemberModel->removeUser(1, 1));
+ $this->assertFalse($groupMemberModel->removeUser(1, 1));
+
+ $this->assertEmpty($groupMemberModel->getMembers(1));
+ }
+
+ public function testMembers()
+ {
+ $userModel = new User($this->container);
+ $groupModel = new Group($this->container);
+ $groupMemberModel = new GroupMember($this->container);
+
+ $this->assertEquals(1, $groupModel->create('Group A'));
+ $this->assertEquals(2, $groupModel->create('Group B'));
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
+ $this->assertEquals(3, $userModel->create(array('username' => 'user2')));
+ $this->assertEquals(4, $userModel->create(array('username' => 'user3')));
+ $this->assertEquals(5, $userModel->create(array('username' => 'user4')));
+
+ $this->assertTrue($groupMemberModel->addUser(1, 1));
+ $this->assertTrue($groupMemberModel->addUser(1, 2));
+ $this->assertTrue($groupMemberModel->addUser(1, 5));
+ $this->assertTrue($groupMemberModel->addUser(2, 3));
+ $this->assertTrue($groupMemberModel->addUser(2, 4));
+ $this->assertTrue($groupMemberModel->addUser(2, 5));
+
+ $users = $groupMemberModel->getMembers(1);
+ $this->assertCount(3, $users);
+ $this->assertEquals('admin', $users[0]['username']);
+ $this->assertEquals('user1', $users[1]['username']);
+ $this->assertEquals('user4', $users[2]['username']);
+
+ $users = $groupMemberModel->getNotMembers(1);
+ $this->assertCount(2, $users);
+ $this->assertEquals('user2', $users[0]['username']);
+ $this->assertEquals('user3', $users[1]['username']);
+
+ $users = $groupMemberModel->getMembers(2);
+ $this->assertCount(3, $users);
+ $this->assertEquals('user2', $users[0]['username']);
+ $this->assertEquals('user3', $users[1]['username']);
+ $this->assertEquals('user4', $users[2]['username']);
+
+ $users = $groupMemberModel->getNotMembers(2);
+ $this->assertCount(2, $users);
+ $this->assertEquals('admin', $users[0]['username']);
+ $this->assertEquals('user1', $users[1]['username']);
+ }
+}
diff --git a/tests/units/Model/GroupTest.php b/tests/units/Model/GroupTest.php
new file mode 100644
index 00000000..2cbb254a
--- /dev/null
+++ b/tests/units/Model/GroupTest.php
@@ -0,0 +1,82 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\Group;
+
+class GroupTest extends Base
+{
+ public function testCreation()
+ {
+ $groupModel = new Group($this->container);
+ $this->assertEquals(1, $groupModel->create('Test'));
+ $this->assertFalse($groupModel->create('Test'));
+ }
+
+ public function testGetById()
+ {
+ $groupModel = new Group($this->container);
+ $this->assertEquals(1, $groupModel->create('Test'));
+
+ $group = $groupModel->getById(1);
+ $this->assertEquals('Test', $group['name']);
+ $this->assertEquals('', $group['external_id']);
+
+ $this->assertEmpty($groupModel->getById(2));
+ }
+
+ public function testGetAll()
+ {
+ $groupModel = new Group($this->container);
+ $this->assertEquals(1, $groupModel->create('B'));
+ $this->assertEquals(2, $groupModel->create('A', 'uuid'));
+
+ $groups = $groupModel->getAll();
+ $this->assertCount(2, $groups);
+ $this->assertEquals('A', $groups[0]['name']);
+ $this->assertEquals('uuid', $groups[0]['external_id']);
+ $this->assertEquals('B', $groups[1]['name']);
+ $this->assertEquals('', $groups[1]['external_id']);
+ }
+
+ public function testUpdate()
+ {
+ $groupModel = new Group($this->container);
+ $this->assertEquals(1, $groupModel->create('Test'));
+ $this->assertTrue($groupModel->update(array('id' => 1, 'name' => 'My group', 'external_id' => 'test')));
+
+ $group = $groupModel->getById(1);
+ $this->assertEquals('My group', $group['name']);
+ $this->assertEquals('test', $group['external_id']);
+ }
+
+ public function testRemove()
+ {
+ $groupModel = new Group($this->container);
+ $this->assertEquals(1, $groupModel->create('Test'));
+ $this->assertTrue($groupModel->remove(1));
+ $this->assertEmpty($groupModel->getById(1));
+ }
+
+ public function testValidateCreation()
+ {
+ $groupModel = new Group($this->container);
+
+ $result = $groupModel->validateCreation(array('name' => 'Test'));
+ $this->assertTrue($result[0]);
+
+ $result = $groupModel->validateCreation(array('name' => ''));
+ $this->assertFalse($result[0]);
+ }
+
+ public function testValidateModification()
+ {
+ $groupModel = new Group($this->container);
+
+ $result = $groupModel->validateModification(array('name' => 'Test', 'id' => 1));
+ $this->assertTrue($result[0]);
+
+ $result = $groupModel->validateModification(array('name' => 'Test'));
+ $this->assertFalse($result[0]);
+ }
+}