Exemplo n.º 1
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id)
 {
     $roleModel = new Role();
     $navigationModel = new Navigation();
     $permissionModel = new Permission();
     if (!($roleRow = $roleModel->getForEdit($id))) {
         return view('admin.common.alert', ['type' => 'warning', 'error' => [trans('page_404')], 'location' => ['url' => route('admin.rbac.roles.index'), 'name' => trans('rbac.role') . trans('common.list')]]);
     }
     return view('admin.rbac.roles.create')->with('navigationRows', $navigationModel->getAllNavigationForChildren())->with('permissionRows', $permissionModel->getAllPermissionForChildren())->with('roleRow', $roleRow);
 }
Exemplo n.º 2
0
 /**
  * 当前面包屑
  * @return [type] [description]
  */
 private function userIndex()
 {
     $permission = new Permission();
     $current = Route::currentRouteName();
     $name = '';
     if (Cache::has("permissionRows[{$current}]")) {
         $permissionRow = Cache::get("permissionRows[{$current}]");
         $name = isset($permissionRow['display_name']) && $permissionRow['display_name'] ? $permissionRow['display_name'] : '';
     }
     if ($name == '') {
         $name = $permission->whereName($current)->pluck('display_name');
     }
     view()->share('userIndex', $name);
 }
Exemplo n.º 3
0
Arquivo: Acl.php Projeto: pfdtk/bmsys
 /**
  * 取得当前登录的用户的权限角色对应表中的信息。
  *
  * @param object $userObj
  * @param int $userOrGroup
  * @access public
  * @return array|null
  */
 public function getUserAccessPermission($userObj, $userOrGroup = false)
 {
     $permission = new Permission();
     $access = new Access();
     //如果是超级管理员或者创始人登陆,那么返回所有的权限
     if ($userObj->group_id == self::ADMIN_ROLE_ID or $userObj->id == self::ADMIN_ID) {
         return $permission->getAllAccessPermission();
     }
     //如果需要对比用户和用户组的权限或者返回用户的权限
     if ($userOrGroup == self::AP_USER or !$userOrGroup) {
         $userAccessPermissionInfo = $access->getUserAccessPermission($userObj->id);
     }
     //如果用户的权限数据为空或者指定了需要查询的权限的类型为用户组,或者需要对比用户和用户组的权限
     if ($userOrGroup == self::AP_GROUP or !$userAccessPermissionInfo or !$userOrGroup) {
         $groupAccessPermissionInfo = $access->getGroupAccessPermission($userObj->group_id);
     }
     //根据条件返回权限信息,注意的是用户的权限会覆盖用户组的权限
     return $userOrGroup == self::AP_USER ? $userAccessPermissionInfo : ($userOrGroup == self::AP_GROUP ? $groupAccessPermissionInfo : ($userAccessPermissionInfo ? $userAccessPermissionInfo : $groupAccessPermissionInfo));
 }
Exemplo n.º 4
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy(Permission $permissionModel, $id)
 {
     $result = $permissionModel->submitForDestroy($id);
     return response()->json(ViewAlert::getViewInstance()->create($result));
 }
Exemplo n.º 5
0
 /**
  * 编辑权限功能
  *
  * @access public
  */
 public function edit(PermissionModel $permissionModel)
 {
     if (Request::method() == 'POST') {
         return $this->updatePermission();
     }
     Session::flashInput(['http_referer' => Session::getOldInput('http_referer')]);
     $id = Request::input('id');
     $permissionId = url_param_decode($id);
     if (!$permissionId or !is_numeric($permissionId)) {
         return Js::error(Lang::get('common.illegal_operation'), true);
     }
     $list = (array) Tree::genTree($permissionModel->getAllAccessPermission());
     $permissionInfo = $permissionModel->getOnePermissionById(intval($permissionId));
     if (empty($permissionInfo)) {
         return Js::error(Lang::get('acl.acl_not_found'), true);
     }
     $select = Tree::dropDownSelect($list, $permissionInfo['pid']);
     $formUrl = route('foundation.acl.edit');
     return view('admin.acl.add', compact('select', 'permissionInfo', 'formUrl', 'id'));
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     Permission::find($id)->delete();
     Session::flash('flash_message', trans('admin/permissions.form.delete_confirm'));
 }
 public function getModels($filter = null)
 {
     $models = Permission::sortable($this->index_view);
     if ($this->show_trash()) {
         $models = $models->withTrashed();
     }
     if (isset($filter)) {
         foreach ($this->filter_fields as $field) {
             if (trim($filter[$field]) != '') {
                 $values = explode(',', $filter[$field]);
                 $first = true;
                 foreach ($values as $value) {
                     if ($field == 'id') {
                         if ($first) {
                             $models = $models->Where($field, $value);
                             $first = false;
                         } else {
                             $models = $models->orWhere($field, $value);
                         }
                     } else {
                         if ($field == 'roles') {
                             $value = '%' . $value . '%';
                             if ($first) {
                                 $models = $models->whereHas('roles', function ($q) use($value) {
                                     $q->where('acronym', 'like', $value);
                                 });
                                 $first = false;
                             } else {
                                 $models = $models->orWhereHas('roles', function ($q) use($value) {
                                     $q->where('acronym', 'like', $value);
                                 });
                             }
                         } else {
                             $value = '%' . $value . '%';
                             if ($first) {
                                 $models = $models->Where($field, 'LIKE', $value);
                                 $first = false;
                             } else {
                                 $models = $models->orWhere($field, 'LIKE', $value);
                             }
                         }
                     }
                 }
             }
         }
     }
     return $models;
 }
Exemplo n.º 8
0
 public function listPermissions()
 {
     return Permission::lists('permission_title', 'id')->toArray();
 }
Exemplo n.º 9
0
 /**
  * 生成url数组
  * @param  string  $method [description]
  * @param  integer $id     [description]
  * @return [type]          [description]
  */
 private function getHrefByMethod($method = 'index', $id = 0)
 {
     $current = $this->getCurrentForParam($method);
     $name = '';
     if (Cache::has("permissionRows[{$current}]")) {
         $permissionRow = Cache::get("permissionRows[{$current}]");
         $name = isset($permissionRow['display_name']) && $permissionRow['display_name'] ? $permissionRow['display_name'] : '';
     }
     if ($name == '') {
         $permission = new Permission();
         $name = $permission->whereName($current)->pluck('display_name');
     }
     if ($id == 0) {
         return ['url' => route($current), 'name' => $name];
     } else {
         return ['url' => route($current, ['id' => $id]), 'name' => $name];
     }
 }