rappasoft / vault

Roles & Permissions for the Laravel 5 Framework
MIT License
103 stars 10 forks source link

permission_role allows for multiple repeating entries #7

Closed makstr closed 9 years ago

makstr commented 9 years ago

screen shot 2015-02-09 at 13 18 41

rappasoft commented 9 years ago

@petewwa what steps are you taking to get the above result so I can trace through the source?

makstr commented 9 years ago

I just got started and this occurs randomly. I followed your VaultTableSeeder and created some permissions and roles of my own. Then when I tried to manipulate them via the browser I received strange results such as administrator role having the View Administrator Link attached to it 3 times

    $permission_model = Config::get('vault.permission');
        $flyAbove = new $permission_model;
        $flyAbove->name = 'fly_above_the_ground';
        $flyAbove->display_name = 'Fly above the ground';
        $flyAbove->system = true;
        $flyAbove->created_at = \Carbon\Carbon::now();
        $flyAbove->updated_at = \Carbon\Carbon::now();
        $flyAbove->save();

        $rolePrototyper = new $role_model;
        $rolePrototyper->name = 'Prototyper';
        $rolePrototyper->created_at = \Carbon\Carbon::now();
        $rolePrototyper->updated_at = \Carbon\Carbon::now();
        $rolePrototyper->save();
        $rolePrototyper->attachPermission($flyAbove);

        $user_model = Config::get('auth.model');
        $user_model::first()->attachRole($rolePrototyper);
makstr commented 9 years ago

By the way what purpose does the "system" attribute in permission model have?

rappasoft commented 9 years ago

System is just a flag, it takes away the delete button on the UI so you don't accidentally delete it if it's really important.

rappasoft commented 9 years ago

Also, can you try to wipe everything, run the seed once, then use the UI to add your roles and permissions? The seeder isn't going to do many checks when using it, however the CRUD operations on the UI should prevent it from doing the above, if it isn't then theres a bug that needs to be fixed. However, the above won't crash your application because the code will still see that it exists and perform the right operations, it's just annoying and shouldn't be doing that if it is. But try this first.

rappasoft commented 9 years ago

Have you tried the above?