-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[Bug] Avoid checking permissions-via-roles on Role
model (ref Model::preventAccessingMissingAttributes()
)
#2227
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
[Bug] Avoid checking permissions-via-roles on Role
model (ref Model::preventAccessingMissingAttributes()
)
#2227
Conversation
Signed-off-by: Julio Motol <julio.motol89@gmail.com>
Why don't change Try this: - if ($this->roles) {
// Try this way
+ if (method_exists($this, 'roles')) {
// Or maybe, i am not sure
+ if (isset($this->roles)) { public function getAllPermissions(): Collection
{
/** @var Collection $permissions */
$permissions = $this->permissions;
if (method_exists($this, 'roles')) {
$permissions = $permissions->merge($this->getPermissionsViaRoles());
}
return $permissions->sort()->values();
} laravel-permission/src/Traits/HasPermissions.php Lines 308 to 318 in dc9c48c
|
I'm down to do that. But what about this: // HasPermissions.php
public function getAllPermissions(): Collection
{
/** @var Collection $permissions */
$permissions = $this->permissions;
if (in_array(HasRoles::class, class_uses($this))) { // Check for the `HasRoles` trait
$permissions = $permissions->merge($this->getPermissionsViaRoles());
}
return $permissions->sort()->values();
} Let me know your thoughts. |
Seems to be working also maybe better if (method_exists($this, 'getPermissionsViaRoles')) {
$permissions = $permissions->merge($this->getPermissionsViaRoles());
} |
I'm inclined to think that |
I think the same, it looks better, but do it works the same? |
That would always result to laravel-permission/src/Traits/HasPermissions.php Lines 297 to 303 in dc9c48c
|
@juliomotol how about |
This reverts commit 4807005.
…roles Signed-off-by: Julio Motol <julio.motol89@gmail.com>
PR has been updated |
while not approved this, this is temporary fix class Role extends \Spatie\Permission\Models\Role
{
protected bool $roles = false; |
@drbyte Any plans on releasing this? |
getAllPermissions()
in Role
Role
model (ref Model::preventAccessingMissingAttributes()
)
Thanks! |
This PR aims to fix an issue when trying to check for
Role
'shasPermissionTo()
whenModel::preventAccessingMissingAttributes()
is enabled.The implemented fix overrides the
HasPermission::getAllPermissions()
to not check for$this->roles
as theRole
model will never have a relationship to itself.