Add option to allow everybody on a project
This commit is contained in:
parent
88a1120d9b
commit
2c056bb9bb
|
|
@ -183,6 +183,30 @@ class Project extends Base
|
|||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow everybody
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function allowEverybody()
|
||||
{
|
||||
$project = $this->getProjectManagement();
|
||||
$values = $this->request->getValues() + array('is_everybody_allowed' => 0);
|
||||
list($valid,) = $this->projectPermission->validateProjectModification($values);
|
||||
|
||||
if ($valid) {
|
||||
|
||||
if ($this->project->update($values)) {
|
||||
$this->session->flash(t('Project updated successfully.'));
|
||||
}
|
||||
else {
|
||||
$this->session->flashError(t('Unable to update this project.'));
|
||||
}
|
||||
}
|
||||
|
||||
$this->response->redirect('?controller=project&action=users&project_id='.$project['id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow a specific user (admin only)
|
||||
*
|
||||
|
|
@ -191,7 +215,7 @@ class Project extends Base
|
|||
public function allow()
|
||||
{
|
||||
$values = $this->request->getValues();
|
||||
list($valid,) = $this->projectPermission->validateModification($values);
|
||||
list($valid,) = $this->projectPermission->validateUserModification($values);
|
||||
|
||||
if ($valid) {
|
||||
|
||||
|
|
|
|||
|
|
@ -549,4 +549,6 @@ return array(
|
|||
// 'Activity stream' => '',
|
||||
// 'Dashboard' => '',
|
||||
// 'Confirmation' => '',
|
||||
// 'Allow everybody to access to this project' => '',
|
||||
// 'Everybody have access to this project.' => '',
|
||||
);
|
||||
|
|
|
|||
|
|
@ -549,4 +549,6 @@ return array(
|
|||
// 'Activity stream' => '',
|
||||
// 'Dashboard' => '',
|
||||
// 'Confirmation' => '',
|
||||
// 'Allow everybody to access to this project' => '',
|
||||
// 'Everybody have access to this project.' => '',
|
||||
);
|
||||
|
|
|
|||
|
|
@ -549,4 +549,6 @@ return array(
|
|||
// 'Activity stream' => '',
|
||||
// 'Dashboard' => '',
|
||||
// 'Confirmation' => '',
|
||||
// 'Allow everybody to access to this project' => '',
|
||||
// 'Everybody have access to this project.' => '',
|
||||
);
|
||||
|
|
|
|||
|
|
@ -549,4 +549,6 @@ return array(
|
|||
// 'Activity stream' => '',
|
||||
// 'Dashboard' => '',
|
||||
// 'Confirmation' => '',
|
||||
// 'Allow everybody to access to this project' => '',
|
||||
// 'Everybody have access to this project.' => '',
|
||||
);
|
||||
|
|
|
|||
|
|
@ -549,4 +549,6 @@ return array(
|
|||
'Activity stream' => 'Flux d\'activité',
|
||||
'Dashboard' => 'Tableau de bord',
|
||||
'Confirmation' => 'Confirmation',
|
||||
'Allow everybody to access to this project' => 'Autoriser tout le monde à accéder à ce projet',
|
||||
'Everybody have access to this project.' => 'Tout le monde a acccès à ce projet.',
|
||||
);
|
||||
|
|
|
|||
|
|
@ -549,4 +549,6 @@ return array(
|
|||
// 'Activity stream' => '',
|
||||
// 'Dashboard' => '',
|
||||
// 'Confirmation' => '',
|
||||
// 'Allow everybody to access to this project' => '',
|
||||
// 'Everybody have access to this project.' => '',
|
||||
);
|
||||
|
|
|
|||
|
|
@ -549,4 +549,6 @@ return array(
|
|||
// 'Activity stream' => '',
|
||||
// 'Dashboard' => '',
|
||||
// 'Confirmation' => '',
|
||||
// 'Allow everybody to access to this project' => '',
|
||||
// 'Everybody have access to this project.' => '',
|
||||
);
|
||||
|
|
|
|||
|
|
@ -549,4 +549,6 @@ return array(
|
|||
// 'Activity stream' => '',
|
||||
// 'Dashboard' => '',
|
||||
// 'Confirmation' => '',
|
||||
// 'Allow everybody to access to this project' => '',
|
||||
// 'Everybody have access to this project.' => '',
|
||||
);
|
||||
|
|
|
|||
|
|
@ -549,4 +549,6 @@ return array(
|
|||
// 'Activity stream' => '',
|
||||
// 'Dashboard' => '',
|
||||
// 'Confirmation' => '',
|
||||
// 'Allow everybody to access to this project' => '',
|
||||
// 'Everybody have access to this project.' => '',
|
||||
);
|
||||
|
|
|
|||
|
|
@ -549,4 +549,6 @@ return array(
|
|||
'Activity stream' => 'Текущая активность',
|
||||
'Dashboard' => 'Инфопанель',
|
||||
'Confirmation' => 'Подтверждение пароля',
|
||||
// 'Allow everybody to access to this project' => '',
|
||||
// 'Everybody have access to this project.' => '',
|
||||
);
|
||||
|
|
|
|||
|
|
@ -549,4 +549,6 @@ return array(
|
|||
'Activity stream' => 'Aktivitetsström',
|
||||
'Dashboard' => 'Instrumentpanel',
|
||||
'Confirmation' => 'Bekräftelse',
|
||||
// 'Allow everybody to access to this project' => '',
|
||||
// 'Everybody have access to this project.' => '',
|
||||
);
|
||||
|
|
|
|||
|
|
@ -549,4 +549,6 @@ return array(
|
|||
'Activity stream' => '活动流',
|
||||
'Dashboard' => '面板',
|
||||
'Confirmation' => '确认',
|
||||
// 'Allow everybody to access to this project' => '',
|
||||
// 'Everybody have access to this project.' => '',
|
||||
);
|
||||
|
|
|
|||
|
|
@ -52,6 +52,22 @@ class ProjectPermission extends Base
|
|||
* @return array
|
||||
*/
|
||||
public function getAllowedUsers($project_id)
|
||||
{
|
||||
if ($this->isEverybodyAllowed($project_id)) {
|
||||
return $this->user->getList();
|
||||
}
|
||||
|
||||
return $this->getAssociatedUsers($project_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of people associated to the project
|
||||
*
|
||||
* @access public
|
||||
* @param integer $project_id Project id
|
||||
* @return array
|
||||
*/
|
||||
public function getAssociatedUsers($project_id)
|
||||
{
|
||||
$users = $this->db
|
||||
->table(self::TABLE)
|
||||
|
|
@ -61,15 +77,7 @@ class ProjectPermission extends Base
|
|||
->columns(User::TABLE.'.id', User::TABLE.'.username', User::TABLE.'.name')
|
||||
->findAll();
|
||||
|
||||
$result = array();
|
||||
|
||||
foreach ($users as $user) {
|
||||
$result[$user['id']] = $user['name'] ?: $user['username'];
|
||||
}
|
||||
|
||||
asort($result);
|
||||
|
||||
return $result;
|
||||
return $this->user->prepareList($users);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -146,6 +154,10 @@ class ProjectPermission extends Base
|
|||
return true;
|
||||
}
|
||||
|
||||
if ($this->isEverybodyAllowed($project_id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return (bool) $this->db
|
||||
->table(self::TABLE)
|
||||
->eq('project_id', $project_id)
|
||||
|
|
@ -153,6 +165,22 @@ class ProjectPermission extends Base
|
|||
->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if everybody is allowed for the project
|
||||
*
|
||||
* @access public
|
||||
* @param integer $project_id Project id
|
||||
* @return bool
|
||||
*/
|
||||
public function isEverybodyAllowed($project_id)
|
||||
{
|
||||
return (bool) $this->db
|
||||
->table(Project::TABLE)
|
||||
->eq('id', $project_id)
|
||||
->eq('is_everybody_allowed', 1)
|
||||
->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a specific user is allowed to manage a project
|
||||
*
|
||||
|
|
@ -223,13 +251,13 @@ class ProjectPermission extends Base
|
|||
}
|
||||
|
||||
/**
|
||||
* Validate allowed users
|
||||
* Validate allow user
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Form values
|
||||
* @return array $valid, $errors [0] = Success or not, [1] = List of errors
|
||||
*/
|
||||
public function validateModification(array $values)
|
||||
public function validateUserModification(array $values)
|
||||
{
|
||||
$v = new Validator($values, array(
|
||||
new Validators\Required('project_id', t('The project id is required')),
|
||||
|
|
@ -243,4 +271,25 @@ class ProjectPermission extends Base
|
|||
$v->getErrors()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate allow everybody
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Form values
|
||||
* @return array $valid, $errors [0] = Success or not, [1] = List of errors
|
||||
*/
|
||||
public function validateProjectModification(array $values)
|
||||
{
|
||||
$v = new Validator($values, array(
|
||||
new Validators\Required('id', t('The project id is required')),
|
||||
new Validators\Integer('id', t('This value must be an integer')),
|
||||
new Validators\Integer('is_everybody_allowed', t('This value must be an integer')),
|
||||
));
|
||||
|
||||
return array(
|
||||
$v->execute(),
|
||||
$v->getErrors()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -151,7 +151,18 @@ class User extends Base
|
|||
public function getList()
|
||||
{
|
||||
$users = $this->db->table(self::TABLE)->columns('id', 'username', 'name')->findAll();
|
||||
return $this->prepareList($users);
|
||||
}
|
||||
|
||||
/**
|
||||
* Common method to prepare a user list
|
||||
*
|
||||
* @access public
|
||||
* @param array $users Users list (from database)
|
||||
* @return array Formated list
|
||||
*/
|
||||
public function prepareList(array $users)
|
||||
{
|
||||
$result = array();
|
||||
|
||||
foreach ($users as $user) {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,12 @@ namespace Schema;
|
|||
use PDO;
|
||||
use Core\Security;
|
||||
|
||||
const VERSION = 33;
|
||||
const VERSION = 34;
|
||||
|
||||
function version_34($pdo)
|
||||
{
|
||||
$pdo->exec("ALTER TABLE projects ADD COLUMN is_everybody_allowed TINYINT(1) DEFAULT '0'");
|
||||
}
|
||||
|
||||
function version_33($pdo)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,7 +5,12 @@ namespace Schema;
|
|||
use PDO;
|
||||
use Core\Security;
|
||||
|
||||
const VERSION = 14;
|
||||
const VERSION = 15;
|
||||
|
||||
function version_15($pdo)
|
||||
{
|
||||
$pdo->exec("ALTER TABLE projects ADD COLUMN is_everybody_allowed BOOLEAN DEFAULT '0'");
|
||||
}
|
||||
|
||||
function version_14($pdo)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,7 +5,12 @@ namespace Schema;
|
|||
use Core\Security;
|
||||
use PDO;
|
||||
|
||||
const VERSION = 33;
|
||||
const VERSION = 34;
|
||||
|
||||
function version_34($pdo)
|
||||
{
|
||||
$pdo->exec('ALTER TABLE projects ADD COLUMN is_everybody_allowed INTEGER DEFAULT "0"');
|
||||
}
|
||||
|
||||
function version_33($pdo)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,37 +2,56 @@
|
|||
<h2><?= t('List of authorized users') ?></h2>
|
||||
</div>
|
||||
|
||||
<?php if (empty($users['allowed'])): ?>
|
||||
<div class="alert alert-info"><?= t('Nobody have access to this project.') ?></div>
|
||||
<?php if ($project['is_everybody_allowed']): ?>
|
||||
<div class="alert alert-info"><?= t('Everybody have access to this project.') ?></div>
|
||||
<?php else: ?>
|
||||
<div class="listing">
|
||||
<p><?= t('Only those users have access to this project:') ?></p>
|
||||
<ul>
|
||||
<?php foreach ($users['allowed'] as $user_id => $username): ?>
|
||||
<li>
|
||||
<strong><?= Helper\escape($username) ?></strong>
|
||||
<?php if ($project['is_private'] == 0): ?>
|
||||
(<a href="?controller=project&action=revoke&project_id=<?= $project['id'] ?>&user_id=<?= $user_id.Helper\param_csrf() ?>"><?= t('revoke') ?></a>)
|
||||
<?php endif ?>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<p><?= t('Don\'t forget that administrators have access to everything.') ?></p>
|
||||
</div>
|
||||
|
||||
<?php if (empty($users['allowed'])): ?>
|
||||
<div class="alert alert-error"><?= t('Nobody have access to this project.') ?></div>
|
||||
<?php else: ?>
|
||||
<div class="listing">
|
||||
<p><?= t('Only those users have access to this project:') ?></p>
|
||||
<ul>
|
||||
<?php foreach ($users['allowed'] as $user_id => $username): ?>
|
||||
<li>
|
||||
<strong><?= Helper\escape($username) ?></strong>
|
||||
<?php if ($project['is_private'] == 0): ?>
|
||||
(<?= Helper\a(t('revoke'), 'project', 'revoke', array('project_id' => $project['id'], 'user_id' => $user_id), true) ?>)
|
||||
<?php endif ?>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<p><?= t('Don\'t forget that administrators have access to everything.') ?></p>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
|
||||
<?php if ($project['is_private'] == 0 && ! empty($users['not_allowed'])): ?>
|
||||
<form method="post" action="<?= Helper\u('project', 'allow', array('project_id' => $project['id'])) ?>" autocomplete="off">
|
||||
|
||||
<?= Helper\form_csrf() ?>
|
||||
|
||||
<?= Helper\form_hidden('project_id', array('project_id' => $project['id'])) ?>
|
||||
|
||||
<?= Helper\form_label(t('User'), 'user_id') ?>
|
||||
<?= Helper\form_select('user_id', $users['not_allowed']) ?><br/>
|
||||
|
||||
<div class="form-actions">
|
||||
<input type="submit" value="<?= t('Allow this user') ?>" class="btn btn-blue"/>
|
||||
</div>
|
||||
</form>
|
||||
<?php endif ?>
|
||||
|
||||
<?php endif ?>
|
||||
|
||||
<?php if ($project['is_private'] == 0 && ! empty($users['not_allowed'])): ?>
|
||||
<form method="post" action="?controller=project&action=allow&project_id=<?= $project['id'] ?>" autocomplete="off">
|
||||
<?php if ($project['is_private'] == 0): ?>
|
||||
<form method="post" action="<?= Helper\u('project', 'allowEverybody', array('project_id' => $project['id'])) ?>">
|
||||
<?= Helper\form_csrf() ?>
|
||||
|
||||
<?= Helper\form_csrf() ?>
|
||||
<?= Helper\form_hidden('id', array('id' => $project['id'])) ?>
|
||||
<?= Helper\form_checkbox('is_everybody_allowed', t('Allow everybody to access to this project'), 1, $project['is_everybody_allowed']) ?>
|
||||
|
||||
<?= Helper\form_hidden('project_id', array('project_id' => $project['id'])) ?>
|
||||
|
||||
<?= Helper\form_label(t('User'), 'user_id') ?>
|
||||
<?= Helper\form_select('user_id', $users['not_allowed']) ?><br/>
|
||||
|
||||
<div class="form-actions">
|
||||
<input type="submit" value="<?= t('Allow this user') ?>" class="btn btn-blue"/>
|
||||
</div>
|
||||
</form>
|
||||
<?php endif ?>
|
||||
<div class="form-actions">
|
||||
<input type="submit" value="<?= t('Save') ?>" class="btn btn-blue"/>
|
||||
</div>
|
||||
</form>
|
||||
<?php endif ?>
|
||||
|
|
|
|||
|
|
@ -589,6 +589,7 @@ a.filter-on {
|
|||
#board th a {
|
||||
text-decoration: none;
|
||||
font-size: 150%;
|
||||
color: #3366CC;
|
||||
}
|
||||
|
||||
#board td {
|
||||
|
|
|
|||
|
|
@ -8,6 +8,32 @@ use Model\User;
|
|||
|
||||
class ProjectPermissionTest extends Base
|
||||
{
|
||||
public function testAllowEverybody()
|
||||
{
|
||||
$user = new User($this->registry);
|
||||
$this->assertTrue($user->create(array('username' => 'unittest#1', 'password' => 'unittest')));
|
||||
$this->assertTrue($user->create(array('username' => 'unittest#2', 'password' => 'unittest')));
|
||||
|
||||
$p = new Project($this->registry);
|
||||
$pp = new ProjectPermission($this->registry);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
|
||||
$this->assertFalse($pp->isEverybodyAllowed(1));
|
||||
$this->assertTrue($pp->isUserAllowed(1, 1));
|
||||
$this->assertFalse($pp->isUserAllowed(1, 2));
|
||||
$this->assertFalse($pp->isUserAllowed(1, 3));
|
||||
$this->assertEquals(array(), $pp->getAllowedUsers(1));
|
||||
$this->assertEquals(array('Unassigned'), $pp->getUsersList(1));
|
||||
|
||||
$this->assertTrue($p->update(array('id' => 1, 'is_everybody_allowed' => 1)));
|
||||
$this->assertTrue($pp->isEverybodyAllowed(1));
|
||||
$this->assertTrue($pp->isUserAllowed(1, 1));
|
||||
$this->assertTrue($pp->isUserAllowed(1, 2));
|
||||
$this->assertTrue($pp->isUserAllowed(1, 3));
|
||||
$this->assertEquals(array('1' => 'admin', '2' => 'unittest#1', '3' => 'unittest#2'), $pp->getAllowedUsers(1));
|
||||
$this->assertEquals(array('Unassigned', '1' => 'admin', '2' => 'unittest#1', '3' => 'unittest#2'), $pp->getUsersList(1));
|
||||
}
|
||||
|
||||
public function testDisallowEverybody()
|
||||
{
|
||||
// We create a regular user
|
||||
|
|
|
|||
Loading…
Reference in New Issue