summaryrefslogtreecommitdiff
path: root/app/Model/ProjectPermission.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/Model/ProjectPermission.php')
-rw-r--r--app/Model/ProjectPermission.php71
1 files changed, 60 insertions, 11 deletions
diff --git a/app/Model/ProjectPermission.php b/app/Model/ProjectPermission.php
index b4466c20..fb9847b5 100644
--- a/app/Model/ProjectPermission.php
+++ b/app/Model/ProjectPermission.php
@@ -53,6 +53,22 @@ class ProjectPermission extends Base
*/
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)
->join(User::TABLE, 'id', 'user_id')
@@ -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)
@@ -154,6 +166,22 @@ class ProjectPermission extends Base
}
/**
+ * 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
*
* @access public
@@ -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()
+ );
+ }
}