Skip to content

Commit 38318bf

Browse files
authored
Pull Spar.Data apart (#2064)
* Split up Spar.Data * make format * Fix test * changelog
1 parent d1df63f commit 38318bf

File tree

16 files changed

+834
-868
lines changed

16 files changed

+834
-868
lines changed

changelog.d/5-internal/diversify-data

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Separate Spar.Data module into smaller Cassandra interpreters

services/spar/src/Spar/API.hs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ import Servant
6161
import qualified Servant.Multipart as Multipart
6262
import Spar.App
6363
import Spar.CanonicalInterpreter
64-
import qualified Spar.Data as Data (GetIdPResult (..), Replaced (..), Replacing (..))
6564
import Spar.Error
6665
import qualified Spar.Intra.BrigApp as Brig
6766
import Spar.Orphans ()
@@ -76,6 +75,7 @@ import Spar.Sem.DefaultSsoCode (DefaultSsoCode)
7675
import qualified Spar.Sem.DefaultSsoCode as DefaultSsoCode
7776
import Spar.Sem.GalleyAccess (GalleyAccess)
7877
import qualified Spar.Sem.GalleyAccess as GalleyAccess
78+
import Spar.Sem.IdP (GetIdPResult (..), Replaced (..), Replacing (..))
7979
import qualified Spar.Sem.IdP as IdPEffect
8080
import Spar.Sem.IdPRawMetadataStore (IdPRawMetadataStore)
8181
import qualified Spar.Sem.IdPRawMetadataStore as IdPRawMetadataStore
@@ -494,11 +494,11 @@ idpDelete zusr idpid (fromMaybe False -> purge) = withDebugLog "idpDelete" (cons
494494
updateReplacingIdP :: IdP -> Sem r ()
495495
updateReplacingIdP idp = forM_ (idp ^. SAML.idpExtraInfo . wiOldIssuers) $ \oldIssuer -> do
496496
getIdPIdByIssuer oldIssuer (idp ^. SAML.idpExtraInfo . wiTeam) >>= \case
497-
Data.GetIdPFound iid -> IdPEffect.clearReplacedBy $ Data.Replaced iid
498-
Data.GetIdPNotFound -> pure ()
499-
Data.GetIdPDanglingId _ -> pure ()
500-
Data.GetIdPNonUnique _ -> pure ()
501-
Data.GetIdPWrongTeam _ -> pure ()
497+
GetIdPFound iid -> IdPEffect.clearReplacedBy $ Replaced iid
498+
GetIdPNotFound -> pure ()
499+
GetIdPDanglingId _ -> pure ()
500+
GetIdPNonUnique _ -> pure ()
501+
GetIdPWrongTeam _ -> pure ()
502502

503503
-- | This handler only does the json parsing, and leaves all authorization checks and
504504
-- application logic to 'idpCreateXML'.
@@ -548,7 +548,7 @@ idpCreateXML zusr raw idpmeta mReplaces (fromMaybe defWireIdPAPIVersion -> apive
548548
IdPRawMetadataStore.store (idp ^. SAML.idpId) raw
549549
storeIdPConfig idp
550550
forM_ mReplaces $ \replaces -> do
551-
IdPEffect.setReplacedBy (Data.Replaced replaces) (Data.Replacing (idp ^. SAML.idpId))
551+
IdPEffect.setReplacedBy (Replaced replaces) (Replacing (idp ^. SAML.idpId))
552552
pure idp
553553

554554
-- | In teams with a scim access token, only one IdP is allowed. The reason is that scim user
@@ -636,11 +636,11 @@ validateNewIdP apiversion _idpMetadata teamId mReplaces = withDebugLog "validate
636636
pure ()
637637

638638
case idp of
639-
Data.GetIdPFound idp' {- same team -} -> handleIdPClash (Right idp')
640-
Data.GetIdPNotFound -> pure ()
641-
res@(Data.GetIdPDanglingId _) -> throwSparSem . SparIdPNotFound . ("validateNewIdP: " <>) . cs . show $ res -- database inconsistency
642-
Data.GetIdPNonUnique ids' {- same team didn't yield anything, but there are at least two other teams with this issuer already -} -> handleIdPClash (Left ids')
643-
Data.GetIdPWrongTeam id' {- different team -} -> handleIdPClash (Left id')
639+
GetIdPFound idp' {- same team -} -> handleIdPClash (Right idp')
640+
GetIdPNotFound -> pure ()
641+
res@(GetIdPDanglingId _) -> throwSparSem . SparIdPNotFound . ("validateNewIdP: " <>) . cs . show $ res -- database inconsistency
642+
GetIdPNonUnique ids' {- same team didn't yield anything, but there are at least two other teams with this issuer already -} -> handleIdPClash (Left ids')
643+
GetIdPWrongTeam id' {- different team -} -> handleIdPClash (Left id')
644644

645645
pure SAML.IdPConfig {..}
646646

