-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
basic enterprise login subsystem scaffold
- Loading branch information
1 parent
2da6c7c
commit e56f371
Showing
5 changed files
with
69 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{-# LANGUAGE TemplateHaskell #-} | ||
|
||
module Wire.EnterpriseLoginSubsystem where | ||
|
||
import Data.Domain | ||
import Imports | ||
import Polysemy | ||
import Wire.API.EnterpriseLogin | ||
|
||
data EnterpriseLoginSubsystem m a where | ||
LockDomain :: Domain -> EnterpriseLoginSubsystem m () | ||
GetDomainRegistration :: Domain -> EnterpriseLoginSubsystem m (Maybe DomainRegistration) | ||
|
||
makeSem ''EnterpriseLoginSubsystem |
45 changes: 45 additions & 0 deletions
45
libs/wire-subsystems/src/Wire/EnterpriseLoginSubsystem/Interpreter.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{-# LANGUAGE OverloadedRecordDot #-} | ||
|
||
module Wire.EnterpriseLoginSubsystem.Interpreter | ||
( runEnterpriseLoginSubsystem, | ||
) | ||
where | ||
|
||
import Imports hiding (lookup) | ||
import Polysemy | ||
import Wire.API.EnterpriseLogin | ||
import Wire.DomainRegistrationStore | ||
import Wire.EnterpriseLoginSubsystem | ||
|
||
runEnterpriseLoginSubsystem :: | ||
( Member DomainRegistrationStore r | ||
) => | ||
Sem (EnterpriseLoginSubsystem ': r) a -> | ||
Sem r a | ||
runEnterpriseLoginSubsystem = interpret $ | ||
\case | ||
LockDomain domain -> upsert $ StoredDomainRegistration domain LockedTag AllowedTag Nothing Nothing Nothing Nothing | ||
GetDomainRegistration domain -> do | ||
mStoredDomainRegistration <- lookup domain | ||
let mDomainRegistration = mStoredDomainRegistration >>= fromStored | ||
pure mDomainRegistration | ||
|
||
fromStored :: StoredDomainRegistration -> Maybe DomainRegistration | ||
fromStored sdr = | ||
DomainRegistration sdr.domain | ||
<$> getDomainRedirect sdr | ||
<*> getTeamInvite sdr | ||
<*> pure sdr.dnsVerificationToken | ||
|
||
getTeamInvite :: StoredDomainRegistration -> Maybe TeamInvite | ||
getTeamInvite = \case | ||
StoredDomainRegistration _ _ ti _ _ _ _ -> case ti of | ||
AllowedTag -> Just Allowed | ||
_ -> Nothing | ||
|
||
getDomainRedirect :: StoredDomainRegistration -> Maybe DomainRedirect | ||
getDomainRedirect = \case | ||
StoredDomainRegistration _ dr _ _ _ _ _ -> case dr of | ||
NoneTag -> Just None | ||
LockedTag -> Just Locked | ||
_ -> Nothing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters