Giter Site home page Giter Site logo

windhoney / yii2-rest-rbac Goto Github PK

View Code? Open in Web Editor NEW
83.0 5.0 20.0 1.93 MB

yii2 rbac yii2 rest RBAC Auth manager for Yii2 RESTful(YII2权限管理rbac--rest接口方式)

Home Page: https://windhoney.gitbooks.io/yii2-rest-rbac/

License: MIT License

PHP 100.00%
yii2-rbac yii2-rest yii2-admin yii2-restful-api oauth yii2 yii2-rest-rbac yii-extension yii2-advanced rbac

yii2-rest-rbac's Issues

composer.json没有PHP版本的信息

??应该是PHP7新增的吧。
我测试环境是PHP5.6,可以通过composer安装这个模块,但因为有类似开头说的PHP7的特性,所以运行时就报错了:

syntax error, unexpected '?'

所以,希望可以增加requirements之类的说明,或者在composer.json里做限制。

关于代码parent_name

components/DbManager.php 157

 $this->db->createCommand()
            ->insert($this->itemTable, [
                'name' => $item->name,
                'type' => $item->type,
                'description' => $item->description,
                'parent_name' => $item->parent_name ?? '',
                'rule_name' => $item->ruleName,
                'data' => $item->data === null ? null : serialize($item->data),
                'created_at' => $item->createdAt,
                'updated_at' => $item->updatedAt,
            ])->execute

上述的代码中有

   'parent_name' => $item->parent_name ?? '',

上面的代码出错了?

生成不了oauth2表问题

php yii migrate --migrationPath=@vendor/filsh/yii2-oauth2-server/migrations
需要换成
php yii migrate --migrationPath=@vendor/filsh/yii2-oauth2-server/src/migrations

前后端分离后,如何控制同一个路由页面中不同角色显示不同的页面元素

首先感谢@windhoney还在更新。现在遇到这样一个问题,想请教一下解决方案。我们前端是vuejs+element-ui,接口就是yii2了。基于现在的rbac解决方案,可以控制某个路由级的权限,比如说create、update、delete等。现在有一个情况是,在一个订单展示页面,不同角色的用户可以查询的内容不一样,比如说admin可以查询订单的价格、数量、利润,而普通员工则只能查询价格和数量。价格、数量、利润这三个查询项是以三个button来展示的,我想的是,如果是admin则在页面上展示这三个button,如果是普通员工则只展示前两个button。因为是前后端分离的,那么在展示这个页面的时候是不是就应该知道该展示哪些button?这个数据是不是应该由接口返回呢,如果说是接口返回的话,那么接口怎么根据不同的角色来确定显示哪些元素并将数据返回去前段。@windhoney你有遇到这样的权限处理场景吗?

wind\rest\components\Configs

class Configs extends \yii\base\Object 调整为 extends \yii\base\BaseObject
调整public $menuTable = '{{%menu}}';public $userTable = '{{%user}}';

前后端分离,如何实现树形多级权限分组显示

基于当前的实现,根据parent_name可以将路由分组,但是只是二级目录显示,一般我们给前端的是树形多级分组
|----客户
| |----客户管理
| | |----添加客户
| | |----删除客户
|----订单
| |----订单管理

其实真正的叶子节点才是权限,目前我采取的方案是,新增auth_group表,这个表存的树形的分组,
|id | name | parent|
将auth_item表中的parent_name改成goup_id,即关联auth_group表中的id。
想让某个权限节点在哪一层分组就赋予对应的group_id,这样的话,我们只关心两点,一是权限分组结构,二是某个权限放在哪个分组。这样分开处理后,更加清晰和容易管理,而且可以实现树形多级分组。

mauth_item表中没有‘parent_name’字段,但是代码中使用了

RouteController中

 public function getRoutes()
    {
        $manager = Yii::$app->getAuthManager();
        $routes = $this->getAppRoutes();
//        print_r($routes);die;
        $exists = [];
        foreach ($manager->getPermissions() as $name) {
            $name = ArrayHelper::toArray($name);
            if ($name['name'][0] !== '/') {
                continue;
            }
            $route['name'] = $name['name'];
            $route['description'] = $name['description'];
            $route['parent_name'] = $name['parent_name'];
            $exists[] = $route;
            unset($routes[$name['name']]);
        }
        $exists = ArrayHelper::index($exists, null, 'parent_name');
        
        return [
            'avaliable' => array_keys($routes),
            'assigned' => $exists
        ];
    }

取了‘parent_name’字段,但是数据库表中没有这个字段啊

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.