add rbac guide

This commit is contained in:
Antonio Ramirez
2017-06-13 14:14:12 +02:00
parent 2d6d6d968b
commit e9fcde48fb
3 changed files with 69 additions and 1 deletions

View File

@ -115,6 +115,7 @@ the official Yii2 advanced application template:
See also all the possible configuration options available: See also all the possible configuration options available:
- [Configuration Options](installation/configuration-options.md) - [Configuration Options](installation/configuration-options.md)
- [RBAC](installation/rbac.md)
Enhancing and Overriding Enhancing and Overriding
------------------------ ------------------------

View File

@ -74,7 +74,7 @@ Configures the permission name for `administrators`. See [AuthHelper](../../src/
Configures the URL prefix for the module. Configures the URL prefix for the module.
### mailParams (type: `array`, default: `[]`) #### mailParams (type: `array`, default: `[]`)
Configures the parameter values used on [MailFactory](../../src/User/Factory/MailFactory.php). The default values are: Configures the parameter values used on [MailFactory](../../src/User/Factory/MailFactory.php). The default values are:

67
docs/installation/rbac.md Normal file
View File

@ -0,0 +1,67 @@
RBAC
====
This module comes with RBAC package by default. We haven't found ourselves that we didn't require at least an admin
which doesn't require that level of security. Our projects always start with simple roles such as `admin` but later on
our customers always ask for different levels of permissions for multiple roles.
That is the reason why we include RBAC features by default, and whether you use it or not, you will have to apply
Yii's `rbac` schema migrations or override the views so `PermissionController` and `RoleController` are never
accessible.
We have added an access filter (`Da\User\Filter\AccessRuleFilter`) to allow you to work with those usernames you
configure as administrators of your app via the
[Module::administradors](configuration-options.md#administrators-type-array-default-) attribute.
How to Use `AccessRuleFilter`
-----------------------------
The following is a fragment on how the `Da\User\Controller\AdminController` has configured the filter:
```php
// ...
use Da\User\Filter\AccessRuleFilter;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
// ...
class AdminController extends Controller
{
// ...
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::class,
'actions' => [
'delete' => ['post'],
'confirm' => ['post'],
'block' => ['post'],
],
],
'access' => [
'class' => AccessControl::class,
'ruleConfig' => [
'class' => AccessRuleFilter::class,
],
'rules' => [
[
'allow' => true,
'roles' => ['admin'],
],
],
],
];
}
// ...
}
```
© [2amigos](http://www.2amigos.us/) 2013-2017