romanbican / roles

Powerful package for handling roles and permissions in Laravel 5
MIT License
1.16k stars 296 forks source link

user role has no permission but can() return true? #191

Closed xlkit456852 closed 8 years ago

xlkit456852 commented 8 years ago

1、User -- Roles admin(id=1) -- super.admin test(id=2) -- admin

2、Role -- Permission super.admin -- admin.manage

but I run: $user = User::find(2); dd($user->can('admin.manage')); it returns true?

liebsen commented 8 years ago

Maybe this block

    return $this->getPermissions()->contains(function ($value, $key) use ($permission) {
        return $permission == $value->id || Str::is($permission, $value->slug);
    });

should be replace by this

    return $this->getPermissions()->contains(function ($value, $key) use ($permission) {
        return $permission == $value->id || $permission == $value->slug;
    });

Bican\Roles\Traits\HasRoleAndPermission I'm guessing.

xlkit456852 commented 8 years ago

I figured out this. Because rolePermissions() has this "->orWhere('roles.level', '<', $this->level())" condition,and my super admin 's level(1) is lower than normal admin(2)....Now I set my super admin level 100

nikolaynesov commented 8 years ago

@xlkit456852 is the issue resolved?

xlkit456852 commented 8 years ago

yes,resolved.

nikolaynesov commented 8 years ago

@xlkit456852 Don't you mind to close the issue then?