Rbac-Laravel is package for implementing the Role Based Access control in laravel application.
List of actions that can be done:
- Role Management
- Permission Management
- Manage Role Permissions
- Menu Management
- Added Permission Group Management - Can be used for grouping the permissions under one title
- Add New Role
- List All Roles
- Update Role Details
- Change Role Status
- View Role Details
- Role List for Dropdown
- Add New Permission
- Update Permission Details
- View Permission Details
- List all Permissions
- Change Permission Status
- Add New Menu Item
- Update Menu Item Information
- View Menu Item Details
- List all Menu Items
- Change Menu Item Status
- Get Menu for a role
- Get Parent Menu List
- Add New Permission Group
- Update Permission Group Details
- View Permission Group Details
- List all Permission Groups
This api end point will be used for adding a new role.
{
    "name": "basic",
    "description": "This is some description"
}
This api lists all the roles added in the application.
- limitis non-required parameter. Value of this parameter decides that number of results to be returned in the response. Default value is as per the application settings
- pageis non-required parameter. Value of this parameter is used for identifying the current page for the paginated result. Default value is 1
- nameis non-required parameter. It can be used to filter the results using the name
- statusis non-required parameter. It can be used to filter the results using the status
{
    "data": [
        {
            "id": 1,
            "name": "Administrator",
            "description": "This is administrator role",
            "status": "blocked"
        },
        {
            "id": 2,
            "name": "Writer",
            "description": "This is writer role",
            "status": "blocked"
        }
    ],
    "pagination": {
        "total": 4,
        "count": 2,
        "per_page": 2,
        "current_page": 1,
        "total_pages": 2
    }
}
This api end point will be used for updating an existing role.
- idis the unique id of the role to be updated
{
    "name": "basic",
    "description": "This is basic role",
    "status": "active"
}
This api end point will be used for changing the status of an existing role.
{
    "id": 12345678,
    "status": "open"
}
This api end point will return the details of the role matching the passed id
- idunique id of the role whose details is required
{
    "id": 1,
    "name": "Administrator",
    "description": "This is administrator role",
    "status": "blocked"
}
This api end point will return the list of roles for dropdown
{
    "data": [
        {
            "id": 1,
            "name": "Administrator"
        },
        {
            "id": 2,
            "name": "basic"
        }
    ]
}
This API end point will be used to add a new permission details
- idunique id of the role whose details is required
{
    "name": "Add role",
    "description": "A role with this permission can add a new role"
}
This api end point will be used for updating an existing permission.
- idis the unique id of the permission to be updated
{
    "name": "Add Role",
    "description": "Role with this permission can add a new role.",
    "status": "active"
}
This api end point will return the details of the permission matching the passed id
- idunique id of the permission whose details required
{
    "id": 1,
    "name": "Add new role",
    "description": "A role with this permission can add a new role",
    "status": "active"
}
This api lists all the permissions added in the application.
- limitis non-required parameter. Value of this parameter decides that number of results to be returned in the response. Default value is as per the application settings
- pageis non-required parameter. Value of this parameter is used for identifying the current page for the paginated result. Default value is 1
{
    "data": [
        {
            "id": 1,
            "name": "Add new role",
            "description": "A role with this permission can add a new role",
            "status": "active"
        },
        {
            "id": 2,
            "name": "List Roles",
            "description": "A role with this permission can view list of all the roles",
            "status": "blocked"
        }
    ],
    "pagination": {
        "totalResult": 2,
        "count": 2,
        "per_page": 5,
        "current_page": 1,
        "total_pages": 1
    }
}
This api end point will be used for changing the status of an existing permission.
{
    "id": 12345678,
    "status": "open"
}
This API end point will be used for assigning permissions to a role
- idunique id of the role whose details required
{
    "role": 1,
    "permissions": [1,2]
}
This api lists all the permissions assigned to a role.
{
    "id": 1,
    "name": "Administrator",
    "description": "This is administrator role",
    "status": "blocked",
    "permissions": [
        {
            "id": 1,
            "name": "Add role",
            "description": "A role with this permission can add a new role",
            "status": "blocked"
        },
        {
            "id": 2,
            "name": "List Roles",
            "description": "A role with this permission view the list of roles",
            "status": "blocked"
        }
    ]
}
This method will be used to check if a permission has been assigned to a particular role.
<?php
namespace App\Libraray\Application;
use ParthShukla\Rbac\Library\Utility;
class TestPackageFeature
{
protected $rbac;
    /**
     * @param Rbac $rbac
     */
    public function __construct(Rbac $rbac)
    {
        $this->rbac = $rbac;
    }
    //-------------------------------------------------------------------------
    public function canUserPerformAction($roleId, $permission)
    {
        return $this->rbac->checkAccess($roleId, $permission);
    }
}
// end of class TestPackageFeature
// end of file TestPackageFeature.php
This api end point will be used for adding a new menu item.
{
    "name": "Dashboard",
    "parentId": "",
    "displayName": "",
    "displayOrder": "",
    "status": "",
    "permissionId": "",
}
This api end point will be used for updating an existing menu item.
- idis the unique id of the role to be updated
{
    "name": "Dashboard",
    "parentId": "",
    "displayName": "My Dashboard",
    "displayOrder": "",
    "status": "",
    "permissionId": ""
}
This api end point will return the details of the menu item matching the passed id
- idunique id of the role whose details is required
{
    "id": 2,
    "name": "Add New Permission",
    "displayName": "",
    "parentId": 0,
    "displayOrder": 0,
    "status": "disabled",
    "permissions": [
        {
            "id": 1,
            "name": "Add Permission",
            "description": null,
            "status": "active"
        }
    ]
}
This api lists all the menu items added in the application.
- limitis non-required parameter. Value of this parameter decides that number of results to be returned as response. Default value is as per the application settings
- pageis non-required parameter. Value of this parameter is used for identifying the current page for the paginated result. Default value is 1
- nameis non-required parameter. It is a search filter to get menu-items whose name similar to passed value
- statusis non-required parameter. It is a search filter to get menu-items whose status is as per the passed value
{
    "data": [
        {
            "id": 1,
            "name": "Dashboard",
            "displayName": "My Dashboard",
            "parentId": "",
            "displayOrder": 0,
            "status": "active",
            "parentName": null
        }
    ],
    "pagination": {
        "totalResult": 1,
        "count": 1,
        "per_page": 5,
        "current_page": 1,
        "total_pages": 1
    }
}
This api end point will update the status of a menu item.
{
    "menuId": 1,
    "status": "active"
}
This method will be used to get the menu for a role.
<?php
namespace App\Libraray\Application;
use ParthShukla\Rbac\Library\Utility\MenuGenerator;
class TestPackageFeature
{
    /**
     * Instance of MenuGenerator
     *
     * @var MenuGenerator
     */
    protected $menuGenerator;
    
