/** * This function will call internal function to check permission, * if permission is not there, redirect to access denied page. * @param $permissionName */ public static function access_check($permissionName) { if (!PermApi::user_has_permission($permissionName)) { header('Location: ' . url('access-denied')); die; } }
public function deleteRole($id) { PermApi::access_check('manage_permissions'); try { DB::beginTransaction(); // start the DB transaction $group = Sentry::findGroupById($id); $authenticatedGroup = Sentry::findGroupById(3); // super admin group cannot be deleted if ($id == 1 || $id == 3) { SentryHelper::setMessage('This role cannot be deleted.', 'warning'); return Redirect::to('user/permission/list'); } // assign authenticated user group $users = Sentry::findAllUsersInGroup($group); foreach ($users as $user) { $user->addGroup($authenticatedGroup); } // delete group $group->delete(); // clear permission in group mapping DB::table('permission_in_group')->where('group_id', $id)->delete(); DB::table('users_groups')->where('user_id', $id)->update(array('group_id' => $authenticatedGroup->id)); DB::commit(); // commit the DB transaction SentryHelper::setMessage('Role deleted, all users of this role are now Authenticated users.'); return Redirect::to('user/permission/list'); } catch (\Exception $e) { DB::rollback(); // something went wrong } }
/** * Handle the role delete. Need to check * @return mixed */ public function handleRoleUpdate() { PermApi::access_check('manage_permissions'); $roleName = Input::get('role'); $roleId = Input::get('roleId'); $SentryPermission = new SentryPermission(); if ($SentryPermission->updateRole($roleId, $roleName)) { SentryHelper::setMessage('Role updated'); } else { SentryHelper::setMessage('Role not updated', 'warning'); } return Redirect::to('user/role/edit/' . $roleId); }
/** * Returning the user add form view. */ public function handleUserAdd() { // checking the access for the user PermApi::access_check('create_users'); // get all sentry groups $roles = Sentry::findAllGroups(); $this->layout->content = View::make('sentryuser::add-user')->with('roles', $roles); }