Git Product home page Git Product logo

laravel-acl's Introduction

Laravel ACL

Latest Version on Packagist Software License

Continuous Integration Static Analysis Total Downloads

Laravel ACL (Access Control List) is a simple role-permission ACL for the Laravel Framework. This package was based on the great package Caffeinated/Shinobi but is fully compatible with Laravel's built-in Gate/Authorization system.

Documentations

Laravel Version Compatibility

Laravel Package
8.x and below 6.x
9.x 9.x
10.x 10.x
11.x 11.x

Installation

Via Composer

$ composer require yajra/laravel-acl:^11

Configuration

Register service provider (Optional on Laravel 5.5+).

Yajra\Acl\AclServiceProvider::class

Publish assets (Optional):

$ php artisan vendor:publish --tag=laravel-acl

Run migrations:

php artisan migrate

Change log

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Security

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

Credits

License

The MIT License (MIT). Please see License File for more information.

laravel-acl's People

Contributors

brandpublico avatar carusogabriel avatar chaospower avatar darrelenano avatar ejgandelaberon avatar hpacleb avatar jaydons avatar jidago avatar jiwom avatar mark-git07 avatar nicacode avatar orumad avatar redredimano avatar rez1dent3 avatar shairayo avatar yajra avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

laravel-acl's Issues

The user()->can($permission) is never called and not working

Summary of problem or feature request

I'm trying to access a route with given permission but it's not authorizing access
when i try to debug the method "Can" which is being called in the middleware
the method is never called from the HasPermission.

How to debug this issue?

class PermissionMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request $request
     * @param  \Closure $next
     * @param  string $permission
     * @return mixed
     */
    public function handle($request, Closure $next, $permission)
    {

        if (! $request->user() || ! $request->user()->can($permission)) {
            if ($request->ajax()) {
                return response()->json([
                    'error' => [
                        'status_code' => 401,
                        'code'        => 'INSUFFICIENT_PERMISSIONS',
                        'description' => 'You are not authorized to access this resource.',
                    ],
                ], 401);
            }

            return abort(401, 'You are not authorized to access this resource.');
        }

        return $next($request);
    }
}

Migrations doesn't allow to change table names

Because of HasRole line 148

public function scopeHavingRoles($query, array $roles)
    {
        return $query->whereExists(function ($query) use ($roles) {
            $query->selectRaw('1')
                  ->from('role_user')
                  ->whereRaw('role_user.user_id = users.id')
                  ->whereIn('role_id', $roles);
        });
    }

Table name should also be configurable

Migrations loaded doesn't allow to customize User model

Summary of problem or feature request

When AclServiceProvider.php calls the loadMigrationsFrom() method, the published migrations (that I changed to reflect a customized User model) will be overwrited by the original migration, stored at yajra/laravel-acl/migrations.

In my case, I have Usuario model instead of User model. The service respects the model assigned at config/auth.php, but the migration fixes internally it to user.

Code snippet

AclServiceProvider.php

    /**
     * Publish package migration files.
     */
    protected function publishMigrations()
    {
        $this->loadMigrationsFrom(__DIR__ . '/../migrations'); //This line could be removed
        $this->publishes([
            __DIR__ . '/../migrations' => database_path('migrations'),
        ], 'laravel-acl');
    }

2015_12_20_100004_create_role_user_table.php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreateRoleUserTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('role_user', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('role_id')->unsigned()->index();
            $table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');
            $table->integer('user_id')->unsigned()->index();
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migration.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('role_user');
    }
}

I would suggest to remove the indicated line at AclServiceProvider.php file.

Middleware canAtLeast for Route::group

Hi Arjay!

I'm trying use the 'canAtLeast' as a Route::group middleware.

Route::group(['middleware' => 'canAtLeast:contratos.externo,contratos.update'], function () {
    Route::get('contratos/contratistas/list', ['as' => 'contratos.contratistasLista', 'uses' => 'Contratos\ContratosController@contratistasLista']);
    Route::post('contratos/contratistas/add', ['as' => 'contratos.addContratista', 'uses' => 'Contratos\ContratosController@addContratista']);
    Route::get('contratos/documentacion/data', ['as' => 'contratos.documentacionData', 'uses' => 'Contratos\ContratosController@documentacionData']);
});

The problem is only the first permission is evaluated (contratos.externo).

I debug your CanAtLeastMiddleware.php file and I see the $permissions argument for this kind of middleware come as an indeterminate number of string arguments (one for every permission you fill in canAtLeast middleware.

I'm running Laravel v.5.3.28 (the last one at this time).

Thanks!

permission not working

i think i'm doing something wrong, not sure, i searched at stackoverflow but i not find anything related to this package, so i followed the installation tutorial at documentation, and inserted a admin permission to test a user, but even after that he keep returning "You are not authorized to access this resource."

i'm using a api route resource, like this:

Route::group(['middleware' => ['auth:api', 'role:admin']], function() {
	Route::resource('users', User\UserController', ['except' => 'edit']);
});

this is my table: permissions
permission-table
this is my tabke: permissions_role
permissions-role-table

HasRole bug

  1. I can't use "can" method, before auth. But I need it.
    For example:
$user = User::findOrFail(1);
$user->can('something');
  1. When I'm authenticated (and I'm using guards), method "can" doesn't work.
    For example:
auth()->guard('staff')->login($user);
auth()->guard('staff')->user()->can('something');

But when I get roles - they are. When I try to get permissions like that:

auth()->guard('staff')->user()->permissions; // returns null
auth()->guard('staff')->user()->getPermissions(); // returns array of permissions [0 => 'permission slug']

I hope you will help me, thx!

Cannot override default models

I've copied Role and Permission to app dir and change config/acl.php to point to that models but original ones steel are used

Inside GateRegistrar there is model that is pointing to Yajra\Acl\Models\Permission` hardcoded.

HasPermission trait too

and AclServiceProvider

[Question] Trying to understand permissions in order to create UI for managing ACL

Managing Roles are straightforward; name, slug, and a description. Though it's not clear what system is for.

Permissions is where I feel is not fully documented. Don't see any information on this except in a Test Case. Also while reading through source code, I see HasPermission trait. Why is that not added to the User model for retrieving permissions of a user or is this optional and one would only know if they happened to dig through source code?

Two actual questions; What mechanism is there for creating a permission other than using the create facade on Permission model? What is resource and system referring two and how is it being used during authorization?

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.