Get an array of default role types.
public static getDefaultTypes ( boolean $translate = true ) : array | ||
$translate | boolean | Whether or not to translate the type names. |
return | array | Returns an array in the form `[type => name]`. |
/** * Edit a role. * * @since 2.0.0 * @access public */ public function edit($RoleID = false) { if (!$this->_permission($RoleID)) { return; } if ($this->Head && $this->Head->title() == '') { $this->Head->title(t('Edit Role')); } $this->addSideMenu('dashboard/role'); $PermissionModel = Gdn::permissionModel(); $this->Role = $this->RoleModel->getByRoleID($RoleID); // $this->EditablePermissions = is_object($this->Role) ? $this->Role->EditablePermissions : '1'; $this->addJsFile('jquery.gardencheckboxgrid.js'); // Set the model on the form. $this->Form->setModel($this->RoleModel); // Make sure the form knows which item we are editing. $this->Form->addHidden('RoleID', $RoleID); $LimitToSuffix = !$this->Role || $this->Role->CanSession == '1' ? '' : 'View'; // If seeing the form for the first time... if ($this->Form->authenticatedPostBack() === false) { // Get the role data for the requested $RoleID and put it into the form. $Permissions = $PermissionModel->getPermissionsEdit($RoleID ? $RoleID : 0, $LimitToSuffix); // Remove permissions the user doesn't have access to. if (!Gdn::session()->checkPermission('Garden.Settings.Manage')) { foreach ($this->RoleModel->RankPermissions as $Permission) { if (Gdn::session()->checkPermission($Permission)) { continue; } list($Px, $Sx) = explode('.', $Permission, 2); unset($Permissions['_' . $Px][$Sx]); } } $this->setData('PermissionData', $Permissions, true); $this->Form->setData($this->Role); } else { $this->removeRankPermissions(); // Make sure the role's checkbox has a false value so that the role model can handle a sparse update of // column from other places. if (!$this->Form->getFormValue('PersonalInfo')) { $this->Form->setFormValue('PersonalInfo', false); } // If the form has been posted back... // 2. Save the data (validation occurs within): if ($RoleID = $this->Form->save()) { if ($this->deliveryType() === DELIVERY_TYPE_DATA) { $this->index($RoleID); return; } $this->informMessage(t('Your changes have been saved.')); $this->RedirectUrl = url('dashboard/role'); // Reload the permission data. $this->setData('PermissionData', $PermissionModel->getPermissionsEdit($RoleID, $LimitToSuffix), true); } } $this->setData('_Types', $this->RoleModel->getDefaultTypes(true)); $this->render(); }
/** * Show list of roles. * * @since 2.0.0 * @access public */ public function index($roleID = null) { $this->_permission(); $this->setHighlightRoute('dashboard/role'); $this->addJsFile('jquery.tablednd.js'); $this->title(t('Roles & Permissions')); if (!$roleID) { $roles = $this->RoleModel->getWithRankPermissions()->resultArray(); // Check to see which roles can be modified. foreach ($roles as &$row) { $canModify = true; if (!Gdn::session()->checkPermission('Garden.Settings.Manage')) { foreach ($this->RoleModel->RankPermissions as $permission) { if ($row[$permission] && !Gdn::session()->checkPermission($permission)) { $canModify = false; break; } } } $row['CanModify'] = $canModify; } $this->setData('Roles', $roles); } elseif ($this->deliveryType() === DELIVERY_TYPE_DATA) { // This is an API request. Get the role in a nicer format. $role = $this->RoleModel->getID($roleID, DATASET_TYPE_ARRAY); // Get the global permissions. $permissions = Gdn::permissionModel()->getGlobalPermissions($roleID); unset($permissions['PermissionID']); // Get the per-category permissions. $permissions['Category'] = $this->RoleModel->getCategoryPermissions($roleID); $role['Permissions'] = $permissions; $this->setData('Role', $role); saveToConfig('Api.Clean', false, false); } else { $Role = $this->RoleModel->getID($roleID); $this->setData('Roles', [$Role]); } // Grab the total users for each role. if (is_array($this->data('Roles'))) { $pastThreshold = Gdn::userModel()->pastUserMegaThreshold(); $thresholdTypeExceptions = RoleModel::getDefaultTypes(); unset($thresholdTypeExceptions[RoleModel::TYPE_MEMBER]); $roles = $this->data('Roles'); foreach ($roles as &$role) { if ($pastThreshold && !in_array($role['Type'], $thresholdTypeExceptions)) { $countUsers = t('View'); } else { $countUsers = $this->RoleModel->getUserCount($role['RoleID']); } $role['CountUsers'] = $countUsers; } $this->setData('Roles', $roles); } $this->render(); }