-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Suggestion] Ability to assign roles to user and/or model entity/id #181
Comments
@konovalov-nk sure |
@kodeine ok, thanks. I've also fixed some issues as well. Permission slugs.
Roles and permissions relations from actual model instances. When I've tried to use this package on existing database models like that: $user_admin = \App\User::first();
$user_admin->assignRole(ROLE_ADMIN);
// $user_admin->getRoles is empty!
$this->assertEquals($user_admin->getRoles(), [
1 => ROLE_ADMIN
]);
// $user_admin->getPermissions is empty!
$this->assertEquals($user_admin->getPermissions(), $admin_role->getPermissions()); It wouldn't work for me. However, new created user works: $user_admin = new User();
$user_admin->firstname = 'Role';
$user_admin->lastname = 'test';
$user_admin->newsletter = 0;
$user_admin->email = 'role@test.com';
$user_admin->password = 'RoleTest';
$user_admin->save();
$user_admin->assignRole(ROLE_ADMIN);
// Test passes.
$this->assertEquals($user_admin->getRoles(), [
1 => ROLE_ADMIN
]);
// Test passes.
$this->assertEquals($user_admin->getPermissions(), $admin_role->getPermissions()); I had to modify core code to fix that behavior (see this commit). Wonder why no one encountered this on Laravel 5.3 |
@konovalov-nk |
@kodeine So, I guess it would be better if I spend some time to merge Should I make pull request now or it's better to fix everything and send proper pull request later? ;) |
@konovalov-nk please make a proper PR when you have time :) no rush. |
@kodeine Sure, thank you for help! |
@kodeine I have one more question. From: public function can($permission, $operator = null, $mergePermissions = []) To: public function can($permission, $model = '', $reference_id = 0, $operator = null, $mergePermissions = []) Possible outcomes:
public function can($permission, $operator = null, $mergePermissions = [])
{
$model = '';
$reference_id = 0;
return $this->able($permission, $model, $reference_id, $operator, $mergePermissions);
} |
@kodeine I've decided to make 3rd outcome since there are a lot of things changed. See pull request. |
Basically, I've already implemented the feature, see this fork.
Here how it works:
I'm using it like this:
This allows me to assign roles to user per entities. For example, users could give other users permissions to edit their posts, etc. Much like groups in a facebook.
Should I clean up my code a little bit and make a pull request?
The text was updated successfully, but these errors were encountered: