-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Support strings as numeric ids #2548
base: main
Are you sure you want to change the base?
Conversation
I think we need to add some tests for this situation we're trying to fix. A couple observations:
|
Ok, i see it now, but laravel-permission/src/Traits/HasPermissions.php Lines 436 to 439 in 62f22e1
laravel-permission/src/Traits/HasPermissions.php Lines 361 to 368 in 62f22e1
On revokePermissionTo it will faillaravel-permission/src/Traits/HasPermissions.php Lines 453 to 455 in 62f22e1
|
I added some tests but I'm still not sure, I feel like I'm missing something 😕 |
Could this be a breaking change? |
As in need to bump to |
Possibly, if someone uses numbers as names in permissions/roles, they will no longer be able to access those models through the package.
|
I wonder if that scenario could be simply handled with a configuration switch? IMO the number-as-a-name is a rare-use case, but number-as-model-id-integer is vast majority use-case. |
Yes, most likely |
After doing some digging it is not a breaking change(v5), it is a bug fix, #2404 break this(lack of tests) laravel-permission/src/Traits/HasPermissions.php Lines 444 to 450 in d829888
laravel-permission/src/Traits/HasRoles.php Lines 319 to 325 in d829888
|
Same issue here upgrading from v.5.5 to v.6.2. Simple test in tinker: <?php
$permissions = ["10", "20", "30"];
$user->syncPermissions($permissions);
// v.5.5 => no error
// v.6.2 => error: Spatie\Permission\Exceptions\PermissionDoesNotExist There is no [permission] named `10` for guard `web`. Adopting the changes proposed in this PR v.6.2 works fine. |
Looks like this fixes a regression in v6, any plans for this to be merged soon? Is there anything missing in this PR? |
Status: Trying to decide whether this is safe to merge into v6, or whether to tag it as v7 .... and then what the complaints will be about v7 :( |
Should probably be v7 to avoid issues with existing installs |
Dear contributor, because this pull request seems to be inactive for quite some time now, I've automatically closed it. If you feel this pull request deserves some attention from my human colleagues feel free to reopen it. |
Is this still relevant? |
Yes. |
testing #2530 (comment)
Closes #2530
Closes #2543
Closes #2541
pro: this is consistent with laravel
sync
method, buton this part it suggests that you can use int string as name (on wildcards), even so, wildcards seems to work, I don't know if it needs more tests
laravel-permission/tests/WildcardHasPermissionsTest.php
Line 244 in 62f22e1
On v5 was
is_int
, anis_string
, so string as"42"
always is taken asname
laravel-permission/src/Traits/HasPermissions.php
Line 138 in d829888
laravel-permission/src/Traits/HasPermissions.php
Lines 156 to 168 in d829888