Add option to allow everybody on a project

This commit is contained in:
Frédéric Guillot
2014-10-21 18:51:59 -04:00
parent 88a1120d9b
commit 2c056bb9bb
21 changed files with 213 additions and 44 deletions

View File

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

View File

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