@@ -726,11 +726,11 @@ validateIdPUpdate zusr _idpMetadata _idpId = withDebugLog "validateNewIdP" (Just
726726
else do
727727
foundConfig <- getIdPConfigByIssuerAllowOld newIssuer (Just teamId)
728728
notInUseByOthers <- case foundConfig of
729-
Data.GetIdPFound c -> pure $ c ^. SAML.idpId == _idpId
730-
Data.GetIdPNotFound -> pure True
731-
res@(Data.GetIdPDanglingId _) -> throwSparSem . SparIdPNotFound . ("validateIdPUpdate: " <>) . cs . show $ res -- impossible
732-
res@(Data.GetIdPNonUnique _) -> throwSparSem . SparIdPNotFound . ("validateIdPUpdate: " <>) . cs . show $ res -- impossible (because team id was used in lookup)
733-
Data.GetIdPWrongTeam _ -> pure False
729+
GetIdPFound c -> pure $ c ^. SAML.idpId == _idpId
730+
GetIdPNotFound -> pure True
731+
res@(GetIdPDanglingId _) -> throwSparSem . SparIdPNotFound . ("validateIdPUpdate: " <>) . cs . show $ res -- impossible
732+
res@(GetIdPNonUnique _) -> throwSparSem . SparIdPNotFound . ("validateIdPUpdate: " <>) . cs . show $ res -- impossible (because team id was used in lookup)
733+
GetIdPWrongTeam _ -> pure False
734734
if notInUseByOthers
735735
then pure $ (previousIdP ^. SAML.idpExtraInfo) & wiOldIssuers %~ nub . (previousIssuer :)
736736
else throwSparSem SparIdPIssuerInUse

services/spar/src/Spar/App.hs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ import qualified SAML2.WebSSO as SAML
7676
import qualified SAML2.WebSSO.Types.Email as SAMLEmail
7777
import Servant
7878
import qualified Servant.Multipart as Multipart
79-
import qualified Spar.Data as Data (GetIdPResult (..))
8079
import Spar.Error hiding (sparToServerErrorWithLogging)
8180
import qualified Spar.Intra.BrigApp as Intra
8281
import Spar.Orphans ()
@@ -141,11 +140,11 @@ storeIdPConfig idp = IdPEffect.storeConfig idp
141140
getIdPConfigByIssuerOptionalSPId :: Members '[IdPEffect.IdP, Error SparError] r => Issuer -> Maybe TeamId -> Sem r IdP
142141
getIdPConfigByIssuerOptionalSPId issuer mbteam = do
143142
getIdPConfigByIssuerAllowOld issuer mbteam >>= \case
144-
Data.GetIdPFound idp -> pure idp
145-
Data.GetIdPNotFound -> throwSparSem $ SparIdPNotFound mempty
146-
res@(Data.GetIdPDanglingId _) -> throwSparSem $ SparIdPNotFound (cs $ show res)
147-
res@(Data.GetIdPNonUnique _) -> throwSparSem $ SparIdPNotFound (cs $ show res)
148-
res@(Data.GetIdPWrongTeam _) -> throwSparSem $ SparIdPNotFound (cs $ show res)
143+
GetIdPFound idp -> pure idp
144+
GetIdPNotFound -> throwSparSem $ SparIdPNotFound mempty
145+
res@(GetIdPDanglingId _) -> throwSparSem $ SparIdPNotFound (cs $ show res)
146+
res@(GetIdPNonUnique _) -> throwSparSem $ SparIdPNotFound (cs $ show res)
147+
res@(GetIdPWrongTeam _) -> throwSparSem $ SparIdPNotFound (cs $ show res)
149148

150149
insertUser :: Member SAMLUserStore r => SAML.UserRef -> UserId -> Sem r ()
151150
insertUser uref uid = SAMLUserStore.insert uref uid
@@ -338,11 +337,11 @@ bindUser buid userref = do
338337
err = throwSparSem . SparBindFromWrongOrNoTeam . cs . show $ buid
339338
teamid :: TeamId <-
340339
getIdPConfigByIssuerAllowOld (userref ^. uidTenant) Nothing >>= \case
341-
Data.GetIdPFound idp -> pure $ idp ^. idpExtraInfo . wiTeam
342-
Data.GetIdPNotFound -> err
343-
Data.GetIdPDanglingId _ -> err -- database inconsistency
344-
Data.GetIdPNonUnique is -> throwSparSem $ SparUserRefInNoOrMultipleTeams (cs $ show (buid, is))
345-
Data.GetIdPWrongTeam _ -> err -- impossible
340+
GetIdPFound idp -> pure $ idp ^. idpExtraInfo . wiTeam
341+
GetIdPNotFound -> err
342+
GetIdPDanglingId _ -> err -- database inconsistency
343+
GetIdPNonUnique is -> throwSparSem $ SparUserRefInNoOrMultipleTeams (cs $ show (buid, is))
344+
GetIdPWrongTeam _ -> err -- impossible
346345
acc <- BrigAccess.getAccount Intra.WithPendingInvitations buid >>= maybe err pure
347346
teamid' :: TeamId <- userTeam (accountUser acc) & maybe err pure
348347
unless (teamid' == teamid) err

0 commit comments

Comments
 (0)