flarum / framework

Simple forum software for building great communities.
http://flarum.org/
6.27k stars 826 forks source link

Tag state loaded for first user in `tag_user` table instead of logged-in user in `ShowTagController` #4007

Closed rafaucau closed 4 weeks ago

rafaucau commented 1 month ago

Current Behavior

The tag state is being loaded for the first user in the database instead of the currently logged-in user. This issue affects extensions like Follow Tags that rely on eager loading of the tag state, causing them to not function correctly. See: https://github.com/FriendsOfFlarum/follow-tags/issues/72#issuecomment-2222283587

Steps to Reproduce

  1. Log in as a user other than the first user in the database.
  2. Observe the subscription state of tag on tag page.
  3. The tag state reflects the subscriptions of the first user in the database rather than the currently logged-in user.

Expected Behavior

The subscription state of tags should be loaded for the currently logged-in user, ensuring that extensions like Follow Tags work as expected.

Screenshots

Modified vendor/flarum/tags/src/Api/Controller/ShowTagController.php to display some info: image

Environment

Additional Context

This issue was initially identified while troubleshooting an issue with the Follow Tags (v1.2.3) extension. The problem lies in this controller: ShowTagController

https://github.com/flarum/framework/blob/2a693db1b65cf7b0f7e76cbaa695a5e65bd947f6/extensions/tags/src/Api/Controller/ShowTagController.php#L72

dsevillamartin commented 1 month ago

That seems right regarding the source - this is what Clockwork shows as the query coming with no user constraint

image image

luceos commented 1 month ago

Is either of you able to provide a patch to 1.x. I'm not sure this applies to 2.x, I'd have to check.

rafaucau commented 1 month ago

I could create a PR. Probably, it is necessary to modify SlugDriverInterface to accept additional query parameters for this to work. Maybe @SychO9 has some hints?

rafaucau commented 1 month ago

@luceos path provided in #4008 and #4009