-
Notifications
You must be signed in to change notification settings - Fork 326
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
Servantify get users by unqualified ids or handles #1291
Conversation
e9530df
to
def05b4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable, though I see 5-6 TODOs still in here, I assume you still want to work on them during this PR?
9e51019
to
1982e3d
Compare
The wire-api unittests fail with a mismatch between user profile JSON and swagger. |
Yes, this should've been a draft. |
* Create a newtype for CommaSeparatedList * Write FromHttpApiData instance for Range
We no longer use 'foo@bar.com' in the backend. One exception is while printing errors for federation not implemented. Maybe this should also not use this format.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems a bit weird to convert the unqualified IDs to qualified ones, just to then partition into local (unqualified) and remote ones again, but I think it makes sense in this situation.
There's one point about mutually exclusive parameters that would be good to address soon, but that could also be in a follow-up PR.
case (mUids, mHandles) of | ||
(Just uids, _) -> listUsersByIdsOrHandles self (Public.ListUsersByIds ((`Qualified` domain) <$> fromCommaSeparatedList uids)) | ||
(_, Just handles) -> | ||
let normalRangedList = fromCommaSeparatedList $ fromRange handles | ||
qualifiedList = (`Qualified` domain) <$> normalRangedList | ||
-- Use of unsafeRange here is ok only because we know that 'handles' | ||
-- is valid for 'Range 1 4'. However, we must not forget to keep this | ||
-- annotation here otherwise a change in 'Public.ListUsersByHandles' | ||
-- could cause this code to break. | ||
qualifiedRangedList :: Range 1 4 [Qualified Handle] = unsafeRange qualifiedList | ||
in listUsersByIdsOrHandles self (Public.ListUsersByHandles qualifiedRangedList) | ||
(Nothing, Nothing) -> throwStd $ badRequest "at least one ids or handles must be provided" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So in case both are provided, we just silently ignore the provided handles? Would be nicer to fail, maybe reducing the boilderplate by using some kind of combinator Maybe a -> Maybe b -> Handler (Either a b)
or even API combinator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to not do this for backwards compatibility. Currently nothing breaks if a client sends both of these and handles get ignored if uids are present. So, maybe it is ok to live with this in the old endpoint.
That being said I agree that it would be nicer to throw an error and since we're making a new endpoint, I will just make the parseJSON
for the input fail if both are present.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, you're right. Didn't know it behaved that way, but agree that it's best to keep it for the deprecated endpoint.
Compile issue:
Also, perhaps it's worthwhile to rebase this PR on current develop. |
Use separate domain and id so we don't have to parse the '@'
It was a little clunky to fit this in swagger, hopefully this will be better in swagger3.
Alright, I think stuff should just work now 🤞 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New commit looks good. It still seems like some mutuallyExclusive
combinator could make the instances clearer, especially if the pattern shows up in multiple places, but I'm fine with it for now.
Co-authored-by: Matthias Heinzel <mheinzel@posteo.de>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor typos for the next PR.
libs/wire-api/src/Wire/API/User.hs
Outdated
case (mUids, mHandles) of | ||
(Just uids, Nothing) -> pure uids | ||
(Nothing, Just handles) -> pure handles | ||
(_, _) -> fail "exactly one of qualifie_ids or qualified_handles must be provided." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(_, _) -> fail "exactly one of qualifie_ids or qualified_handles must be provided." | |
(_, _) -> fail "exactly one of qualified_ids or qualified_handles must be provided." |
NamedSchema (Just "ListUsersQuery") $ | ||
mempty | ||
& type_ ?~ SwaggerObject | ||
& description ?~ "exactly one of qualifie_ids or qualified_handles must be provided." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
& description ?~ "exactly one of qualifie_ids or qualified_handles must be provided." | |
& description ?~ "exactly one of qualified_ids or qualified_handles must be provided." |
-- NB: It is not possible to specific mutually exclusive fields in swagger2, so | ||
-- here we write it in description and modify the example to have the correct |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-- NB: It is not possible to specific mutually exclusive fields in swagger2, so | |
-- here we write it in description and modify the example to have the correct | |
-- NB: It is not possible to specify mutually exclusive fields in swagger2, so | |
-- here we write it in the description and modify the example to have the correct |
-- could cause this code to break. | ||
qualifiedRangedList :: Range 1 4 [Qualified Handle] = unsafeRange qualifiedList | ||
in listUsersByIdsOrHandles self (Public.ListUsersByHandles qualifiedRangedList) | ||
(Nothing, Nothing) -> throwStd $ badRequest "at least one ids or handles must be provided" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Nothing, Nothing) -> throwStd $ badRequest "at least one ids or handles must be provided" | |
(Nothing, Nothing) -> throwStd $ badRequest "One of 'ids' or 'handles' as query parameter must be provided" |
us <- getIds localHandles | ||
filterHandleResults self =<< byIds us | ||
case foundUsers of | ||
[] -> throwStd $ notFound "None of the specified ids or handles match any users" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[] -> throwStd $ notFound "None of the specified ids or handles match any users" | |
[] -> throwStd $ notFound "None of the specified ids or handles matches any users" |
No description provided.