Skip to content

Comments

Brig: Servantify self API#2091

Merged
akshaymankar merged 14 commits intodevelopfrom
akshaymankar/servantify-self
Feb 3, 2022
Merged

Brig: Servantify self API#2091
akshaymankar merged 14 commits intodevelopfrom
akshaymankar/servantify-self

Conversation

@akshaymankar
Copy link
Member

@akshaymankar akshaymankar commented Feb 1, 2022

https://wearezeta.atlassian.net/browse/SQCORE-1167

Checklist

  • The PR Title explains the impact of the change.
  • The PR description provides context as to why the change should occur and what the code contributes to that effect. This could also be a link to a JIRA ticket or a Github issue, if there is one.
  • changelog.d contains the following bits of information (details):
    • A file with the changelog entry in one or more suitable sub-sections. The sub-sections are marked by directories inside changelog.d.

@akshaymankar akshaymankar force-pushed the akshaymankar/servantify-self branch 4 times, most recently from 4870d1c to 9c3f0cf Compare February 2, 2022 12:43
@akshaymankar akshaymankar force-pushed the akshaymankar/servantify-self branch from 9c3f0cf to 73df876 Compare February 3, 2022 08:45
Also add instnce for AsUnion '[..] Bool back.
Only `FromJSON` needs to be backwards compatible as this object is consumed as
request body by brig. So, breaking `ToJSON` like this shouldn't cause any issues.
@akshaymankar akshaymankar force-pushed the akshaymankar/servantify-self branch from 73df876 to 9b5aabd Compare February 3, 2022 09:10
@akshaymankar
Copy link
Member Author

The GET /self/name endpoint was found to be unused. I will delete it in a separate PR.

@akshaymankar akshaymankar marked this pull request as ready for review February 3, 2022 09:15
Copy link
Contributor

@pcapriotti pcapriotti left a comment

Choose a reason for hiding this comment

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

Looks good!

As commented below, I think we could get rid of the boilerplate (which is quite a lot!) by changing the result types to include all responses (including the successful ones) and deriving AsUnion via GenericAsUnion.

If you prefer to keep the Maybe ErrorType pattern, you can also use GenericAsUnion, by deriving an AsUnion instance for the error type, and then having a couple lines of boilerplate to combine it into an instance for Maybe (using eitherToUnion and eitherFromUnion).

This is all a bit unfortunate, but managing error types is always a pain. Once we switch to using polysemy in brig, we might be able to improve the situation.

Comment on lines 872 to 879
instance AsUnion PutSelfResponses (Maybe UpdateProfileError) where
toUnion (Just ProfileNotFound) = Z (I mkErrorDescription)
toUnion (Just DisplayNameManagedByScim) = S (Z (I mkErrorDescription))
toUnion Nothing = S (S (Z (I ())))
fromUnion (Z (I _)) = Just ProfileNotFound
fromUnion (S (Z (I _))) = Just DisplayNameManagedByScim
fromUnion (S (S (Z (I _)))) = Nothing
fromUnion (S (S (S x))) = case x of
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be probably easy to automate using GenericAsUnion.

You could also consider creating a type like UpdateProfileResult with 3 constructors instead, and then you could directly use deriving via to get the AsUnion instance.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the tip. I created maybeToUnion and maybeFromUnion (this one uses eitherFromUnion) to define these instances. Let me know if they look ok.

The test was using a hardcoded name for a user and searching for the user. Since
the DB is not cleaned up after/before every test run, this causes the new users
to not show up in the search results.
@akshaymankar akshaymankar force-pushed the akshaymankar/servantify-self branch from f26fab8 to 244cdb4 Compare February 3, 2022 10:12
@akshaymankar akshaymankar force-pushed the akshaymankar/servantify-self branch from 194c184 to eaf73a4 Compare February 3, 2022 12:58
Copy link
Contributor

@pcapriotti pcapriotti left a comment

Choose a reason for hiding this comment

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

Looks good. It's a bit unfortunate that GHC doesn't let you define an instance for a type family application, even when it fully reduces. I'm not sure why this restriction exists.

@pcapriotti pcapriotti mentioned this pull request Feb 3, 2022
4 tasks
@akshaymankar akshaymankar merged commit e48a6bd into develop Feb 3, 2022
@akshaymankar akshaymankar deleted the akshaymankar/servantify-self branch February 3, 2022 16:12
@akshaymankar
Copy link
Member Author

Looks good. It's a bit unfortunate that GHC doesn't let you define an instance for a type family application, even when it fully reduces. I'm not sure why this restriction exists.

I found this when I was confused about the error: https://gitlab.haskell.org/ghc/ghc/-/issues/3485

@pcapriotti
Copy link
Contributor

I found this when I was confused about the error: https://gitlab.haskell.org/ghc/ghc/-/issues/3485

In that example the type family is stuck, and I can understand that something like that would not be allowed. However, if the type family application computes to something that is accepted as as the type of an instance, why not accept the application itself?

@fisx fisx mentioned this pull request Feb 18, 2022
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.

2 participants