diff options
Diffstat (limited to 'app/Model')
-rw-r--r-- | app/Model/Config.php | 1 | ||||
-rw-r--r-- | app/Model/LastLogin.php | 1 | ||||
-rw-r--r-- | app/Model/Project.php | 206 | ||||
-rw-r--r-- | app/Model/ReverseProxyAuth.php | 70 |
4 files changed, 278 insertions, 0 deletions
diff --git a/app/Model/Config.php b/app/Model/Config.php index 178093c4..9ba2187a 100644 --- a/app/Model/Config.php +++ b/app/Model/Config.php @@ -51,6 +51,7 @@ class Config extends Base 'pt_BR' => t('Portuguese (Brazilian)'), 'sv_SE' => t('Swedish'), 'zh_CN' => t('Chinese (Simplified)'), + 'fi_FI' => t('Finnish'), ); asort($languages); diff --git a/app/Model/LastLogin.php b/app/Model/LastLogin.php index db4c4a57..e2ea63e1 100644 --- a/app/Model/LastLogin.php +++ b/app/Model/LastLogin.php @@ -34,6 +34,7 @@ class LastLogin extends Base const AUTH_LDAP = 'ldap'; const AUTH_GOOGLE = 'google'; const AUTH_GITHUB = 'github'; + const AUTH_REVERSE_PROXY = 'reverse_proxy'; /** * Create a new record diff --git a/app/Model/Project.php b/app/Model/Project.php index 5d3f01b9..f598c96f 100644 --- a/app/Model/Project.php +++ b/app/Model/Project.php @@ -378,6 +378,212 @@ class Project extends Base } /** + * Create a project from another one. + * + * @author Antonio Rabelo + * @param integer $project_id Project Id + * @return integer Cloned Project Id + */ + public function createProjectFromAnotherProject($project_id) + { + // Recover the template project data + $project = $this->getById($project_id); + + // Create a Clone project + $clone_project = array( + 'name' => $project['name'].' ('.t('Clone').')', + 'is_active' => true, + 'last_modified' => 0, + 'token' => Security::generateToken(), + ); + + // Register the cloned project + if (! $this->db->table(self::TABLE)->save($clone_project)) { + return false; + } + + // Get the cloned project Id + return $this->db->getConnection()->getLastId(); + } + + /** + * Copy Board Columns from a project to another one. + * + * @author Antonio Rabelo + * @param integer $project_from Project Template + * @return integer $project_to Project that receives the copy + * @return boolean + */ + public function copyBoardFromAnotherProject($project_from, $project_to) + { + $boardModel = new Board($this->db, $this->event); + $columns = $this->db->table(Board::TABLE)->eq('project_id', $project_from)->asc('position')->findAllByColumn('title'); + return $boardModel->create($project_to, $columns); + } + + /** + * Copy Categories from a project to another one. + * + * @author Antonio Rabelo + * @param integer $project_from Project Template + * @return integer $project_to Project that receives the copy + * @return boolean + */ + public function copyCategoriesFromAnotherProject($project_from, $project_to) + { + $categoryModel = new Category($this->db, $this->event); + $categoriesTemplate = $categoryModel->getAll($project_from); + + foreach ($categoriesTemplate as $category) { + + unset($category['id']); + $category['project_id'] = $project_to; + + if (! $categoryModel->create($category)) { + return false; + } + } + + return true; + } + + /** + * Copy User Access from a project to another one. + * + * @author Antonio Rabelo + * @param integer $project_from Project Template + * @return integer $project_to Project that receives the copy + * @return boolean + */ + public function copyUserAccessFromAnotherProject($project_from, $project_to) + { + $usersList = $this->getAllowedUsers($project_from); + + foreach ($usersList as $id => $userName) { + if (! $this->allowUser($project_to, $id)) { + return false; + } + } + + return true; + } + + /** + * Copy Actions and related Actions Parameters from a project to another one. + * + * @author Antonio Rabelo + * @param integer $project_from Project Template + * @return integer $project_to Project that receives the copy + * @return boolean + */ + public function copyActionsFromAnotherProject($project_from, $project_to) + { + $actionModel = new Action($this->db, $this->event); + $actionTemplate = $actionModel->getAllByProject($project_from); + + foreach ($actionTemplate as $action) { + + unset($action['id']); + $action['project_id'] = $project_to; + $actionParams = $action['params']; + unset($action['params']); + + if (! $this->db->table(Action::TABLE)->save($action)) { + return false; + } + + $action_clone_id = $this->db->getConnection()->getLastId(); + + foreach ($actionParams as $param) { + unset($param['id']); + $param['value'] = $this->resolveValueParamToClonedAction($param, $project_to); + $param['action_id'] = $action_clone_id; + + if (! $this->db->table(Action::TABLE_PARAMS)->save($param)) { + return false; + } + } + } + + return true; + } + + /** + * Resolve type of action value from a project to the respective value in another project. + * + * @author Antonio Rabelo + * @param integer $param A action parameter + * @return integer $project_to Project to find the corresponding values + * @return mixed The corresponding values from $project_to + */ + private function resolveValueParamToClonedAction($param, $project_to) + { + switch($param['name']) { + case 'project_id': + return $project_to; + case 'category_id': + $categoryModel = new Category($this->db, $this->event); + $categoryTemplate = $categoryModel->getById($param['value']); + $categoryFromNewProject = $this->db->table(Category::TABLE)->eq('project_id', $project_to)->eq('name', $categoryTemplate['name'])->findOne(); + return $categoryFromNewProject['id']; + case 'column_id': + $boardModel = new Board($this->db, $this->event); + $boardTemplate = $boardModel->getColumn($param['value']); + $boardFromNewProject = $this->db->table(Board::TABLE)->eq('project_id', $project_to)->eq('title', $boardTemplate['title'])->findOne(); + return $boardFromNewProject['id']; + default: + return $param['value']; + } + } + + /** + * Clone a project + * + * @author Antonio Rabelo + * @param integer $project_id Project Id + * @return integer Cloned Project Id + */ + public function duplicate($project_id) + { + $this->db->startTransaction(); + + // Get the cloned project Id + $clone_project_id = $this->createProjectFromAnotherProject($project_id); + if (! $clone_project_id) { + $this->db->cancelTransaction(); + return false; + } + + // Clone Board + if (! $this->copyBoardFromAnotherProject($project_id, $clone_project_id)) { + $this->db->cancelTransaction(); + return false; + } + + // Clone Categories + if (! $this->copyCategoriesFromAnotherProject($project_id, $clone_project_id)) { + $this->db->cancelTransaction(); + return false; + } + + // Clone Allowed Users + if (! $this->copyUserAccessFromAnotherProject($project_id, $clone_project_id)) { + $this->db->cancelTransaction(); + return false; + } + + // Clone Actions + if (! $this->copyActionsFromAnotherProject($project_id, $clone_project_id)) { + $this->db->cancelTransaction(); + return false; + } + + $this->db->closeTransaction(); + + return (int) $clone_project_id; + } + + /** * Create a project * * @access public diff --git a/app/Model/ReverseProxyAuth.php b/app/Model/ReverseProxyAuth.php new file mode 100644 index 00000000..1b9ed06c --- /dev/null +++ b/app/Model/ReverseProxyAuth.php @@ -0,0 +1,70 @@ +<?php + +namespace Model; + +use Core\Security; + +/** + * ReverseProxyAuth model + * + * @package model + * @author Sylvain VeyriƩ + */ +class ReverseProxyAuth extends Base +{ + /** + * Authenticate the user with the HTTP header + * + * @access public + * @return bool + */ + public function authenticate() + { + if (isset($_SERVER[REVERSE_PROXY_USER_HEADER])) { + + $login = $_SERVER[REVERSE_PROXY_USER_HEADER]; + $userModel = new User($this->db, $this->event); + $user = $userModel->getByUsername($login); + + if (! $user) { + $this->createUser($login); + $user = $userModel->getByUsername($login); + } + + // Create the user session + $userModel->updateSession($user); + + // Update login history + $lastLogin = new LastLogin($this->db, $this->event); + $lastLogin->create( + LastLogin::AUTH_REVERSE_PROXY, + $user['id'], + $userModel->getIpAddress(), + $userModel->getUserAgent() + ); + + return true; + } + + return false; + } + + /** + * Create automatically a new local user after the authentication + * + * @access private + * @param string $login Username + * @return bool + */ + private function createUser($login) + { + $userModel = new User($this->db, $this->event); + + return $userModel->create(array( + 'email' => strpos($login, '@') !== false ? $login : '', + 'username' => $login, + 'is_admin' => REVERSE_PROXY_DEFAULT_ADMIN === $login, + 'is_ldap_user' => 1, + )); + } +} |