public function getPermissions($roleId = null) { if (!$roleId) { return null; } // Check if the table exists (patch not installed yet) $db = ConnectionManager::getDataSource('default'); $tables = $db->listSources(); if (!in_array($this->tablePrefix . 'role_permission_roles', $tables)) { $permissions['full_permissions'] = $roleId == 1; $permissions['limited_admin'] = false; $permissions['manage_events'] = false; $permissions['manage_own_events'] = false; $permissions['create_templates'] = false; $permissions['create_reports'] = false; return $permissions; } $permissions = array(); $rolePermissionsAssigned = array(); App::uses('RolePermissionRole', 'Model'); $RolePermissionRoleModel = new RolePermissionRole(); App::uses('RolePermission', 'Model'); $RolePermissionModel = new RolePermission(); $params = array(); $params['recursive'] = 1; $params['fields'] = array('id', 'role_id'); $params['contain']['RolePermission']['fields'] = array('alias'); $params['conditions']['role_id'] = $roleId; if ($rolePermissionRoles = $RolePermissionRoleModel->find('all', $params)) { foreach ($rolePermissionRoles as $rolePermissionRole) { $permissions[$rolePermissionRole['RolePermission']['alias']] = $rolePermissionRole['RolePermissionRole']['role_id'] == $roleId; $rolePermissionsAssigned[] = $rolePermissionRole['RolePermission']['id']; } } $params = array(); $params['recursive'] = -1; $params['conditions']['id !='] = $rolePermissionsAssigned; if ($rolePermissions = $RolePermissionModel->find('all', $params)) { foreach ($rolePermissions as $rolePermission) { if (!isset($permissions[$rolePermission['RolePermission']['alias']])) { $permissions[$rolePermission['RolePermission']['alias']] = false; } } } return $permissions; }
public function v14() { // Regenerate cache Cache::clear(false); /* * API */ // Copy bridge secret key to API private key $bridge = json_decode($this->Setting->getOption('bridge')); if (!empty($bridge) && $bridge->enabled && !empty($bridge->secret)) { $api = array(); $api['enabled'] = 0; $api['privateKey'] = $bridge->secret; $this->Setting->setOption('api', json_encode($api)); // Disable bridge to make use users update their bridge plugin $bridgeSettings = array(); $bridgeSettings['enabled'] = 0; $bridgeSettings['url'] = $bridge->url; $this->Setting->setOption('bridge', json_encode($bridgeSettings)); $this->Session->setFlash(__('Bridge has been disabled ! Be sure to use an updated version of your bridge plugin for MushRaider 1.4. If you don\'t you\'re gonna have a bad time !'), 'flash_important', array(), 'important'); } /* * Import */ // Add absolute path to games's logo field to prepare import functionallity App::uses('Game', 'Model'); $GameModel = new Game(); $params = array(); $params['recursive'] = -1; $params['fields'] = array('id', 'logo'); if ($games = $GameModel->find('all', $params)) { foreach ($games as $game) { if (!empty($game['Game']['logo']) && strpos($game['Game']['logo'], '/files/') === false) { $toUpdate = array(); $toUpdate['id'] = $game['Game']['id']; $toUpdate['logo'] = '/files/logos/' . $game['Game']['logo']; $GameModel->create(); $GameModel->save($toUpdate); } } } /* * Roles permissions */ // Add roles permissions $rolesPermissions = array(array('title' => __('Full permissions'), 'alias' => 'full_permissions', 'description' => __('Like Chuck Norris, he can do anything. This overwrite every permissions')), array('title' => __('Limited admin access'), 'alias' => 'limited_admin', 'description' => __('Like Robin, he can do some things but not all (like driving the batmobile or change user role)')), array('title' => __('Can manage events'), 'alias' => 'manage_events', 'description' => __('Can create, edit and delete events. Can also manage the roster for each events')), array('title' => __('Can create templates'), 'alias' => 'create_templates', 'description' => __('Can create events templates')), array('title' => __('Can create reports'), 'alias' => 'create_reports', 'description' => __('Can create events reports'))); App::uses('RolePermission', 'Model'); $RolePermissionModel = new RolePermission(); foreach ($rolesPermissions as $rolesPermission) { $RolePermissionModel->create(); $RolePermissionModel->save($rolesPermission); } // Add new roles permissions to existing roles App::uses('Role', 'Model'); $RoleModel = new Role(); App::uses('RolePermissionRole', 'Model'); $RolePermissionRoleModel = new RolePermissionRole(); $RolePermissionRoleModel->__add(array('role_id' => $RoleModel->getIdByAlias('admin'), 'role_permission_id' => $RolePermissionModel->getIdByAlias('full_permissions'))); $RolePermissionRoleModel->__add(array('role_id' => $RoleModel->getIdByAlias('officer'), 'role_permission_id' => $RolePermissionModel->getIdByAlias('limited_admin'))); $RolePermissionRoleModel->__add(array('role_id' => $RoleModel->getIdByAlias('officer'), 'role_permission_id' => $RolePermissionModel->getIdByAlias('manage_events'))); $RolePermissionRoleModel->__add(array('role_id' => $RoleModel->getIdByAlias('officer'), 'role_permission_id' => $RolePermissionModel->getIdByAlias('create_templates'))); $RolePermissionRoleModel->__add(array('role_id' => $RoleModel->getIdByAlias('officer'), 'role_permission_id' => $RolePermissionModel->getIdByAlias('create_reports'))); }
private function postInstallData($siteTitle) { // Add default settings $host = substr_count($_SERVER['HTTP_HOST'], '.') > 1 ? substr($_SERVER['HTTP_HOST'], strpos($_SERVER['HTTP_HOST'], '.') + 1) : $_SERVER['HTTP_HOST']; $host = strpos($host, ':') !== false ? substr($host, 0, strpos($host, ':')) : $host; // Remove port if present on unusual configurations App::uses('Setting', 'Model'); $settingModel = new Setting(); $defaultSettings = array(); $defaultSettings['title'] = $siteTitle; $defaultSettings['theme'] = json_encode(array('logo' => '/img/logo.png', 'bgcolor' => '#444444', 'bgimage' => $this->request->webroot . 'img/bg.png', 'bgrepeat' => 'repeat')); $defaultSettings['css'] = ''; $defaultSettings['notifications'] = json_encode(array('enabled' => 1, 'signup' => 0, 'contact' => '')); $defaultSettings['email'] = json_encode(array('name' => 'MushRaider', 'from' => 'mushraider@' . $host, 'encoding' => '', 'transport' => 'Mail', 'host' => '', 'port' => '', 'username' => '', 'password' => '')); $defaultSettings['Mushstats'] = time(); $defaultSettings['calendar'] = json_encode(array('weekStartDay' => 1, 'title' => 'event', 'timeToDisplay' => 'time_invitation', 'gameIcon' => 1, 'dungeonIcon' => 1)); $defaultSettings['timezone'] = 'Europe/Paris'; foreach ($defaultSettings as $option => $value) { $settingModel->create(); $settingModel->save(array('option' => $option, 'value' => $value)); } // Add default roles permissions $rolesPermissions = array(array('title' => __('Full permissions'), 'alias' => 'full_permissions', 'description' => __('Like Chuck Norris, he can do anything. This overwrite every permissions')), array('title' => __('Limited admin access'), 'alias' => 'limited_admin', 'description' => __('Like Robin, he can do some things but not all (like driving the batmobile or change user role)')), array('title' => __('Can manage events'), 'alias' => 'manage_events', 'description' => __('Can create, edit and delete events. Can also manage the roster for each events')), array('title' => __('Can manage own events only'), 'alias' => 'manage_own_events', 'description' => __('Can create, edit and delete own events only. Can also manage the roster for his events')), array('title' => __('Can create templates'), 'alias' => 'create_templates', 'description' => __('Can create events templates')), array('title' => __('Can create reports'), 'alias' => 'create_reports', 'description' => __('Can create events reports'))); App::uses('RolePermission', 'Model'); $RolePermissionModel = new RolePermission(); foreach ($rolesPermissions as $rolesPermission) { $RolePermissionModel->create(); $RolePermissionModel->save($rolesPermission); } // Add new roles permissions to existing roles App::uses('Role', 'Model'); $RoleModel = new Role(); App::uses('RolePermissionRole', 'Model'); $RolePermissionRoleModel = new RolePermissionRole(); $RolePermissionRoleModel->__add(array('role_id' => $RoleModel->getIdByAlias('admin'), 'role_permission_id' => $RolePermissionModel->getIdByAlias('full_permissions'))); $RolePermissionRoleModel->__add(array('role_id' => $RoleModel->getIdByAlias('officer'), 'role_permission_id' => $RolePermissionModel->getIdByAlias('limited_admin'))); $RolePermissionRoleModel->__add(array('role_id' => $RoleModel->getIdByAlias('officer'), 'role_permission_id' => $RolePermissionModel->getIdByAlias('manage_events'))); $RolePermissionRoleModel->__add(array('role_id' => $RoleModel->getIdByAlias('officer'), 'role_permission_id' => $RolePermissionModel->getIdByAlias('create_templates'))); $RolePermissionRoleModel->__add(array('role_id' => $RoleModel->getIdByAlias('officer'), 'role_permission_id' => $RolePermissionModel->getIdByAlias('create_reports'))); }