-
Notifications
You must be signed in to change notification settings - Fork 334
[SQSERVICES-1643] Servantify brig account API 3 - POST /activate
#2701
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| The `POST /activate` endpoint of the account API is now migrated to servant |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -34,14 +34,14 @@ module Wire.API.User.Activation | |||||||||||||||||||||||||
| SendActivationCode (..), | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| -- * Swagger | ||||||||||||||||||||||||||
| modelActivate, | ||||||||||||||||||||||||||
| modelSendActivationCode, | ||||||||||||||||||||||||||
| modelActivationResponse, | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
| where | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| import Control.Lens ((?~)) | ||||||||||||||||||||||||||
| import Data.Aeson | ||||||||||||||||||||||||||
| import Data.Aeson.Types (Parser) | ||||||||||||||||||||||||||
| import Data.ByteString.Conversion | ||||||||||||||||||||||||||
| import Data.Data (Proxy (Proxy)) | ||||||||||||||||||||||||||
| import Data.Json.Util ((#)) | ||||||||||||||||||||||||||
|
|
@@ -51,6 +51,7 @@ import Data.Swagger (ToParamSchema) | |||||||||||||||||||||||||
| import qualified Data.Swagger as S | ||||||||||||||||||||||||||
| import qualified Data.Swagger.Build.Api as Doc | ||||||||||||||||||||||||||
| import Data.Text.Ascii | ||||||||||||||||||||||||||
| import Data.Tuple.Extra (fst3, snd3, thd3) | ||||||||||||||||||||||||||
| import Imports | ||||||||||||||||||||||||||
| import Servant (FromHttpApiData (..)) | ||||||||||||||||||||||||||
| import Wire.API.User.Identity | ||||||||||||||||||||||||||
|
|
@@ -80,14 +81,42 @@ instance ToByteString ActivationTarget where | |||||||||||||||||||||||||
| newtype ActivationKey = ActivationKey | ||||||||||||||||||||||||||
| {fromActivationKey :: AsciiBase64Url} | ||||||||||||||||||||||||||
| deriving stock (Eq, Show, Generic) | ||||||||||||||||||||||||||
| deriving newtype (ToByteString, FromByteString, ToJSON, FromJSON, Arbitrary) | ||||||||||||||||||||||||||
| deriving newtype (ToSchema, ToByteString, FromByteString, ToJSON, FromJSON, Arbitrary) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| instance ToParamSchema ActivationKey where | ||||||||||||||||||||||||||
| toParamSchema _ = S.toParamSchema (Proxy @Text) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| instance FromHttpApiData ActivationKey where | ||||||||||||||||||||||||||
| parseUrlPiece = fmap ActivationKey . parseUrlPiece | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| maybeActivationKeyObjectSchema :: Schema.ObjectSchemaP Schema.SwaggerDoc (Maybe ActivationKey, Maybe Phone, Maybe Email) ActivationTarget | ||||||||||||||||||||||||||
| maybeActivationKeyObjectSchema = | ||||||||||||||||||||||||||
| Schema.withParser activationKeyTupleObjectSchema maybeActivationKeyTargetFromTuple | ||||||||||||||||||||||||||
| where | ||||||||||||||||||||||||||
| activationKeyTupleObjectSchema :: Schema.ObjectSchema Schema.SwaggerDoc (Maybe ActivationKey, Maybe Phone, Maybe Email) | ||||||||||||||||||||||||||
| activationKeyTupleObjectSchema = | ||||||||||||||||||||||||||
| (,,) | ||||||||||||||||||||||||||
| <$> fst3 Schema..= Schema.maybe_ (Schema.optFieldWithDocModifier "key" keyDocs Schema.schema) | ||||||||||||||||||||||||||
| <*> snd3 Schema..= Schema.maybe_ (Schema.optFieldWithDocModifier "phone" phoneDocs Schema.schema) | ||||||||||||||||||||||||||
| <*> thd3 Schema..= Schema.maybe_ (Schema.optFieldWithDocModifier "email" emailDocs Schema.schema) | ||||||||||||||||||||||||||
| where | ||||||||||||||||||||||||||
| keyDocs = description ?~ "An opaque key to activate, as it was sent by the API." | ||||||||||||||||||||||||||
| phoneDocs = description ?~ "A known phone number to activate." | ||||||||||||||||||||||||||
| emailDocs = description ?~ "A known email address to activate." | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| maybeActivationKeyTargetFromTuple :: (Maybe ActivationKey, Maybe Phone, Maybe Email) -> Parser ActivationTarget | ||||||||||||||||||||||||||
| maybeActivationKeyTargetFromTuple = \case | ||||||||||||||||||||||||||
| (Just key, _, _) -> pure $ ActivateKey key | ||||||||||||||||||||||||||
| (_, _, Just email) -> pure $ ActivateEmail email | ||||||||||||||||||||||||||
| (_, Just phone, _) -> pure $ ActivatePhone phone | ||||||||||||||||||||||||||
| _ -> fail "key, email or phone must be present" | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| maybeActivationKeyTargetFromTuple :: (Maybe ActivationKey, Maybe Phone, Maybe Email) -> Parser ActivationTarget | |
| maybeActivationKeyTargetFromTuple = \case | |
| (Just key, _, _) -> pure $ ActivateKey key | |
| (_, _, Just email) -> pure $ ActivateEmail email | |
| (_, Just phone, _) -> pure $ ActivatePhone phone | |
| _ -> fail "key, email or phone must be present" | |
| maybeActivationKeyTargetFromTuple :: (Maybe ActivationKey, Maybe Phone, Maybe Email) -> Parser ActivationTarget | |
| maybeActivationKeyTargetFromTuple = \case | |
| (Just key, _, _) -> pure $ ActivateKey key | |
| (_, _, Just email) -> pure $ ActivateEmail email | |
| (_, Just phone, _) -> pure $ ActivatePhone phone | |
| _ -> fail "key, email or phone must be present" |
I like symmetry! :)
Outdated
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.
does was a lie before, right? the json instances didn't know about this field?
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.
Yeah, I noticed that, too.
Uh oh!
There was an error while loading. Please reload this page.