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

Group Gambit Improvements #2192

Merged
merged 4 commits into from Jun 8, 2020
Merged

Group Gambit Improvements #2192

merged 4 commits into from Jun 8, 2020

Conversation

askvortsov1
Copy link
Sponsor Member

@askvortsov1 askvortsov1 commented Jun 7, 2020

Needed for FriendsOfFlarum/user-directory#39

Changes proposed in this pull request:

  • Add ID to fields searched in group gambit. This is needed to search for groups that have a space in their names. When we add in group slugs as per Add unique slug to groups #1991, this should be less necessary, but good to have for now.
  • Use joins instead of looping in group gambit

Confirmed

  • Frontend changes: tested on a local Flarum installation.
  • Backend changes: tests are green (run composer test).

- Use joins instead of looping in group gambit
Copy link
Member

@clarkwinkelmann clarkwinkelmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm globally ok with the approach, but I'm thinking it might be more appropriate to actually use is_numeric to make the difference between a name and ID.

So my suggestions would be, if the identifier is numeric, check IDs. Otherwise, do the check on the names.

That way if the name of a group is a number, those results will not be returned when a program uses the API to return the list of users for a specific other group that has that ID.

It will have the same issues as the current "get user" endpoint, but I think here it makes most sense to have ID return only the correct results, and "name" to be a convenience for the few searches that will be typed by hand https://github.com/flarum/core/blob/master/src/Api/Controller/ShowUserController.php#L51

Then there's just the question of the comma-separated list of identifiers. Either use a loop and do an is_numeric on each identifier before adding it to an orWhere, or use the first value to apply all of the OR to ids or names.

I hope that makes sense.

src/User/Search/Gambit/GroupGambit.php Outdated Show resolved Hide resolved
@askvortsov1
Copy link
Sponsor Member Author

I'm globally ok with the approach, but I'm thinking it might be more appropriate to actually use is_numeric to make the difference between a name and ID.

Is the goal to avoid groups named "123"? Personally I'd prefer if we could query with a slug instead of an ID, but there's currently no slug mechanism. Maybe I should make a group slug PR first, and then when that's merged we can use that here?

@clarkwinkelmann
Copy link
Member

I think the slug thing needs more discussion before it happens, so I'd suggest making the ID the primary way to use the gambit for now, so that extensions like user-directory can start using it starting next beta even if we don't decide on anything for the slug before then.

Copy link
Member

@clarkwinkelmann clarkwinkelmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just reading the code, ok for me

@askvortsov1 askvortsov1 merged commit 4da2994 into master Jun 8, 2020
@askvortsov1 askvortsov1 deleted the as/improve_group_gambit branch June 8, 2020 21:35
@askvortsov1 askvortsov1 added this to the 0.1.0-beta.14 milestone Jun 8, 2020
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

Successfully merging this pull request may close these issues.

None yet

3 participants