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

This proposes a fix for 1774 #5998

Closed

Conversation

smithellis
Copy link
Contributor

@smithellis smithellis commented May 8, 2024

Uses the get_autocomplete_suggestions method from api.py when we receive a GET request that contains to

  • This ensures that what is sent as 'to' is handled like entered text
  • api.py returns confirmed User or Group in the right format
  • We populate the field with the returned items

Caveat : if a name is passed in 'to' that is both a User and a Group, both will be returned and populated (if the user has
permissions). The end user can remove one if they'd like. This shouldn't be a problem as the bulk of this usage will be from people clicking "Private Message" on a profile page.

* Using the `get_autocomplete_suggestions` method from `api.py`
* * This ensures that what is sent as 'to' is handled like
entered text
** `api.py` returns confirmed User or Group in the right format
** We populate the field with the returned items

Caveat : if a name is passed in 'to' that is both a User and a
Group, both will be returned and populated (if the user has
 permissions). The end user can remove one if they'd like. This
shouldn't be a problem as the bulk of this usage will be from
people clicking "Private Message" on a profile page.
Copy link
Contributor

@escattone escattone left a comment

Choose a reason for hiding this comment

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

This works great, but I would recommend an organizational change.

kitsune/messages/views.py Outdated Show resolved Hide resolved
* Move bulk of code into utils.py as two functions
** `create_suggestion` which takes one instance object of type
user or group and returns suggestion code needed by js
** `find_users_and_groups_by_search` will return either all users
and groups that match search criteria OR exact match in the case
of a `to` param -- this avoids cases where something like
`?to=s` would return all items starting with s on a GET request
@smithellis smithellis requested a review from escattone May 9, 2024 19:53
}


def find_users_and_groups_by_search(pre, show_groups=False, exact=False):
Copy link
Contributor

Choose a reason for hiding this comment

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

Since both current use cases -- the API and the new_message view -- need suggestions rather than DB objects, and there's no current use case for DB objects, I would have this function return a list of suggestions by default, and perhaps add a keyword argument that allows the caller to ask for a list of DB objects instead.

Do you think the limit of users or groups -- in this case 10 -- should be configurable via a keyword argument as well?

@akatsoulas
Copy link
Collaborator

I opened PR #6001 as an alternative suggestion to populate the username by default. It is assumed that's always a user since it's populated by the username of the profile. Thoughts?

@smithellis
Copy link
Contributor Author

In the original work I was told there was no reason to grab the 'to' from a GET request, so I removed that functionality. We now found this use case for it. Thinking to the future, if our form allows users and groups in the to field, it could be problematic to some later use case - and the dev will have to go looking around to figure out why this form seemingly accepts a to but not in all the same cases he/she/they might expect. I was honestly not willing to assume I should only fix for this one case, because as sure as I did that I'd get a ticket about how groups can't be sent as a to param but are allowed on the form.
If that isn't something to be worried about, then #6001 is an eloquent solution.
Let me know your thoughts...We need to decide on:
1 - Just your proposed fix OR
2 - Refactor plus your proposed fix OR
3 - Continue with group inclusive fix and refactor

@akatsoulas
Copy link
Collaborator

Since groups target many users, I would argue that it's best to explicitly type the name in the form instead of prepopulating the field (now and in the future) to avoid spamming by mistake. Moreover, since this is a GET request passed as a parameter I believe it's good hygiene to default to the User: instance for the same reasons - to avoid spamming groups

Regarding the refactor, it's totally up to you. For what is worth I don't see a use case right now for refactoring the code. The refactor won't make it more DRY than it is right now. FWIW, I would opt for just getting the fix in.

@smithellis
Copy link
Contributor Author

Closing in favor of #6001

@smithellis smithellis closed this May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants