From fdaf50116c208e78b6c4de6e6fe263541163c4af Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Fri, 16 Mar 2018 22:49:51 +0000 Subject: [PATCH] Initial implementation of role editor. --- WEB-INF/lib/ttRoleHelper.class.php | 3 ++- WEB-INF/lib/ttTeamHelper.class.php | 22 ++++++++++++++++++++++ WEB-INF/templates/footer.tpl | 2 +- WEB-INF/templates/profile_edit.tpl | 2 +- role_edit.php | 1 + roles.php | 4 ++-- 6 files changed, 29 insertions(+), 5 deletions(-) diff --git a/WEB-INF/lib/ttRoleHelper.class.php b/WEB-INF/lib/ttRoleHelper.class.php index 4a666cb6..2f2415b9 100644 --- a/WEB-INF/lib/ttRoleHelper.class.php +++ b/WEB-INF/lib/ttRoleHelper.class.php @@ -126,10 +126,11 @@ class ttRoleHelper { $id = (int)$fields['id']; if (isset($fields['name'])) $name_part = 'name = '.$mdb2->quote($fields['name']); + if (isset($fields['rank'])) $rank_part = ', rank = '.(int)$fields['rank']; if (isset($fields['description'])) $descr_part = ', description = '.$mdb2->quote($fields['description']); if (isset($fields['status'])) $status_part = ', status = '.(int)$fields['status']; if (isset($fields['rights'])) $rights_part = ', rights = '.$mdb2->quote($fields['rights']); - $parts = trim($name_part.$descr_part.$status_part.$rights_part, ','); + $parts = trim($name_part.$rank_part.$descr_part.$status_part.$rights_part, ','); $sql = "update tt_roles set $parts where id = $id and team_id = $user->team_id"; $affected = $mdb2->exec($sql); return (!is_a($affected, 'PEAR_Error')); diff --git a/WEB-INF/lib/ttTeamHelper.class.php b/WEB-INF/lib/ttTeamHelper.class.php index b30b9ccd..fec798a5 100644 --- a/WEB-INF/lib/ttTeamHelper.class.php +++ b/WEB-INF/lib/ttTeamHelper.class.php @@ -325,6 +325,28 @@ class ttTeamHelper { return $result; } + // getInactiveRolesForUser - returns an array of relevant active roles for user with rank less than self. + // "Relevant" means that client roles are filtered out if Client plugin is disabled. + static function getInactiveRolesForUser() + { + global $user; + $result = array(); + $mdb2 = getConnection(); + + $sql = "select id, name, description, rank, rights from tt_roles where team_id = $user->team_id and rank < $user->rank and status = 0 order by rank"; + $res = $mdb2->query($sql); + $result = array(); + if (!is_a($res, 'PEAR_Error')) { + while ($val = $res->fetchRow()) { + $val['is_client'] = in_array('track_own_time', explode(',', $val['rights'])) ? 0 : 1; // Clients do not have data entry right. + if ($val['is_client'] && !$user->isPluginEnabled('cl')) + continue; // Skip adding a client role. + $result[] = $val; + } + } + return $result; + } + // getAllRoles - obtains all roles defined for team. static function getAllRoles($team_id) { $mdb2 = getConnection(); diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 9a23ed46..8f5d92e7 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
- - {if defined(DEBUG_ROLES)} + {if $user->can('manage_roles')} diff --git a/role_edit.php b/role_edit.php index 25970bdd..946f8347 100644 --- a/role_edit.php +++ b/role_edit.php @@ -89,6 +89,7 @@ if ($request->isPost()) { if (ttRoleHelper::update(array( 'id' => $cl_role_id, 'name' => $cl_name, + 'rank' => $cl_rank, 'description' => $cl_description, 'status' => $cl_status))) { header('Location: roles.php'); diff --git a/roles.php b/roles.php index b2629be8..64a1ee4a 100644 --- a/roles.php +++ b/roles.php @@ -37,8 +37,8 @@ if (!ttAccessAllowed('manage_roles')) { exit(); } -$smarty->assign('active_roles', ttTeamHelper::getActiveRoles($user->team_id)); -$smarty->assign('inactive_roles', ttTeamHelper::getInactiveRoles($user->team_id)); +$smarty->assign('active_roles', ttTeamHelper::getActiveRolesForUser()); +$smarty->assign('inactive_roles', ttTeamHelper::getInactiveRolesForUser()); $smarty->assign('title', $i18n->getKey('title.roles')); $smarty->assign('content_page_name', 'roles.tpl'); $smarty->display('index.tpl'); -- 2.20.1
 Anuko Time Tracker 1.17.50.4090 | Copyright © Anuko | +  Anuko Time Tracker 1.17.51.4091 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/WEB-INF/templates/profile_edit.tpl b/WEB-INF/templates/profile_edit.tpl index 955f7d5a..244c6cb1 100644 --- a/WEB-INF/templates/profile_edit.tpl +++ b/WEB-INF/templates/profile_edit.tpl @@ -141,7 +141,7 @@ function handlePluginCheckboxes() { {$i18n.label.currency}: {$forms.profileForm.currency.control}
{$i18n.label.roles}: {$i18n.label.configure}