/** * Returns whether the logged in user is allowed to edit a page. * * @return bool */ public function allowedToEdit(Page $page = null) { if ($page === null) { return true; } return Editor::isEnabled() && $this->gate->allows('edit', $page); }
/** * Authorizes a given route. * * @param Route $route * @return bool */ public function passesAuthorization() { if (!$this->hasToBeAuthorized()) { return true; } return $this->gate->allows($this->route->getName()); }
/** * Get dynamic option data for the editor * * @return array */ protected function getDynamicOption() { $data = array_except($this->config->all(), 'tools'); $data['fontFamily'] = isset($data['fontFamily']) ? array_map(function ($v) { return trim($v); }, explode(',', $data['fontFamily'])) : []; $data['extensions'] = isset($data['extensions']) ? array_map(function ($v) { return trim($v); }, explode(',', $data['extensions'])) : []; $data['extensions'] = array_search('*', $data['extensions']) !== false ? ['*'] : $data['extensions']; $instance = new Instance($this->editors->getPermKey($this->instanceId)); $data['perms'] = ['html' => $this->gate->allows('html', $instance), 'tool' => $this->gate->allows('tool', $instance), 'upload' => $this->gate->allows('upload', $instance)]; $data['files'] = $this->files; return $data; }
/** * 관리페이지 메뉴 목록을 생성한다. 현재 요청의 user와 route 정보를 이용하여 선택된 메뉴, 감추어야할 메뉴를 설정한다. * * @param Router $router router * @param boolean $isSuper 최고관리자 여부 * * @return void */ protected function makeMenuList(Router $router, $isSuper) { // 등록된 menu list를 가져온다. $menus = $this->getRegisteredMenus(); // menu를 tree로 구성한다. $this->menuList = new Tree($menus); // menu가 지정된 route 목록을 가져온다. $routes = $router->getRoutes()->getSettingsMenuRoutes(); // 각 메뉴에 해당되는 route를 지정한다. foreach ($routes as $route) { /** @var Route $route */ $menuIds = array_get($route->getAction(), 'settings_menu', []); // 만약 route에 permission 정보가 있고, 그 permission을 현재 member가 통과하지 못하면 display=false로 지정한다. $permissions = array_get($route->getAction(), 'permission', []); $visible = false; if (false && !$isSuper) { foreach ((array) $permissions as $permissionId) { // todo: implementing $instance = new Instance('settings.' . $permissionId); $perm = app('xe.permission')->get($instance->getName(), $instance->getSiteKey()); if ($perm === null) { $visible = false; continue; } if ($this->gate->allows('access', $instance)) { $visible = true; } } } else { $visible = true; } // 메뉴에 route 지정, foreach ((array) $menuIds as $menuId) { $menu = $this->menuList[$menuId]; $menu->route = $route; if ($visible === false) { $menu->display = false; } } } $this->setSelectedMenu($router->current()); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id, Gate $gate) { if ($gate->allows('destroy-posts')) { $post = $this->postRepo->find($id); $post->delete(); return redirect(route('admin::posts.index'))->with('flash.message', trans('admin::posts.post_deleted')); } }
/** * update existing user * * @param string $username * @return Response */ public function update(UpdateUserRequest $request, Gate $gate, $username) { if ($gate->allows('edit-users')) { $this->userRepo->byUsername($username)->profile()->update($request->except('_token', '_method')); return back(); } return redirect()->route('admin::dashboard')->with('flash.message', trans('admin::users.can_not_create_user')); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($role, Gate $gate) { if ($gate->allows('destroy-roles')) { $this->roleRepo->find($role)->delete(); return true; } return false; }