diff --git a/ChangeLog b/ChangeLog index 6c29301b1..230e99739 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,7 @@ Version 1.0.18 (unreleased) New features: +* Add new role "Project Administrator" * Add login bruteforce protection with captcha and account lockdown * Add new api procedures: getDefaultTaskColor(), getDefaultTaskColors() and getColorList() * Add user api access diff --git a/app/Api/User.php b/app/Api/User.php index 7409a41bb..4884c45cd 100644 --- a/app/Api/User.php +++ b/app/Api/User.php @@ -27,7 +27,7 @@ class User extends \Core\Base return $this->user->remove($user_id); } - public function createUser($username, $password, $name = '', $email = '', $is_admin = 0) + public function createUser($username, $password, $name = '', $email = '', $is_admin = 0, $is_project_admin = 0) { $values = array( 'username' => $username, @@ -36,14 +36,14 @@ class User extends \Core\Base 'name' => $name, 'email' => $email, 'is_admin' => $is_admin, + 'is_project_admin' => $is_project_admin, ); list($valid,) = $this->user->validateCreation($values); - return $valid ? $this->user->create($values) : false; } - public function createLdapUser($username = '', $email = '', $is_admin = 0) + public function createLdapUser($username = '', $email = '', $is_admin = 0, $is_project_admin = 0) { $ldap = new Ldap($this->container); $user = $ldap->lookup($username, $email); @@ -58,12 +58,13 @@ class User extends \Core\Base 'email' => $user['email'], 'is_ldap_user' => 1, 'is_admin' => $is_admin, + 'is_project_admin' => $is_project_admin, ); return $this->user->create($values); } - public function updateUser($id, $username = null, $name = null, $email = null, $is_admin = null) + public function updateUser($id, $username = null, $name = null, $email = null, $is_admin = null, $is_project_admin = null) { $values = array( 'id' => $id, @@ -71,6 +72,7 @@ class User extends \Core\Base 'name' => $name, 'email' => $email, 'is_admin' => $is_admin, + 'is_project_admin' => $is_project_admin, ); foreach ($values as $key => $value) { diff --git a/app/Controller/Project.php b/app/Controller/Project.php index 45bc2a460..9309cfae2 100644 --- a/app/Controller/Project.php +++ b/app/Controller/Project.php @@ -141,8 +141,15 @@ class Project extends Base $project = $this->getProject(); $values = $this->request->getValues(); - if ($project['is_private'] == 1 && $this->userSession->isAdmin() && ! isset($values['is_private'])) { - $values += array('is_private' => 0); + if (isset($values['is_private'])) { + if (! $this->helper->user->isProjectAdministrationAllowed($project['id'])) { + unset($values['is_private']); + } + } + else if ($project['is_private'] == 1 && ! isset($values['is_private'])) { + if ($this->helper->user->isProjectAdministrationAllowed($project['id'])) { + $values += array('is_private' => 0); + } } list($valid, $errors) = $this->project->validateModification($values); @@ -402,7 +409,7 @@ class Project extends Base */ public function create(array $values = array(), array $errors = array()) { - $is_private = $this->request->getIntegerParam('private', $this->userSession->isAdmin() ? 0 : 1); + $is_private = $this->request->getIntegerParam('private', $this->userSession->isAdmin() || $this->userSession->isProjectAdmin() ? 0 : 1); $this->response->html($this->template->layout('project/new', array( 'board_selector' => $this->projectPermission->getAllowedProjects($this->userSession->getId()), diff --git a/app/Controller/User.php b/app/Controller/User.php index 10a3a931d..04e574178 100644 --- a/app/Controller/User.php +++ b/app/Controller/User.php @@ -303,12 +303,16 @@ class User extends Base $values = $this->request->getValues(); if ($this->userSession->isAdmin()) { - $values += array('is_admin' => 0); + $values += array('is_admin' => 0, 'is_project_admin' => 0); } else { - + // Regular users can't be admin if (isset($values['is_admin'])) { - unset($values['is_admin']); // Regular users can't be admin + unset($values['is_admin']); + } + + if (isset($values['is_project_admin'])) { + unset($values['is_project_admin']); } } diff --git a/app/Helper/User.php b/app/Helper/User.php index c1fff8c63..cb596fb03 100644 --- a/app/Helper/User.php +++ b/app/Helper/User.php @@ -77,19 +77,44 @@ class User extends \Core\Base } /** - * Proxy cache helper for acl::isManagerActionAllowed() + * Return if the logged user is project admin * * @access public - * @param integer $project_id * @return boolean */ - public function isManager($project_id) + public function isProjectAdmin() + { + return $this->userSession->isProjectAdmin(); + } + + /** + * Check for project administration actions access (Project Admin group) + * + * @access public + * @return boolean + */ + public function isProjectAdministrationAllowed($project_id) { if ($this->userSession->isAdmin()) { return true; } - return $this->memoryCache->proxy('acl', 'isManagerActionAllowed', $project_id); + return $this->memoryCache->proxy('acl', 'handleProjectAdminPermissions', $project_id); + } + + /** + * Check for project management actions access (Regular users who are Project Managers) + * + * @access public + * @return boolean + */ + public function isProjectManagementAllowed($project_id) + { + if ($this->userSession->isAdmin()) { + return true; + } + + return $this->memoryCache->proxy('acl', 'handleProjectManagerPermissions', $project_id); } /** diff --git a/app/Locale/cs_CZ/translations.php b/app/Locale/cs_CZ/translations.php index c83fe21ba..d968c0b33 100644 --- a/app/Locale/cs_CZ/translations.php +++ b/app/Locale/cs_CZ/translations.php @@ -1015,4 +1015,6 @@ return array( // 'contributors' => '', // 'License:' => '', // 'License' => '', + // 'Project Administrator' => '', + // 'Enter the text below' => '', ); diff --git a/app/Locale/da_DK/translations.php b/app/Locale/da_DK/translations.php index cd7a6f0dc..c48a3339b 100644 --- a/app/Locale/da_DK/translations.php +++ b/app/Locale/da_DK/translations.php @@ -1015,4 +1015,6 @@ return array( // 'contributors' => '', // 'License:' => '', // 'License' => '', + // 'Project Administrator' => '', + // 'Enter the text below' => '', ); diff --git a/app/Locale/de_DE/translations.php b/app/Locale/de_DE/translations.php index 891ed651d..ca5a3fa4c 100644 --- a/app/Locale/de_DE/translations.php +++ b/app/Locale/de_DE/translations.php @@ -1015,4 +1015,6 @@ return array( // 'contributors' => '', // 'License:' => '', // 'License' => '', + // 'Project Administrator' => '', + // 'Enter the text below' => '', ); diff --git a/app/Locale/es_ES/translations.php b/app/Locale/es_ES/translations.php index a1ba90297..feda7b043 100644 --- a/app/Locale/es_ES/translations.php +++ b/app/Locale/es_ES/translations.php @@ -1015,4 +1015,6 @@ return array( // 'contributors' => '', // 'License:' => '', // 'License' => '', + // 'Project Administrator' => '', + // 'Enter the text below' => '', ); diff --git a/app/Locale/fi_FI/translations.php b/app/Locale/fi_FI/translations.php index 4acd409ce..e65f6a348 100644 --- a/app/Locale/fi_FI/translations.php +++ b/app/Locale/fi_FI/translations.php @@ -1015,4 +1015,6 @@ return array( // 'contributors' => '', // 'License:' => '', // 'License' => '', + // 'Project Administrator' => '', + // 'Enter the text below' => '', ); diff --git a/app/Locale/fr_FR/translations.php b/app/Locale/fr_FR/translations.php index 11a429ee2..3f26afe66 100644 --- a/app/Locale/fr_FR/translations.php +++ b/app/Locale/fr_FR/translations.php @@ -1017,4 +1017,6 @@ return array( 'contributors' => 'contributeurs', 'License:' => 'Licence :', 'License' => 'Licence', + 'Project Administrator' => 'Administrateur de projet', + 'Enter the text below' => 'Entrez le texte ci-dessous', ); diff --git a/app/Locale/hu_HU/translations.php b/app/Locale/hu_HU/translations.php index 18737dc12..d697e9de4 100644 --- a/app/Locale/hu_HU/translations.php +++ b/app/Locale/hu_HU/translations.php @@ -1015,4 +1015,6 @@ return array( // 'contributors' => '', // 'License:' => '', // 'License' => '', + // 'Project Administrator' => '', + // 'Enter the text below' => '', ); diff --git a/app/Locale/it_IT/translations.php b/app/Locale/it_IT/translations.php index 93800be6a..665ecfaae 100644 --- a/app/Locale/it_IT/translations.php +++ b/app/Locale/it_IT/translations.php @@ -1015,4 +1015,6 @@ return array( // 'contributors' => '', // 'License:' => '', // 'License' => '', + // 'Project Administrator' => '', + // 'Enter the text below' => '', ); diff --git a/app/Locale/ja_JP/translations.php b/app/Locale/ja_JP/translations.php index 77ebd6504..7b424f863 100644 --- a/app/Locale/ja_JP/translations.php +++ b/app/Locale/ja_JP/translations.php @@ -1015,4 +1015,6 @@ return array( // 'contributors' => '', // 'License:' => '', // 'License' => '', + // 'Project Administrator' => '', + // 'Enter the text below' => '', ); diff --git a/app/Locale/nl_NL/translations.php b/app/Locale/nl_NL/translations.php index fedf0c65f..42c10941d 100644 --- a/app/Locale/nl_NL/translations.php +++ b/app/Locale/nl_NL/translations.php @@ -1015,4 +1015,6 @@ return array( // 'contributors' => '', // 'License:' => '', // 'License' => '', + // 'Project Administrator' => '', + // 'Enter the text below' => '', ); diff --git a/app/Locale/pl_PL/translations.php b/app/Locale/pl_PL/translations.php index e55e2dcd7..0b4a8b7ab 100644 --- a/app/Locale/pl_PL/translations.php +++ b/app/Locale/pl_PL/translations.php @@ -1015,4 +1015,6 @@ return array( // 'contributors' => '', // 'License:' => '', // 'License' => '', + // 'Project Administrator' => '', + // 'Enter the text below' => '', ); diff --git a/app/Locale/pt_BR/translations.php b/app/Locale/pt_BR/translations.php index 8965c5aff..009cd01fd 100644 --- a/app/Locale/pt_BR/translations.php +++ b/app/Locale/pt_BR/translations.php @@ -1015,4 +1015,6 @@ return array( // 'contributors' => '', // 'License:' => '', // 'License' => '', + // 'Project Administrator' => '', + // 'Enter the text below' => '', ); diff --git a/app/Locale/pt_PT/translations.php b/app/Locale/pt_PT/translations.php index 2f294cfd3..0a95b1664 100644 --- a/app/Locale/pt_PT/translations.php +++ b/app/Locale/pt_PT/translations.php @@ -1015,4 +1015,6 @@ return array( 'contributors' => 'contribuidores', 'License:' => 'Licença:', 'License' => 'Licença', + // 'Project Administrator' => '', + // 'Enter the text below' => '', ); diff --git a/app/Locale/ru_RU/translations.php b/app/Locale/ru_RU/translations.php index bc02e35aa..d81c5ea06 100644 --- a/app/Locale/ru_RU/translations.php +++ b/app/Locale/ru_RU/translations.php @@ -1015,4 +1015,6 @@ return array( // 'contributors' => '', // 'License:' => '', // 'License' => '', + // 'Project Administrator' => '', + // 'Enter the text below' => '', ); diff --git a/app/Locale/sr_Latn_RS/translations.php b/app/Locale/sr_Latn_RS/translations.php index b6b4ca144..e053eddfb 100644 --- a/app/Locale/sr_Latn_RS/translations.php +++ b/app/Locale/sr_Latn_RS/translations.php @@ -1015,4 +1015,6 @@ return array( // 'contributors' => '', // 'License:' => '', // 'License' => '', + // 'Project Administrator' => '', + // 'Enter the text below' => '', ); diff --git a/app/Locale/sv_SE/translations.php b/app/Locale/sv_SE/translations.php index fd29872a6..97cfe42ff 100644 --- a/app/Locale/sv_SE/translations.php +++ b/app/Locale/sv_SE/translations.php @@ -1015,4 +1015,6 @@ return array( // 'contributors' => '', // 'License:' => '', // 'License' => '', + // 'Project Administrator' => '', + // 'Enter the text below' => '', ); diff --git a/app/Locale/th_TH/translations.php b/app/Locale/th_TH/translations.php index 28e403768..8b2ec5517 100644 --- a/app/Locale/th_TH/translations.php +++ b/app/Locale/th_TH/translations.php @@ -1015,4 +1015,6 @@ return array( // 'contributors' => '', // 'License:' => '', // 'License' => '', + // 'Project Administrator' => '', + // 'Enter the text below' => '', ); diff --git a/app/Locale/tr_TR/translations.php b/app/Locale/tr_TR/translations.php index a014dfc16..c16789f4c 100644 --- a/app/Locale/tr_TR/translations.php +++ b/app/Locale/tr_TR/translations.php @@ -1015,4 +1015,6 @@ return array( // 'contributors' => '', // 'License:' => '', // 'License' => '', + // 'Project Administrator' => '', + // 'Enter the text below' => '', ); diff --git a/app/Locale/zh_CN/translations.php b/app/Locale/zh_CN/translations.php index 71c89d91f..f5fb4d37c 100644 --- a/app/Locale/zh_CN/translations.php +++ b/app/Locale/zh_CN/translations.php @@ -1015,4 +1015,6 @@ return array( // 'contributors' => '', // 'License:' => '', // 'License' => '', + // 'Project Administrator' => '', + // 'Enter the text below' => '', ); diff --git a/app/Model/Acl.php b/app/Model/Acl.php index a47886bb7..0840f44c2 100644 --- a/app/Model/Acl.php +++ b/app/Model/Acl.php @@ -32,7 +32,7 @@ class Acl extends Base * @access private * @var array */ - private $member_acl = array( + private $project_member_acl = array( 'board' => '*', 'comment' => '*', 'file' => '*', @@ -56,17 +56,27 @@ class Acl extends Base * @access private * @var array */ - private $manager_acl = array( + private $project_manager_acl = array( 'action' => '*', 'analytic' => '*', 'category' => '*', 'column' => '*', - 'export' => array('tasks', 'subtasks', 'summary'), + 'export' => '*', 'project' => array('edit', 'update', 'share', 'integration', 'users', 'alloweverybody', 'allow', 'setowner', 'revoke', 'duplicate', 'disable', 'enable'), 'swimlane' => '*', 'budget' => '*', ); + /** + * Controllers and actions for project admins + * + * @access private + * @var array + */ + private $project_admin_acl = array( + 'project' => array('remove'), + ); + /** * Controllers and actions for admins * @@ -77,8 +87,6 @@ class Acl extends Base 'user' => array('index', 'create', 'save', 'remove', 'authentication'), 'config' => '*', 'link' => '*', - 'project' => array('remove'), - 'hourlyrate' => '*', 'currency' => '*', 'twofactor' => array('disable'), ); @@ -149,9 +157,22 @@ class Acl extends Base * @param string $action Action name * @return bool */ - public function isManagerAction($controller, $action) + public function isProjectManagerAction($controller, $action) { - return $this->matchAcl($this->manager_acl, $controller, $action); + return $this->matchAcl($this->project_manager_acl, $controller, $action); + } + + /** + * Return true if the given action is for application managers + * + * @access public + * @param string $controller Controller name + * @param string $action Action name + * @return bool + */ + public function isProjectAdminAction($controller, $action) + { + return $this->matchAcl($this->project_admin_acl, $controller, $action); } /** @@ -162,9 +183,9 @@ class Acl extends Base * @param string $action Action name * @return bool */ - public function isMemberAction($controller, $action) + public function isProjectMemberAction($controller, $action) { - return $this->matchAcl($this->member_acl, $controller, $action); + return $this->matchAcl($this->project_member_acl, $controller, $action); } /** @@ -189,13 +210,18 @@ class Acl extends Base return false; } + // Check project admin permissions + if ($this->isProjectAdminAction($controller, $action)) { + return $this->handleProjectAdminPermissions($project_id); + } + // Check project manager permissions - if ($this->isManagerAction($controller, $action)) { - return $this->isManagerActionAllowed($project_id); + if ($this->isProjectManagerAction($controller, $action)) { + return $this->handleProjectManagerPermissions($project_id); } // Check project member permissions - if ($this->isMemberAction($controller, $action)) { + if ($this->isProjectMemberAction($controller, $action)) { return $project_id > 0 && $this->projectPermission->isMember($project_id, $this->userSession->getId()); } @@ -203,12 +229,43 @@ class Acl extends Base return true; } - public function isManagerActionAllowed($project_id) + /** + * Handle permission for project manager + * + * @access public + * @param integer $project_id + * @return boolean + */ + public function handleProjectManagerPermissions($project_id) { - if ($this->userSession->isAdmin()) { - return true; + if ($project_id > 0) { + if ($this->userSession->isProjectAdmin()) { + return $this->projectPermission->isMember($project_id, $this->userSession->getId()); + } + + return $this->projectPermission->isManager($project_id, $this->userSession->getId()); } - return $project_id > 0 && $this->projectPermission->isManager($project_id, $this->userSession->getId()); + return false; + } + + /** + * Handle permission for project admins + * + * @access public + * @param integer $project_id + * @return boolean + */ + public function handleProjectAdminPermissions($project_id) + { + if (! $this->userSession->isProjectAdmin()) { + return false; + } + + if ($project_id > 0) { + return $this->projectPermission->isMember($project_id, $this->userSession->getId()); + } + + return true; } } diff --git a/app/Model/User.php b/app/Model/User.php index 8daef3f2c..76af342d3 100644 --- a/app/Model/User.php +++ b/app/Model/User.php @@ -57,6 +57,7 @@ class User extends Base 'name', 'email', 'is_admin', + 'is_project_admin', 'is_ldap_user', 'notifications_enabled', 'google_id', @@ -254,7 +255,7 @@ class User extends Base } $this->removeFields($values, array('confirmation', 'current_password')); - $this->resetFields($values, array('is_admin', 'is_ldap_user')); + $this->resetFields($values, array('is_admin', 'is_ldap_user', 'is_project_admin')); } /** @@ -442,6 +443,7 @@ class User extends Base new Validators\Unique('username', t('The username must be unique'), $this->db->getConnection(), self::TABLE, 'id'), new Validators\Email('email', t('Email address invalid')), new Validators\Integer('is_admin', t('This value must be an integer')), + new Validators\Integer('is_project_admin', t('This value must be an integer')), new Validators\Integer('is_ldap_user', t('This value must be an integer')), ); } diff --git a/app/Model/UserSession.php b/app/Model/UserSession.php index 44a9c2a2e..1ae3fdf4d 100644 --- a/app/Model/UserSession.php +++ b/app/Model/UserSession.php @@ -34,6 +34,7 @@ class UserSession extends Base $user['id'] = (int) $user['id']; $user['is_admin'] = (bool) $user['is_admin']; + $user['is_project_admin'] = (bool) $user['is_project_admin']; $user['is_ldap_user'] = (bool) $user['is_ldap_user']; $user['twofactor_activated'] = (bool) $user['twofactor_activated']; @@ -73,6 +74,17 @@ class UserSession extends Base return isset($this->session['user']['is_admin']) && $this->session['user']['is_admin'] === true; } + /** + * Return true if the logged user is project admin + * + * @access public + * @return bool + */ + public function isProjectAdmin() + { + return isset($this->session['user']['is_project_admin']) && $this->session['user']['is_project_admin'] === true; + } + /** * Get the connected user id * diff --git a/app/Schema/Mysql.php b/app/Schema/Mysql.php index 31ffaa32d..9bd610bb6 100644 --- a/app/Schema/Mysql.php +++ b/app/Schema/Mysql.php @@ -6,7 +6,12 @@ use PDO; use Core\Security; use Model\Link; -const VERSION = 82; +const VERSION = 83; + +function version_83($pdo) +{ + $pdo->exec("ALTER TABLE users ADD COLUMN is_project_admin INT DEFAULT 0"); +} function version_82($pdo) { diff --git a/app/Schema/Postgres.php b/app/Schema/Postgres.php index 876df981d..e1ba07e3f 100644 --- a/app/Schema/Postgres.php +++ b/app/Schema/Postgres.php @@ -6,7 +6,12 @@ use PDO; use Core\Security; use Model\Link; -const VERSION = 62; +const VERSION = 63; + +function version_63($pdo) +{ + $pdo->exec("ALTER TABLE users ADD COLUMN is_project_admin INTEGER DEFAULT 0"); +} function version_62($pdo) { diff --git a/app/Schema/Sqlite.php b/app/Schema/Sqlite.php index 4b8f5ac62..15268d9ab 100644 --- a/app/Schema/Sqlite.php +++ b/app/Schema/Sqlite.php @@ -6,7 +6,12 @@ use Core\Security; use PDO; use Model\Link; -const VERSION = 78; +const VERSION = 79; + +function version_79($pdo) +{ + $pdo->exec("ALTER TABLE users ADD COLUMN is_project_admin INTEGER DEFAULT 0"); +} function version_78($pdo) { diff --git a/app/Template/activity/project.php b/app/Template/activity/project.php index 480bbadd6..bc5852129 100644 --- a/app/Template/activity/project.php +++ b/app/Template/activity/project.php @@ -19,7 +19,7 @@ url->link(t('Back to the calendar'), 'calendar', 'show', array('project_id' => $project['id'])) ?> - user->isManager($project['id'])): ?> + user->isProjectManagementAllowed($project['id'])): ?>
  • url->link(t('Project settings'), 'project', 'show', array('project_id' => $project['id'])) ?> diff --git a/app/Template/analytic/layout.php b/app/Template/analytic/layout.php index 9d6bf77c4..fd2090ae3 100644 --- a/app/Template/analytic/layout.php +++ b/app/Template/analytic/layout.php @@ -19,7 +19,7 @@ url->link(t('Back to the calendar'), 'calendar', 'show', array('project_id' => $project['id'])) ?>
  • - user->isManager($project['id'])): ?> + user->isProjectManagementAllowed($project['id'])): ?>
  • url->link(t('Project settings'), 'project', 'show', array('project_id' => $project['id'])) ?> diff --git a/app/Template/app/layout.php b/app/Template/app/layout.php index 4a307a198..de561dede 100644 --- a/app/Template/app/layout.php +++ b/app/Template/app/layout.php @@ -1,7 +1,7 @@