Users API: Filter by email - #530
Conversation
4872705 to
86fc745
Compare
johnbaldwin
left a comment
There was a problem hiding this comment.
@OmarIthawi Once we release this api update, we may have to live with it for a long time.
It seems like a very small addition, but I'm concerned on the context that we are using a list context to check on a single user. Do you see where we want a single email address to be shared among multiple users?
To fix this, how about using icontains instead of exact? Now we have the proper list context
Then the API consumer can check for specific matches in the response set. This would also be helpful when filtering for users from a specific domain.
Not really. At least not within a single site.
Thanks @johnbaldwin. I wanted the During our discussion with Maxi (although not written anywhere) we thought of an additional more generic class UserIndexFilter(FilterSet):
search_term = CharFilter()
email = ...
class Meta:
model = User
fields = [
'search',
'email',
]
def filter_search_term(self, queryset, name, value):
return queryset.filter(
Q(username__icontains=value) | Q(email__icontains=value) | Q(profile__name__icontains=value)
)I didn't want to add this feature now because no one requested it yet and we have other features that are being requested. |
|
@OmarIthawi My caution again, adding this effectively will become a contractual obligation and we will have to live with for the duration that 'v1' of this API lives. I see it as an anti-pattern because we are using a list view filter to report the state of a single record. However, this is also a rather benign example of an anti-pattern, so I'll approve the PR and hopefully we won't regret it |
|
@OmarIthawi Can you at least use a different query param name instead of |
86fc745 to
20b82af
Compare
Great suggestion. Thanks @johnbaldwin! I've updated the PR accordingly. |
grozdanowski
left a comment
There was a problem hiding this comment.
I can only comment on the general idea (not the details of implementation) - looks according to spec required. I can see some reasoning for a list:
- ?email=XXXX search should return a list (since it is not exact)
therefore: - ?email_exact=XXXX should also return a list for consistency, but can only return one record of course.
Thanks @grozdanowski. Yes, the other (now rejected) alternatives were one of the following: A. Overload the single User API to accept email as a primary key: B. Create a new API endpoint just for that. Not really RESTful since this is something definitely the C. Maxi and I ended up choosing the list-but-not-really-list although it's not a prefect approach. The main motivator it was very simple to test and implement besides being 100% fulling the immediate needs. @johnbaldwin ☝️ |
This change makes it possible to know whether a specific user is registered in a site or not.
Returning either a list of one user, or no one at all:
RED-594: Enrollment API update epic.