All Projects → Laravel-Backpack → Permissionmanager

Laravel-Backpack / Permissionmanager

Licence: other
Admin interface for managing users, roles, permissions, using Backpack CRUD

Projects that are alternatives of or similar to Permissionmanager

Brandenburg
Laravel Authentication Package
Stars: ✭ 79 (-78.24%)
Mutual labels:  laravel, authentication, acl
Nova Permission
A Laravel Nova tool for Spatie's laravel-permission library
Stars: ✭ 294 (-19.01%)
Mutual labels:  laravel, acl, permission
Laravel Acl
This package helps you to associate users with permissions and permission groups with laravel framework
Stars: ✭ 404 (+11.29%)
Mutual labels:  laravel, authentication, acl
Laravel Auth
Laravel 8 with user authentication, registration with email confirmation, social media authentication, password recovery, and captcha protection. Uses offical [Bootstrap 4](http://getbootstrap.com). This also makes full use of Controllers for the routes, templates for the views, and makes use of middleware for routing. The project can be stood u…
Stars: ✭ 2,692 (+641.6%)
Mutual labels:  laravel, authentication, user-management
objection-authorize
isomorphic, "magical" authorization integration with Objection.js 🎉
Stars: ✭ 71 (-80.44%)
Mutual labels:  acl, permission
actix-casbin-auth
Casbin Actix-web access control middleware
Stars: ✭ 40 (-88.98%)
Mutual labels:  acl, permission
sqlx-adapter
Asynchronous casbin adapter for mysql, postgres, sqlite based on sqlx-rs
Stars: ✭ 27 (-92.56%)
Mutual labels:  acl, permission
laravel-casbin
This repository has moved to https://github.com/php-casbin/laravel-authz
Stars: ✭ 42 (-88.43%)
Mutual labels:  acl, permission
Auth Tests
Always-current tests for Laravel's authentication system. Curated by the community.
Stars: ✭ 230 (-36.64%)
Mutual labels:  laravel, authentication
Acl
The Hoa\Acl library.
Stars: ✭ 27 (-92.56%)
Mutual labels:  acl, permission
casbin-ex
An authorization library that supports access control models like ACL, RBAC, ABAC in Elixir
Stars: ✭ 37 (-89.81%)
Mutual labels:  acl, permission
lua-casbin
An authorization library that supports access control models like ACL, RBAC, ABAC in Lua (OpenResty)
Stars: ✭ 43 (-88.15%)
Mutual labels:  acl, permission
ng2-acl
Role based permissions for Angular v2++
Stars: ✭ 15 (-95.87%)
Mutual labels:  acl, permission
sqlalchemy-adapter
SQLAlchemy Adapter for PyCasbin
Stars: ✭ 53 (-85.4%)
Mutual labels:  acl, permission
Bouncer
Eloquent roles and abilities.
Stars: ✭ 2,763 (+661.16%)
Mutual labels:  laravel, acl
browser-acl
Simple acceess control (ACL) library for the browser inspired by Laravel's guards and policies.
Stars: ✭ 36 (-90.08%)
Mutual labels:  acl, user-management
Laravel Authentication Acl
Laravel authentication and ACL admin panel package based on sentry
Stars: ✭ 292 (-19.56%)
Mutual labels:  laravel, acl
Flask Appbuilder
Simple and rapid application development framework, built on top of Flask. includes detailed security, auto CRUD generation for your models, google charts and much more. Demo (login with guest/welcome) - http://flaskappbuilder.pythonanywhere.com/
Stars: ✭ 3,603 (+892.56%)
Mutual labels:  crud, authentication
Laravel Adminless Ldap Auth
Authenticate users in Laravel against an adminless LDAP server
Stars: ✭ 199 (-45.18%)
Mutual labels:  laravel, authentication
Shinobi
👺 Simple and light-weight role-based permissions system for Laravel's built in Auth system.
Stars: ✭ 349 (-3.86%)
Mutual labels:  laravel, authentication

Backpack\PermissionManager

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Style CI Total Downloads

Admin interface for spatie/laravel-permission. It allows admins to easily add/edit/remove users, roles and permissions, using Laravel Backpack.

As opposed to some other packages:

  • a user can have multiple roles;
  • a user can have extra permissions, in addition to the permissions on the roles he has;

This package is just a user interface for spatie/laravel-permission. It will install it, and let you use its API in code. Please refer to their README for more information on how to use in code.

Edit a user in Backpack/PermissionManager

Security updates and breaking changes

Please subscribe to the Backpack Newsletter so you can find out about any security updates, breaking changes or major features. We send an email every 1-2 months.

Install

  1. This package assumes you've already installed Backpack for Laravel. If you haven't, please install Backpack first.

  2. In your terminal:

composer require backpack/permissionmanager
  1. Finish all installation steps for spatie/laravel-permission, which as been pulled as a dependency. Run its migrations. Publish its config files. Most likely it's:
php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider" --tag="migrations"
php artisan migrate
php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider" --tag="config"
// then First, add the Spatie\Permission\Traits\HasRoles trait to your User model(s)
  1. Publish the config file & run the migrations
php artisan vendor:publish --provider="Backpack\PermissionManager\PermissionManagerServiceProvider"
  1. The package assumes it's ok to use App\Models\BackpackUser to administer Users. Use a different one if you'd like by changing the user model in the config/backpack/permissionmanager.php file. Any model you're using, make sure it's using the CrudTrait and HasRoles traits:
<?php namespace App;

use Backpack\CRUD\app\Models\Traits\CrudTrait; // <------------------------------- this one
use Spatie\Permission\Traits\HasRoles;// <---------------------- and this one
use Illuminate\Foundation\Auth\User as Authenticatable; 

class User extends Authenticatable
{
    use CrudTrait; // <----- this
    use HasRoles; // <------ and this

    /**
     * Your User Model content
     */
  1. [Optional] Add a menu item for it in resources/views/vendor/backpack/base/inc/sidebar_content.blade.php or menu.blade.php:
<!-- Users, Roles, Permissions -->
<li class="nav-item nav-dropdown">
	<a class="nav-link nav-dropdown-toggle" href="#"><i class="nav-icon la la-users"></i> Authentication</a>
	<ul class="nav-dropdown-items">
	  <li class="nav-item"><a class="nav-link" href="{{ backpack_url('user') }}"><i class="nav-icon la la-user"></i> <span>Users</span></a></li>
	  <li class="nav-item"><a class="nav-link" href="{{ backpack_url('role') }}"><i class="nav-icon la la-id-badge"></i> <span>Roles</span></a></li>
	  <li class="nav-item"><a class="nav-link" href="{{ backpack_url('permission') }}"><i class="nav-icon la la-key"></i> <span>Permissions</span></a></li>
	</ul>
</li>
  1. [Optional] If you want to use the @can handler inside Backpack routes, you can:

(6.A.) Change Backpack to use the default web guard instead of its own guard. Inside config/backpack/base.php change:

    // The guard that protects the Backpack admin panel.
    // If null, the config.auth.defaults.guard value will be used.
-   'guard' => 'backpack',
+   'guard' => null,

Note:

  • when you add new roles and permissions, the guard that gets saved in the database will be "web";

OR

(6.B.) Add a middleware to all your Backpack routes by adding this to your config/backpack/base.php file:

    // The classes for the middleware to check if the visitor is an admin
    // Can be a single class or an array of clases
    'middleware_class' => [
        App\Http\Middleware\CheckIfAdmin::class,
        \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
+       Backpack\Base\app\Http\Middleware\UseBackpackAuthGuardInsteadOfDefaultAuthGuard::class,
    ],

Why? spatie/laravel-permission uses the Auth facade for determining permissions with @can. The Auth facade uses the default guard defined in config/auth.php, NOT our backpack guard.

Please note:

  • this will make auth() return the exact same thing as backpack_auth() on Backpack routes;
  • you only need this if you want to use @can; you can just as well use @if(backpack_user()->can('read')), which does the exact same thing, but works 100% of the time;
  • when you add new roles and permissions, the guard that gets saved in the database will be "backpack";
  1. [Optional] Disallow create/update on your roles or permissions after you define them, using the config file in config/backpack/permissionmanager.php. Please note permissions and roles are referenced in code using their name. If you let your admins edit these strings and they do, your permission and role checks will stop working.

Customize UserCrudController

If you would like to add more fields to the default user controller provided by this package, you can bind your own controller to overwrite the one provided in this package:

// in some ServiceProvider, AppServiceProvider for example

$this->app->bind(
    \Backpack\PermissionManager\app\Http\Controllers\UserCrudController::class, //this is package controller
    \App\Http\Controllers\Admin\UserCrudController::class //this should be your own controller
);

// this tells Laravel that when UserCrudController is requested, your own UserCrudController should be served.

API Usage

Because the package requires spatie/laravel-permission, the API will be the same. Please refer to their README file for a complete API. Here's a summary though:

Using permissions

A permission can be given to a user:

backpack_user()->givePermissionTo('edit articles');

A permission can be revoked from a user:

backpack_user()->revokePermissionTo('edit articles');

You can test if a user has a permission:

backpack_user()->hasPermissionTo('edit articles');

Saved permissions will be registered with the Illuminate\Auth\Access\Gate-class. So you can test if a user has a permission with Laravel's default can-function.

backpack_user()->can('edit articles');

Using roles and permissions

A role can be assigned to a user:

backpack_user()->assignRole('writer');

A role can be removed from a user:

backpack_user()->removeRole('writer');

You can determine if a user has a certain role:

backpack_user()->hasRole('writer');

You can also determine if a user has any of a given list of roles:

backpack_user()->hasAnyRole(Role::all());

You can also determine if a user has all of a given list of roles:

backpack_user()->hasAllRoles(Role::all());

The assignRole, hasRole, hasAnyRole, hasAllRoles and removeRole-functions can accept a string, a Role-object or an \Illuminate\Support\Collection-object.

A permission can be given to a role:

$role->givePermissionTo('edit articles');

You can determine if a role has a certain permission:

$role->hasPermissionTo('edit articles');

A permission can be revoked from a role:

$role->revokePermissionTo('edit articles');

The givePermissionTo and revokePermissionTo-functions can accept a string or a Permission-object.

Saved permission and roles are also registered with the Illuminate\Auth\Access\Gate-class.

backpack_user()->can('edit articles');

Using blade directives

This package also adds Blade directives to verify whether the currently logged in user has all or any of a given list of roles.

@role('writer')
    I\'m a writer!
@else
    I\'m not a writer...
@endrole
@hasrole('writer')
    I\'m a writer!
@else
    I\'m not a writer...
@endhasrole
@hasanyrole(Role::all())
    I have one or more of these roles!
@else
    I have none of these roles...
@endhasanyrole
@hasallroles(Role::all())
    I have all of these roles!
@else
    I don\'t have all of these roles
@endhasallroles

You can use Laravels native @can directive to check if a user has a certain permission.

Upgrade from 3.x to 4.x

To upgrade from PermissionManager 3.x to 4.x:

  • upgrade to spatie/laravel-permission 2.28.2+ - do take note that the DB has changed, and they don't provide a track of the changes;
  • require backpack/permissionmanager version 4.0.* in your composer.json file;
  • delete your old config/backpack/permissionmanager.php file;
  • follow the installation steps above;

If you are upgrading to a Laravel 8 instalation, please note that User Model may have moved from App\User::class to App\Models\User::class, check if your config is compliant with that change config/backpack/permissionmanager.php.

Change log

Please see CHANGELOG for more information what has changed recently.

Screenshots

Roles table view in Backpack/PermissionManager

Overwriting functionality

If you need to modify how this works in a project:

  • create a routes/backpack/permissionmanager.php file; the package will see that, and load your routes file, instead of the one in the package;
  • create controllers/models that extend the ones in the package, and use those in your new routes file;
  • modify anything you'd like in the new controllers/models;

When creating your own controllers, seeders, make sure you use the BackpackUser model, instead of the User model in your app. The easiest would be to use config('backpack.base.user_model_fqn') which pulls in the User model fully qualified namespace, as defined in your config/backpack/base.php. You might need to instantiate it using $model = config('backpack.base.user_model_fqn'); $model = new $model; in order to do things like $model->where(...).

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Please subscribe to the Backpack Newsletter so you can find out about any security updates, breaking changes or major features. We send an email every 1-2 months.

Credits

License

Backpack is free for non-commercial use and 49 EUR/project for commercial use. Please see License File and backpackforlaravel.com for more information.

Hire us

We've spend more than 50.000 hours creating, polishing and maintaining administration panels on Laravel. We've developed e-Commerce, e-Learning, ERPs, social networks, payment gateways and much more. We've worked on admin panels so much, that we've created one of the most popular software in its niche - just from making public what was repetitive in our projects.

If you are looking for a developer/team to help you build an admin panel on Laravel, look no further. You'll have a difficult time finding someone with more experience & enthusiasm for this. This is what we do. Contact us. Let's see if we can work together.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].