askvortsov1 / flarum-moderator-warnings

Moderator Warnings extension for flarum
MIT License
6 stars 7 forks source link

Breaks ::class User gate #21

Closed clarkwinkelmann closed 3 years ago

clarkwinkelmann commented 3 years ago

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 https://github.com/askvortsov1/flarum-moderator-warnings/blob/cb9e8f77dd70b6e701585da24d7fa2e182194865/src/Access/UserPolicy.php#L26 , 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 commented 3 years ago

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

clarkwinkelmann commented 3 years ago

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.