diff options
author | Gerardo Zamudio <gerardozamudio@users.noreply.github.com> | 2016-02-24 23:48:50 -0600 |
---|---|---|
committer | Gerardo Zamudio <gerardozamudio@users.noreply.github.com> | 2016-02-24 23:48:50 -0600 |
commit | e4de6b3898b64b26d29aff31f21df5fda8055686 (patch) | |
tree | 575f8a65440f291d70a070d168eafca8c82a6459 /app/Helper | |
parent | d9ffbea174ea6524d0a22f8375ca8b3aa04a3c96 (diff) | |
parent | a6540bc604c837d92c9368540c145606723e97f7 (diff) |
Merge pull request #1 from fguillot/master
Update from upstream
Diffstat (limited to 'app/Helper')
-rw-r--r-- | app/Helper/App.php | 73 | ||||
-rw-r--r-- | app/Helper/Dt.php | 46 | ||||
-rw-r--r-- | app/Helper/File.php | 57 | ||||
-rw-r--r-- | app/Helper/Form.php | 6 | ||||
-rw-r--r-- | app/Helper/Layout.php | 171 | ||||
-rw-r--r-- | app/Helper/Subtask.php | 88 | ||||
-rw-r--r-- | app/Helper/Task.php | 151 | ||||
-rw-r--r-- | app/Helper/Text.php | 30 | ||||
-rw-r--r-- | app/Helper/Url.php | 25 | ||||
-rw-r--r-- | app/Helper/User.php | 82 |
10 files changed, 644 insertions, 85 deletions
diff --git a/app/Helper/App.php b/app/Helper/App.php index 19801fa8..79afa5b9 100644 --- a/app/Helper/App.php +++ b/app/Helper/App.php @@ -2,15 +2,65 @@ namespace Kanboard\Helper; +use Kanboard\Core\Base; + /** * Application helpers * * @package helper * @author Frederic Guillot */ -class App extends \Kanboard\Core\Base +class App extends Base { /** + * Get config variable + * + * @access public + * @param string $param + * @param mixed $default_value + * @return mixed + */ + public function config($param, $default_value = '') + { + return $this->config->get($param, $default_value); + } + + /** + * Make sidebar menu active + * + * @access public + * @param string $controller + * @param string $action + * @param string $plugin + * @return string + */ + public function checkMenuSelection($controller, $action = '', $plugin = '') + { + $result = strtolower($this->getRouterController()) === strtolower($controller); + + if ($result && $action !== '') { + $result = strtolower($this->getRouterAction()) === strtolower($action); + } + + if ($result && $plugin !== '') { + $result = strtolower($this->getPluginName()) === strtolower($plugin); + } + + return $result ? 'class="active"' : ''; + } + + /** + * Get plugin name from route + * + * @access public + * @return string + */ + public function getPluginName() + { + return $this->router->getPlugin(); + } + + /** * Get router controller * * @access public @@ -62,18 +112,17 @@ class App extends \Kanboard\Core\Base */ public function flashMessage() { - $html = ''; - - if (isset($this->session['flash_message'])) { - $html = '<div class="alert alert-success alert-fade-out">'.$this->helper->e($this->session['flash_message']).'</div>'; - unset($this->session['flash_message']); - unset($this->session['flash_error_message']); - } elseif (isset($this->session['flash_error_message'])) { - $html = '<div class="alert alert-error">'.$this->helper->e($this->session['flash_error_message']).'</div>'; - unset($this->session['flash_message']); - unset($this->session['flash_error_message']); + $success_message = $this->flash->getMessage('success'); + $failure_message = $this->flash->getMessage('failure'); + + if (! empty($success_message)) { + return '<div class="alert alert-success alert-fade-out">'.$this->helper->e($success_message).'</div>'; + } + + if (! empty($failure_message)) { + return '<div class="alert alert-error">'.$this->helper->e($failure_message).'</div>'; } - return $html; + return ''; } } diff --git a/app/Helper/Dt.php b/app/Helper/Dt.php index 78002b1b..eb3f93b3 100644 --- a/app/Helper/Dt.php +++ b/app/Helper/Dt.php @@ -13,6 +13,50 @@ use DateTime; class Dt extends \Kanboard\Core\Base { /** + * Get formatted time + * + * @access public + * @param integer $value + * @return string + */ + public function time($value) + { + return date($this->config->get('application_time_format', 'H:i'), $value); + } + + /** + * Get formatted date + * + * @access public + * @param integer $value + * @return string + */ + public function date($value) + { + if (empty($value)) { + return ''; + } + + if (! ctype_digit($value)) { + $value = strtotime($value); + } + + return date($this->config->get('application_date_format', 'm/d/Y'), $value); + } + + /** + * Get formatted datetime + * + * @access public + * @param integer $value + * @return string + */ + public function datetime($value) + { + return date($this->config->get('application_datetime_format', 'm/d/Y H:i'), $value); + } + + /** * Get duration in seconds into human format * * @access public @@ -107,6 +151,6 @@ class Dt extends \Kanboard\Core\Base */ public function getWeekDay($day) { - return dt('%A', strtotime('next Monday +'.($day - 1).' days')); + return date('l', strtotime('next Monday +'.($day - 1).' days')); } } diff --git a/app/Helper/File.php b/app/Helper/File.php index d2cdfc6a..b493e64f 100644 --- a/app/Helper/File.php +++ b/app/Helper/File.php @@ -38,19 +38,70 @@ class File extends \Kanboard\Core\Base return 'fa-file-powerpoint-o'; case 'zip': case 'rar': + case 'tar': + case 'bz2': + case 'xz': + case 'gz': return 'fa-file-archive-o'; case 'mp3': - return 'fa-audio-o'; + return 'fa-file-audio-o'; case 'avi': - return 'fa-video-o'; + case 'mov': + return 'fa-file-video-o'; case 'php': case 'html': case 'css': - return 'fa-code-o'; + return 'fa-file-code-o'; case 'pdf': return 'fa-file-pdf-o'; } return 'fa-file-o'; } + + /** + * Return the image mimetype based on the file extension + * + * @access public + * @param $filename + * @return string + */ + public function getImageMimeType($filename) + { + $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); + + switch ($extension) { + case 'jpeg': + case 'jpg': + return 'image/jpeg'; + case 'png': + return 'image/png'; + case 'gif': + return 'image/gif'; + default: + return 'image/jpeg'; + } + } + + /** + * Get the preview type + * + * @access public + * @param string $filename + * @return string + */ + public function getPreviewType($filename) + { + $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); + + switch ($extension) { + case 'md': + case 'markdown': + return 'markdown'; + case 'txt': + return 'text'; + } + + return null; + } } diff --git a/app/Helper/Form.php b/app/Helper/Form.php index 5f19f2a8..bfd75ee3 100644 --- a/app/Helper/Form.php +++ b/app/Helper/Form.php @@ -2,7 +2,7 @@ namespace Kanboard\Helper; -use Kanboard\Core\Security; +use Kanboard\Core\Base; /** * Form helpers @@ -10,7 +10,7 @@ use Kanboard\Core\Security; * @package helper * @author Frederic Guillot */ -class Form extends \Kanboard\Core\Base +class Form extends Base { /** * Hidden CSRF token field @@ -20,7 +20,7 @@ class Form extends \Kanboard\Core\Base */ public function csrf() { - return '<input type="hidden" name="csrf_token" value="'.Security::getCSRFToken().'"/>'; + return '<input type="hidden" name="csrf_token" value="'.$this->token->getCSRFToken().'"/>'; } /** diff --git a/app/Helper/Layout.php b/app/Helper/Layout.php new file mode 100644 index 00000000..3db23920 --- /dev/null +++ b/app/Helper/Layout.php @@ -0,0 +1,171 @@ +<?php + +namespace Kanboard\Helper; + +use Kanboard\Core\Base; + +/** + * Layout helpers + * + * @package helper + * @author Frederic Guillot + */ +class Layout extends Base +{ + /** + * Render a template without the layout if Ajax request + * + * @access public + * @param string $template Template name + * @param array $params Template parameters + * @return string + */ + public function app($template, array $params = array()) + { + if ($this->request->isAjax()) { + return $this->template->render($template, $params); + } + + if (! isset($params['no_layout']) && ! isset($params['board_selector'])) { + $params['board_selector'] = $this->projectUserRole->getActiveProjectsByUser($this->userSession->getId()); + } + + return $this->template->layout($template, $params); + } + + /** + * Common layout for user views + * + * @access public + * @param string $template Template name + * @param array $params Template parameters + * @return string + */ + public function user($template, array $params) + { + if (isset($params['user'])) { + $params['title'] = '#'.$params['user']['id'].' '.($params['user']['name'] ?: $params['user']['username']); + } + + return $this->subLayout('user/layout', 'user/sidebar', $template, $params); + } + + /** + * Common layout for task views + * + * @access public + * @param string $template Template name + * @param array $params Template parameters + * @return string + */ + public function task($template, array $params) + { + $params['title'] = $params['task']['title']; + return $this->subLayout('task/layout', 'task/sidebar', $template, $params); + } + + /** + * Common layout for project views + * + * @access public + * @param string $template + * @param array $params + * @param string $sidebar + * @return string + */ + public function project($template, array $params, $sidebar = 'project/sidebar') + { + if (empty($params['title'])) { + $params['title'] = $params['project']['name']; + } elseif ($params['project']['name'] !== $params['title']) { + $params['title'] = $params['project']['name'].' > '.$params['title']; + } + + return $this->subLayout('project/layout', $sidebar, $template, $params); + } + + /** + * Common layout for project user views + * + * @access public + * @param string $template + * @param array $params + * @return string + */ + public function projectUser($template, array $params) + { + $params['filter'] = array('user_id' => $params['user_id']); + return $this->subLayout('project_user/layout', 'project_user/sidebar', $template, $params); + } + + /** + * Common layout for config views + * + * @access public + * @param string $template + * @param array $params + * @return string + */ + public function config($template, array $params) + { + if (! isset($params['values'])) { + $params['values'] = $this->config->getAll(); + } + + if (! isset($params['errors'])) { + $params['errors'] = array(); + } + + return $this->subLayout('config/layout', 'config/sidebar', $template, $params); + } + + /** + * Common layout for dashboard views + * + * @access public + * @param string $template + * @param array $params + * @return string + */ + public function dashboard($template, array $params) + { + return $this->subLayout('app/layout', 'app/sidebar', $template, $params); + } + + /** + * Common layout for analytic views + * + * @access public + * @param string $template + * @param array $params + * @return string + */ + public function analytic($template, array $params) + { + return $this->subLayout('analytic/layout', 'analytic/sidebar', $template, $params); + } + + /** + * Common method to generate a sublayout + * + * @access public + * @param string $sublayout + * @param string $sidebar + * @param string $template + * @param array $params + * @return string + */ + public function subLayout($sublayout, $sidebar, $template, array $params = array()) + { + $content = $this->template->render($template, $params); + + if ($this->request->isAjax()) { + return $content; + } + + $params['content_for_sublayout'] = $content; + $params['sidebar_template'] = $sidebar; + + return $this->app($sublayout, $params); + } +} diff --git a/app/Helper/Subtask.php b/app/Helper/Subtask.php index 1f367b27..1784a2bf 100644 --- a/app/Helper/Subtask.php +++ b/app/Helper/Subtask.php @@ -10,32 +10,84 @@ namespace Kanboard\Helper; */ class Subtask extends \Kanboard\Core\Base { + public function getTitle(array $subtask) + { + if ($subtask['status'] == 0) { + $html = '<i class="fa fa-square-o fa-fw"></i>'; + } elseif ($subtask['status'] == 1) { + $html = '<i class="fa fa-gears fa-fw"></i>'; + } else { + $html = '<i class="fa fa-check-square-o fa-fw"></i>'; + } + + return $html.$this->helper->e($subtask['title']); + } + /** * Get the link to toggle subtask status * * @access public - * @param array $subtask - * @param string $redirect + * @param array $subtask + * @param integer $project_id + * @param boolean $refresh_table * @return string */ - public function toggleStatus(array $subtask, $redirect) + public function toggleStatus(array $subtask, $project_id, $refresh_table = false) { - if ($subtask['status'] == 0 && isset($this->session['has_subtask_inprogress']) && $this->session['has_subtask_inprogress'] === true) { - return $this->helper->url->link( - trim($this->template->render('subtask/icons', array('subtask' => $subtask))) . $this->helper->e($subtask['title']), - 'subtask', - 'subtaskRestriction', - array('task_id' => $subtask['task_id'], 'subtask_id' => $subtask['id'], 'redirect' => $redirect), - false, - 'popover task-board-popover' - ); + if (! $this->helper->user->hasProjectAccess('subtask', 'edit', $project_id)) { + return $this->getTitle($subtask); + } + + $params = array('task_id' => $subtask['task_id'], 'subtask_id' => $subtask['id'], 'refresh-table' => (int) $refresh_table); + + if ($subtask['status'] == 0 && isset($this->sessionStorage->hasSubtaskInProgress) && $this->sessionStorage->hasSubtaskInProgress) { + return $this->helper->url->link($this->getTitle($subtask), 'SubtaskRestriction', 'popover', $params, false, 'popover'); } - return $this->helper->url->link( - trim($this->template->render('subtask/icons', array('subtask' => $subtask))) . $this->helper->e($subtask['title']), - 'subtask', - 'toggleStatus', - array('task_id' => $subtask['task_id'], 'subtask_id' => $subtask['id'], 'redirect' => $redirect) - ); + $class = 'subtask-toggle-status '.($refresh_table ? 'subtask-refresh-table' : ''); + return $this->helper->url->link($this->getTitle($subtask), 'SubtaskStatus', 'change', $params, false, $class); + } + + public function selectTitle(array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="1"', 'required', 'maxlength="255"'), $attributes); + + $html = $this->helper->form->label(t('Title'), 'title'); + $html .= $this->helper->form->text('title', $values, $errors, $attributes); + + return $html; + } + + public function selectAssignee(array $users, array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="2"'), $attributes); + + $html = $this->helper->form->label(t('Assignee'), 'user_id'); + $html .= $this->helper->form->select('user_id', $users, $values, $errors, $attributes); + $html .= ' <a href="#" class="assign-me" data-target-id="form-user_id" data-current-id="'.$this->userSession->getId().'" title="'.t('Assign to me').'">'.t('Me').'</a>'; + + return $html; + } + + public function selectTimeEstimated(array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="3"'), $attributes); + + $html = $this->helper->form->label(t('Original estimate'), 'time_estimated'); + $html .= $this->helper->form->numeric('time_estimated', $values, $errors, $attributes); + $html .= ' '.t('hours'); + + return $html; + } + + public function selectTimeSpent(array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="4"'), $attributes); + + $html = $this->helper->form->label(t('Time spent'), 'time_spent'); + $html .= $this->helper->form->numeric('time_spent', $values, $errors, $attributes); + $html .= ' '.t('hours'); + + return $html; } } diff --git a/app/Helper/Task.php b/app/Helper/Task.php index 1405a167..6058c099 100644 --- a/app/Helper/Task.php +++ b/app/Helper/Task.php @@ -2,14 +2,24 @@ namespace Kanboard\Helper; +use Kanboard\Core\Base; + /** * Task helpers * * @package helper * @author Frederic Guillot */ -class Task extends \Kanboard\Core\Base +class Task extends Base { + /** + * Local cache for project columns + * + * @access private + * @var array + */ + private $columns = array(); + public function getColors() { return $this->color->getList(); @@ -34,4 +44,143 @@ class Task extends \Kanboard\Core\Base { return $this->taskPermission->canRemoveTask($task); } + + public function selectAssignee(array $users, array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="3"'), $attributes); + + $html = $this->helper->form->label(t('Assignee'), 'owner_id'); + $html .= $this->helper->form->select('owner_id', $users, $values, $errors, $attributes); + $html .= ' <a href="#" class="assign-me" data-target-id="form-owner_id" data-current-id="'.$this->userSession->getId().'" title="'.t('Assign to me').'">'.t('Me').'</a>'; + + return $html; + } + + public function selectCategory(array $categories, array $values, array $errors = array(), array $attributes = array(), $allow_one_item = false) + { + $attributes = array_merge(array('tabindex="4"'), $attributes); + $html = ''; + + if (! (! $allow_one_item && count($categories) === 1 && key($categories) == 0)) { + $html .= $this->helper->form->label(t('Category'), 'category_id'); + $html .= $this->helper->form->select('category_id', $categories, $values, $errors, $attributes); + } + + return $html; + } + + public function selectSwimlane(array $swimlanes, array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="5"'), $attributes); + $html = ''; + + if (! (count($swimlanes) === 1 && key($swimlanes) == 0)) { + $html .= $this->helper->form->label(t('Swimlane'), 'swimlane_id'); + $html .= $this->helper->form->select('swimlane_id', $swimlanes, $values, $errors, $attributes); + } + + return $html; + } + + public function selectColumn(array $columns, array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="6"'), $attributes); + + $html = $this->helper->form->label(t('Column'), 'column_id'); + $html .= $this->helper->form->select('column_id', $columns, $values, $errors, $attributes); + + return $html; + } + + public function selectPriority(array $project, array $values) + { + $html = ''; + + if ($project['priority_end'] > $project['priority_start']) { + $range = range($project['priority_start'], $project['priority_end']); + $options = array_combine($range, $range); + $values += array('priority' => $project['priority_default']); + + $html .= $this->helper->form->label(t('Priority'), 'priority'); + $html .= $this->helper->form->select('priority', $options, $values, array(), array('tabindex="7"')); + } + + return $html; + } + + public function selectScore(array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="8"'), $attributes); + + $html = $this->helper->form->label(t('Complexity'), 'score'); + $html .= $this->helper->form->number('score', $values, $errors, $attributes); + + return $html; + } + + public function selectTimeEstimated(array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="9"'), $attributes); + + $html = $this->helper->form->label(t('Original estimate'), 'time_estimated'); + $html .= $this->helper->form->numeric('time_estimated', $values, $errors, $attributes); + $html .= ' '.t('hours'); + + return $html; + } + + public function selectTimeSpent(array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="10"'), $attributes); + + $html = $this->helper->form->label(t('Time spent'), 'time_spent'); + $html .= $this->helper->form->numeric('time_spent', $values, $errors, $attributes); + $html .= ' '.t('hours'); + + return $html; + } + + public function selectStartDate(array $values, array $errors = array(), array $attributes = array()) + { + $placeholder = date($this->config->get('application_date_format', 'm/d/Y H:i')); + $attributes = array_merge(array('tabindex="11"', 'placeholder="'.$placeholder.'"'), $attributes); + + $html = $this->helper->form->label(t('Start Date'), 'date_started'); + $html .= $this->helper->form->text('date_started', $values, $errors, $attributes, 'form-datetime'); + + return $html; + } + + public function selectDueDate(array $values, array $errors = array(), array $attributes = array()) + { + $placeholder = date($this->config->get('application_date_format', 'm/d/Y')); + $attributes = array_merge(array('tabindex="12"', 'placeholder="'.$placeholder.'"'), $attributes); + + $html = $this->helper->form->label(t('Due Date'), 'date_due'); + $html .= $this->helper->form->text('date_due', $values, $errors, $attributes, 'form-date'); + + return $html; + } + + public function formatPriority(array $project, array $task) + { + $html = ''; + + if ($project['priority_end'] > $project['priority_start']) { + $html .= '<span class="task-board-priority" title="'.t('Task priority').'">'; + $html .= $task['priority'] >= 0 ? 'P'.$task['priority'] : '-P'.abs($task['priority']); + $html .= '</span>'; + } + + return $html; + } + + public function getProgress($task) + { + if (! isset($this->columns[$task['project_id']])) { + $this->columns[$task['project_id']] = $this->column->getList($task['project_id']); + } + + return $this->task->getProgress($task, $this->columns[$task['project_id']]); + } } diff --git a/app/Helper/Text.php b/app/Helper/Text.php index d2075fe4..83f1e3f9 100644 --- a/app/Helper/Text.php +++ b/app/Helper/Text.php @@ -3,14 +3,15 @@ namespace Kanboard\Helper; use Kanboard\Core\Markdown; +use Kanboard\Core\Base; /** - * Text helpers + * Text Helpers * * @package helper * @author Frederic Guillot */ -class Text extends \Kanboard\Core\Base +class Text extends Base { /** * Markdown transformation @@ -21,7 +22,7 @@ class Text extends \Kanboard\Core\Base */ public function markdown($text, array $link = array()) { - $parser = new Markdown($link, $this->helper->url); + $parser = new Markdown($this->container, $link); $parser->setMarkupEscaped(MARKDOWN_ESCAPE_HTML); return $parser->text($text); } @@ -42,6 +43,29 @@ class Text extends \Kanboard\Core\Base } /** + * Get the number of bytes from PHP size + * + * @param integer $val PHP size (example: 2M) + * @return integer + */ + public function phpToBytes($val) + { + $val = trim($val); + $last = strtolower($val[strlen($val)-1]); + + switch ($last) { + case 'g': + $val *= 1024; + case 'm': + $val *= 1024; + case 'k': + $val *= 1024; + } + + return $val; + } + + /** * Return true if needle is contained in the haystack * * @param string $haystack Haystack diff --git a/app/Helper/Url.php b/app/Helper/Url.php index f120252d..7de8a571 100644 --- a/app/Helper/Url.php +++ b/app/Helper/Url.php @@ -2,8 +2,7 @@ namespace Kanboard\Helper; -use Kanboard\Core\Request; -use Kanboard\Core\Security; +use Kanboard\Core\Base; /** * Url helpers @@ -11,7 +10,7 @@ use Kanboard\Core\Security; * @package helper * @author Frederic Guillot */ -class Url extends \Kanboard\Core\Base +class Url extends Base { private $base = ''; private $directory = ''; @@ -45,7 +44,7 @@ class Url extends \Kanboard\Core\Base */ public function link($label, $controller, $action, array $params = array(), $csrf = false, $class = '', $title = '', $new_tab = false, $anchor = '') { - return '<a href="'.$this->href($controller, $action, $params, $csrf, $anchor).'" class="'.$class.'" title="'.$title.'" '.($new_tab ? 'target="_blank"' : '').'>'.$label.'</a>'; + return '<a href="'.$this->href($controller, $action, $params, $csrf, $anchor).'" class="'.$class.'" title=\''.$title.'\' '.($new_tab ? 'target="_blank"' : '').'>'.$label.'</a>'; } /** @@ -104,8 +103,8 @@ class Url extends \Kanboard\Core\Base */ public function dir() { - if (empty($this->directory) && isset($_SERVER['REQUEST_METHOD'])) { - $this->directory = str_replace('\\', '/', dirname($_SERVER['PHP_SELF'])); + if ($this->directory === '' && $this->request->getMethod() !== '') { + $this->directory = str_replace('\\', '/', dirname($this->request->getServerVariable('PHP_SELF'))); $this->directory = $this->directory !== '/' ? $this->directory.'/' : '/'; $this->directory = str_replace('//', '/', $this->directory); } @@ -121,13 +120,13 @@ class Url extends \Kanboard\Core\Base */ public function server() { - if (empty($_SERVER['SERVER_NAME'])) { + if ($this->request->getServerVariable('SERVER_NAME') === '') { return 'http://localhost/'; } - $url = Request::isHTTPS() ? 'https://' : 'http://'; - $url .= $_SERVER['SERVER_NAME']; - $url .= $_SERVER['SERVER_PORT'] == 80 || $_SERVER['SERVER_PORT'] == 443 ? '' : ':'.$_SERVER['SERVER_PORT']; + $url = $this->request->isHTTPS() ? 'https://' : 'http://'; + $url .= $this->request->getServerVariable('SERVER_NAME'); + $url .= $this->request->getServerVariable('SERVER_PORT') == 80 || $this->request->getServerVariable('SERVER_PORT') == 443 ? '' : ':'.$this->request->getServerVariable('SERVER_PORT'); $url .= $this->dir() ?: '/'; return $url; @@ -148,17 +147,19 @@ class Url extends \Kanboard\Core\Base */ private function build($separator, $controller, $action, array $params = array(), $csrf = false, $anchor = '', $absolute = false) { - $path = $this->router->findUrl($controller, $action, $params); + $path = $this->route->findUrl($controller, $action, $params); $qs = array(); if (empty($path)) { $qs['controller'] = $controller; $qs['action'] = $action; $qs += $params; + } else { + unset($params['plugin']); } if ($csrf) { - $qs['csrf_token'] = Security::getCSRFToken(); + $qs['csrf_token'] = $this->token->getCSRFToken(); } if (! empty($qs)) { diff --git a/app/Helper/User.php b/app/Helper/User.php index 9cd39bd9..29844dfb 100644 --- a/app/Helper/User.php +++ b/app/Helper/User.php @@ -51,21 +51,6 @@ class User extends \Kanboard\Core\Base } /** - * Get user profile - * - * @access public - * @return string - */ - public function getProfileLink() - { - return $this->helper->url->link( - $this->helper->e($this->getFullname()), - 'user', - 'show', - array('user_id' => $this->userSession->getId()) - ); - } - /** * Check if the given user_id is the connected user * * @param integer $user_id User id @@ -88,44 +73,77 @@ class User extends \Kanboard\Core\Base } /** - * Return if the logged user is project admin + * Get role name * * @access public - * @return boolean + * @param string $role + * @return string */ - public function isProjectAdmin() + public function getRoleName($role = '') { - return $this->userSession->isProjectAdmin(); + return $this->role->getRoleName($role ?: $this->userSession->getRole()); } /** - * Check for project administration actions access (Project Admin group) + * Check application access * - * @access public - * @return boolean + * @param string $controller + * @param string $action + * @return bool */ - public function isProjectAdministrationAllowed($project_id) + public function hasAccess($controller, $action) { - if ($this->userSession->isAdmin()) { - return true; + $key = 'app_access:'.$controller.$action; + $result = $this->memoryCache->get($key); + + if ($result === null) { + $result = $this->applicationAuthorization->isAllowed($controller, $action, $this->userSession->getRole()); + $this->memoryCache->set($key, $result); } - return $this->memoryCache->proxy($this->container['acl'], 'handleProjectAdminPermissions', $project_id); + return $result; } /** - * Check for project management actions access (Regular users who are Project Managers) + * Check project access * - * @access public - * @return boolean + * @param string $controller + * @param string $action + * @param integer $project_id + * @return bool */ - public function isProjectManagementAllowed($project_id) + public function hasProjectAccess($controller, $action, $project_id) { if ($this->userSession->isAdmin()) { return true; } - return $this->memoryCache->proxy($this->container['acl'], 'handleProjectManagerPermissions', $project_id); + if (! $this->hasAccess($controller, $action)) { + return false; + } + + $key = 'project_access:'.$controller.$action.$project_id; + $result = $this->memoryCache->get($key); + + if ($result === null) { + $role = $this->getProjectUserRole($project_id); + $result = $this->projectAuthorization->isAllowed($controller, $action, $role); + $this->memoryCache->set($key, $result); + } + + return $result; + } + + /** + * Get project role for the current user + * + * @access public + * @param integer $project_id + * @return string + */ + public function getProjectUserRole($project_id) + { + return $this->memoryCache->proxy($this->projectUserRole, 'getUserRole', $project_id, $this->userSession->getId()); } /** @@ -136,7 +154,7 @@ class User extends \Kanboard\Core\Base */ public function getFullname(array $user = array()) { - return $this->user->getFullname(empty($user) ? $_SESSION['user'] : $user); + return $this->user->getFullname(empty($user) ? $this->sessionStorage->user : $user); } /** |