Skip to content
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

Policy add command incorrectly inserts policy resulting in error #55

Closed
timyourivh opened this issue Mar 8, 2023 · 5 comments
Closed

Comments

@timyourivh
Copy link

Package version used: casbin/laravel-authz: ^3.1 (v3.1.4 in lockfile)

When trying out this package I tried adding a policy using the policy:add command. As stated in the documentation found in the README.md:

README.md snippet

Using artisan commands

You can create a policy from a console with artisan commands.
(...)
To Role::

php artisan policy:add writer,articles,edit

I ran command php artisan policy:add admin,posts,index. This resulted in the following record being inserted:

image

Which I assumed was incorrect.
It also throws an error when comparing/checking the rule:

image

I manually changed the rule to the way the Enforcer facade adds it:

image

Which worked. So I think this is a bug.


Sidenote:

The command policy:add implies that it adds a policy while Enforcer::addPermissionForUser() (which does the same) implies that it adds a permission which is inconsistent. I suggest renaming one of the two to match the other.

@hsluoyz
Copy link
Member

hsluoyz commented Mar 8, 2023

@timyourivh hi, can you make a PR to fix it?

@hsluoyz
Copy link
Member

hsluoyz commented Mar 9, 2023

@leeqvip

@leeqvip
Copy link
Member

leeqvip commented Mar 19, 2023

@timyourivh The fourth parameter of this command is the policy string, separated by commas(,). I followed your steps, but it didn't reproduce in my console. Which terminal do you use, is it a character problem?

@timyourivh
Copy link
Author

@leeqvip That appears to be it!
Interesting, I have a powershell script to add shorthand's but when using the shorthand for php artisan (which is pa for me) in combination with policy:add some how doesn't work:

image

I was already wondering what could be the issue since I couldn't find any issues or bug in the code responsible :p

@timyourivh
Copy link
Author

Note:

The docs state that php artisan vendor:publish will "will create a new model config file and a new lauthz config file" but instead will display a list of all publishable assets available and launch a prompt to choose one. I suggest adding the tags in the tutorial resulting in:

php artisan vendor:publish --tag=laravel-lauthz-config --tag=laravel-lauthz-migrations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants