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

Breaks ::class User gate #21

Closed
clarkwinkelmann opened this issue Jul 16, 2021 · 2 comments
Closed

Breaks ::class User gate #21

clarkwinkelmann opened this issue Jul 16, 2021 · 2 comments

Comments

@clarkwinkelmann
Copy link

When this extension is enabled, it's no longer possible to use model-less calls on the gate for the User model.

It's the same issue that's currently plaguing the Tags extension in Flarum https://github.com/flarum/core/issues/2908

An extension that uses such a call is my shadow ban extension with $actor->can('shadowBan', User::class) https://github.com/clarkwinkelmann/flarum-ext-shadow-ban/blob/main/src/Scope/ViewUser.php#L21

[2021-07-16 16:09:24] flarum.ERROR: TypeError: Askvortsov\FlarumWarnings\Access\UserPolicy::can(): Argument flarum/framework#3 ($user) must be of type Flarum\User\User, string given in /home/metabullet/public_html/vendor/askvortsov/flarum-moderator-warnings/src/Access/UserPolicy.php:26

The error is in this file

public function can(User $actor, $ability, User $user)
, the third parameter should accept a string as well.

Reported on the forum here https://discuss.flarum.org/d/23228-moderator-warnings-extension/87

@askvortsov1
Copy link
Owner

Isn't our convention to use new Guest() instead of User::class?

@clarkwinkelmann
Copy link
Author

There's no convention I'm aware of.

Using ::class to check permissions to create something that doesn't exist yet is a standard Laravel practice which we previously implemented into core. But extensions can break it due to the can() function which itself isn't a Laravel feature.

Another option could be to not proxy ::class gates through can() in core, but that would be a breaking change.

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

2 participants