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

Servantify get users by unqualified ids or handles #1291

Merged
merged 15 commits into from
Jan 5, 2021

Conversation

akshaymankar
Copy link
Member

No description provided.

Copy link
Member

@jschaul jschaul left a 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?

@jschaul
Copy link
Member

jschaul commented Dec 29, 2020

The wire-api unittests fail with a mismatch between user profile JSON and swagger.

@akshaymankar
Copy link
Member Author

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.
Copy link
Contributor

@mheinzel mheinzel left a 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.

Comment on lines +1231 to +1242
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"
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

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.

@jschaul
Copy link
Member

jschaul commented Jan 4, 2021

Compile issue:

[4 of 8] Compiling Federator.Impl
                       
/home/user/Documents/git/wire-server/services/federator/src/Federator/Impl.hs:35:9: error:
    • No instance for (http-api-data-0.4.1.1:Web.Internal.HttpApiData.FromHttpApiData
                         (Data.Qualified.Qualified Data.Id.UserId))
        arising from a use of ‘serve’
    • In the expression: serve api (mock api (Proxy @'[]))
      In an equation for ‘app’:
          app _        
            = serve api (mock api (Proxy @'[]))
            where      
                api = Proxy @(ToServantApi API.Api)
   |                   
35 | app _ = serve api (mock api (Proxy @'[]))
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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.
@akshaymankar
Copy link
Member Author

Alright, I think stuff should just work now 🤞
Could one of you please have a look at b06813b and let me know if the approval still stands?

Copy link
Contributor

@mheinzel mheinzel left a 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>
@akshaymankar akshaymankar merged commit 9d89976 into develop Jan 5, 2021
@akshaymankar akshaymankar deleted the akshaymankar/get-users branch January 5, 2021 11:11
Copy link
Member

@jschaul jschaul left a 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.

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."
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
(_, _) -> 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."
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
& description ?~ "exactly one of qualifie_ids or qualified_handles must be provided."
& description ?~ "exactly one of qualified_ids or qualified_handles must be provided."

Comment on lines +1053 to +1054
-- 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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
-- 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"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
(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"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
[] -> throwStd $ notFound "None of the specified ids or handles match any users"
[] -> throwStd $ notFound "None of the specified ids or handles matches any users"

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