label305/permissions-component

此包已被废弃且不再维护。未建议替代包。
此包最新版本(dev-master)没有提供许可证信息。

权限组件

dev-master 2016-10-31 10:23 UTC

This package is not auto-updated.

Last update: 2020-01-28 05:56:15 UTC


README

简化从模型中获取 CRUD 权限的过程。

没有维护计划

此项目不再积极维护。它完成了其任务,但没有计划扩展或更改。

安装

将存储库添加到您的需求中,并使用 composer 加载

    "require": {
        "label305/permissions-component": "dev-master"
    }

将组件添加到您的应用程序中

public $components = array(
	'PermissionsComponent.Permissions'
);

用法

使用 Auth 组件设置身份验证并定义用户模型

public $components = array(
    'Auth' => array(
        'authenticate' => array(
            'Form' => array(
                'userModel' => 'YourUserModel'
                )
            )
        )
    );

之后,权限组件将使用 YourUserModel 作为通过选项传递给 CRUD 方法的可许可模型。

例如

public function canUpdate($options) {
    $result = false;
    
    switch($options['PermissibleModel']) {
        case 'PermAccount':
            if(isset($options['PermissibleId'], $options['id'])) {
				$this->id = $options['id'];
                $result = $this->field('perm_account_id') == $options['PermissibleId'];
            }
        break; 
    }
    return $result;
}

这将检查请求的项目 $options['id'] 是否有与登录用户匹配的 perm_account_id。您可以在需要定义类似 API 密钥等权限时使用多个模型进行身份验证。您只需要更改 Authentication 组件使用的 userModel

管理员用户

为了方便,您可以在用户模型中定义一个 "isAdmin" 方法。当该方法被定义时,权限组件将首先查询此方法。如果该方法返回 true,则允许认证用户执行所有操作。

许可证

版权所有 2014 Label305 B.V.

根据 Apache 许可证版本 2.0(“许可证”);除非您遵守许可证的规定,否则不得使用此文件。您可以在以下位置获取许可证副本:

https://apache.ac.cn/licenses/LICENSE-2.0

除非适用法律要求或书面同意,否则在许可证下分发的软件按“原样”分发,不提供任何明示或暗示的保证。有关许可证的具体语言和限制,请参阅许可证。