    //-------------------------------------------------------------------------
    /**
     * Constructor
     * 
     * @param MenuGenerator $menuGenerator
     */
    public function __construct(MenuGenerator $menuGenerator)
    {
        $this->menuGenerator = $menuGenerator;
    }
    //-------------------------------------------------------------------------
    public function getRoleMenu($roleId)
    {
        return $this->menuGenerator->getRoleMenu($roleId);
    }
}
// end of class TestPackageFeature
// end of file TestPackageFeature.php
This api lists all the parent menu items added in the application.
{
    "data": [
        {
            "id": 1,
            "name": "Dashboard",
            "displayName": "My Dashboard"
        },
        {
            "id": 5,
            "name": "Permission",
            "displayName": ""
        }
    ]
}
This api end point will be used for adding a new permission group.
{
    "name": "User Management",
    "description": "This group contains all the permissions related to user management"
}
This api end point will be used for updating an existing permission group.
- idis the unique id of the permission group to be updated
{
    "name": "User Management",
    "description": "This group contains all the permissions related to user management",
    
}
This api end point will return the details of the permission group matching the passed id
- idunique id of the permission group whose details is required
{
    "id": 1,
    "name": "Manage Permissions",
    "status": "Active",
    "permissions": [
        {
            "id": 1,
            "name": "Add Permission",
            "description": null,
            "status": "active"
        },
        {
            "id": 2,
            "name": "Update Permission",
            "description": null,
            "status": "active"
        },       
    ]
}
This api lists all the permission groups added in the application.
- limitis non-required parameter. Value of this parameter decides that number of results to be returned as response. Default value is as per the application settings
- pageis non-required parameter. Value of this parameter is used for identifying the current page for the paginated result. Default value is 1
- nameis non-required parameter. It is a search filter to get permission-groups whose name similar to passed value
- statusis non-required parameter. It is a search filter to get permission-groups whose status is as per the passed value
{
    "data": [
        {
            "id": 1,
            "name": "Manage Permissions",
            "description": null,
            "status": "Active"
        },
        {
            "id": 2,
            "name": "Manage Roles",
            "description": "This group has all the permissions to manage the role",
            "status": "Active"
        }
    ],
    "pagination": {
        "totalResult": 2,
        "count": 2,
        "per_page": 5,
        "current_page": 1,
        "total_pages": 1
    }
}