From 2c056bb9bbfd22c7c2225964d994c79a60b7f64d Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Tue, 21 Oct 2014 18:51:59 -0400 Subject: Add option to allow everybody on a project --- app/Controller/Project.php | 26 ++++++++++++- app/Locales/da_DK/translations.php | 2 + app/Locales/de_DE/translations.php | 2 + app/Locales/es_ES/translations.php | 2 + app/Locales/fi_FI/translations.php | 2 + app/Locales/fr_FR/translations.php | 2 + app/Locales/it_IT/translations.php | 2 + app/Locales/ja_JP/translations.php | 2 + app/Locales/pl_PL/translations.php | 2 + app/Locales/pt_BR/translations.php | 2 + app/Locales/ru_RU/translations.php | 2 + app/Locales/sv_SE/translations.php | 2 + app/Locales/zh_CN/translations.php | 2 + app/Model/ProjectPermission.php | 71 ++++++++++++++++++++++++++++++------ app/Model/User.php | 11 ++++++ app/Schema/Mysql.php | 7 +++- app/Schema/Postgres.php | 7 +++- app/Schema/Sqlite.php | 7 +++- app/Templates/project_users.php | 75 ++++++++++++++++++++++++-------------- 19 files changed, 185 insertions(+), 43 deletions(-) (limited to 'app') diff --git a/app/Controller/Project.php b/app/Controller/Project.php index a4ebdbc0..2b0258d5 100644 --- a/app/Controller/Project.php +++ b/app/Controller/Project.php @@ -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) { diff --git a/app/Locales/da_DK/translations.php b/app/Locales/da_DK/translations.php index 210876ce..3032b6cf 100644 --- a/app/Locales/da_DK/translations.php +++ b/app/Locales/da_DK/translations.php @@ -549,4 +549,6 @@ return array( // 'Activity stream' => '', // 'Dashboard' => '', // 'Confirmation' => '', + // 'Allow everybody to access to this project' => '', + // 'Everybody have access to this project.' => '', ); diff --git a/app/Locales/de_DE/translations.php b/app/Locales/de_DE/translations.php index e8f4f53f..5f860c44 100644 --- a/app/Locales/de_DE/translations.php +++ b/app/Locales/de_DE/translations.php @@ -549,4 +549,6 @@ return array( // 'Activity stream' => '', // 'Dashboard' => '', // 'Confirmation' => '', + // 'Allow everybody to access to this project' => '', + // 'Everybody have access to this project.' => '', ); diff --git a/app/Locales/es_ES/translations.php b/app/Locales/es_ES/translations.php index ffaeaf2d..d24cdfcf 100644 --- a/app/Locales/es_ES/translations.php +++ b/app/Locales/es_ES/translations.php @@ -549,4 +549,6 @@ return array( // 'Activity stream' => '', // 'Dashboard' => '', // 'Confirmation' => '', + // 'Allow everybody to access to this project' => '', + // 'Everybody have access to this project.' => '', ); diff --git a/app/Locales/fi_FI/translations.php b/app/Locales/fi_FI/translations.php index 1c1b3439..4811b832 100644 --- a/app/Locales/fi_FI/translations.php +++ b/app/Locales/fi_FI/translations.php @@ -549,4 +549,6 @@ return array( // 'Activity stream' => '', // 'Dashboard' => '', // 'Confirmation' => '', + // 'Allow everybody to access to this project' => '', + // 'Everybody have access to this project.' => '', ); diff --git a/app/Locales/fr_FR/translations.php b/app/Locales/fr_FR/translations.php index 5809ef69..4f19ebd1 100644 --- a/app/Locales/fr_FR/translations.php +++ b/app/Locales/fr_FR/translations.php @@ -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.', ); diff --git a/app/Locales/it_IT/translations.php b/app/Locales/it_IT/translations.php index d933d5c7..4d2cfc91 100644 --- a/app/Locales/it_IT/translations.php +++ b/app/Locales/it_IT/translations.php @@ -549,4 +549,6 @@ return array( // 'Activity stream' => '', // 'Dashboard' => '', // 'Confirmation' => '', + // 'Allow everybody to access to this project' => '', + // 'Everybody have access to this project.' => '', ); diff --git a/app/Locales/ja_JP/translations.php b/app/Locales/ja_JP/translations.php index 210c476b..6b6c795d 100644 --- a/app/Locales/ja_JP/translations.php +++ b/app/Locales/ja_JP/translations.php @@ -549,4 +549,6 @@ return array( // 'Activity stream' => '', // 'Dashboard' => '', // 'Confirmation' => '', + // 'Allow everybody to access to this project' => '', + // 'Everybody have access to this project.' => '', ); diff --git a/app/Locales/pl_PL/translations.php b/app/Locales/pl_PL/translations.php index 6f6732d6..1ca201c1 100644 --- a/app/Locales/pl_PL/translations.php +++ b/app/Locales/pl_PL/translations.php @@ -549,4 +549,6 @@ return array( // 'Activity stream' => '', // 'Dashboard' => '', // 'Confirmation' => '', + // 'Allow everybody to access to this project' => '', + // 'Everybody have access to this project.' => '', ); diff --git a/app/Locales/pt_BR/translations.php b/app/Locales/pt_BR/translations.php index 0a5b2e28..9bfc9cb3 100644 --- a/app/Locales/pt_BR/translations.php +++ b/app/Locales/pt_BR/translations.php @@ -549,4 +549,6 @@ return array( // 'Activity stream' => '', // 'Dashboard' => '', // 'Confirmation' => '', + // 'Allow everybody to access to this project' => '', + // 'Everybody have access to this project.' => '', ); diff --git a/app/Locales/ru_RU/translations.php b/app/Locales/ru_RU/translations.php index dc9dc9ba..9d236947 100644 --- a/app/Locales/ru_RU/translations.php +++ b/app/Locales/ru_RU/translations.php @@ -549,4 +549,6 @@ return array( 'Activity stream' => 'Текущая активность', 'Dashboard' => 'Инфопанель', 'Confirmation' => 'Подтверждение пароля', + // 'Allow everybody to access to this project' => '', + // 'Everybody have access to this project.' => '', ); diff --git a/app/Locales/sv_SE/translations.php b/app/Locales/sv_SE/translations.php index 3ed8557a..71e03090 100644 --- a/app/Locales/sv_SE/translations.php +++ b/app/Locales/sv_SE/translations.php @@ -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.' => '', ); diff --git a/app/Locales/zh_CN/translations.php b/app/Locales/zh_CN/translations.php index 38f2fee5..fbaef229 100644 --- a/app/Locales/zh_CN/translations.php +++ b/app/Locales/zh_CN/translations.php @@ -549,4 +549,6 @@ return array( 'Activity stream' => '活动流', 'Dashboard' => '面板', 'Confirmation' => '确认', + // 'Allow everybody to access to this project' => '', + // 'Everybody have access to this project.' => '', ); 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 @@ -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() + ); + } } diff --git a/app/Model/User.php b/app/Model/User.php index 33bd6720..9544f3c9 100644 --- a/app/Model/User.php +++ b/app/Model/User.php @@ -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) { diff --git a/app/Schema/Mysql.php b/app/Schema/Mysql.php index 05bef8cd..4f74f761 100644 --- a/app/Schema/Mysql.php +++ b/app/Schema/Mysql.php @@ -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) { diff --git a/app/Schema/Postgres.php b/app/Schema/Postgres.php index 8aaff259..f301f3e8 100644 --- a/app/Schema/Postgres.php +++ b/app/Schema/Postgres.php @@ -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) { diff --git a/app/Schema/Sqlite.php b/app/Schema/Sqlite.php index 3c220f8c..8571d924 100644 --- a/app/Schema/Sqlite.php +++ b/app/Schema/Sqlite.php @@ -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) { diff --git a/app/Templates/project_users.php b/app/Templates/project_users.php index 3b0de7f0..35079df6 100644 --- a/app/Templates/project_users.php +++ b/app/Templates/project_users.php @@ -2,37 +2,56 @@

- -
+ +
-
-

- -

-
- - -
+ +
+ +
+

+
    + $username): ?> +
  • + + + ( $project['id'], 'user_id' => $user_id), true) ?>) + +
  • + +
+

+
+ + + + - + - $project['id'])) ?> + $project['id'])) ?> - -
+ +
-
- -
-
- \ No newline at end of file +
+ +
+ + + + + + +
+ + + $project['id'])) ?> + + +
+ +
+
+ -- cgit v1.2.3