Skip to content

Bug: TypeError checking permissions #505

@virdb

Description

@virdb

PHP Version

7.4.32 | 8.1.12

CodeIgniter4 Version

4.2.8

Shield Version

v1.0.0-beta.3

Which operating systems have you tested for this bug?

Linux

Which server did you use?

cli-server (PHP built-in webserver)

Database

MariaDB 10.9.3

Did you customize Shield?

Just disabled registration and configured groups, permissions and matrix

What happened?

when I check for user permissions, got a Type error.

My code in controller:

$user = auth()->user();
if ( $user->can('developer') || $user->can('admin.user'))
 {
   // ...
 }

Error:

TypeError
substr() expects parameter 3 to be int, bool given 
VENDORPATH/codeigniter4/shield/src/Authorization/Traits/Authorizable.php at line 259

...
259             $check = substr($permission, 0, strpos($permission, '.')) . '.*';
...

Steps to Reproduce

  • composer require codeigniter4/shield:v1.0.0-beta.3
  • setup groups, permissions and matrix in AuthGroups.php
  • add a user with appropriate permissions
  • check if user has permission
  • got the error

Expected Output

expected the can() method works

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions