module Test.FeatureFlags.LegalHold where
import qualified API.Galley as Public
import qualified API.GalleyInternal as Internal
import Control.Monad.Codensity (Codensity (runCodensity))
import Control.Monad.Reader
import SetupHelpers
import Test.FeatureFlags.Util
import Testlib.Prelude
import Testlib.ResourcePool (acquireResources)
testLegalholdDisabledByDefault :: (HasCallStack) => App ()
testLegalholdDisabledByDefault :: HasCallStack => App ()
testLegalholdDisabledByDefault = do
let put :: domain -> team -> a -> App ()
put domain
uid team
tid a
st = domain -> team -> String -> Value -> App Response
forall domain team featureName payload.
(HasCallStack, MakesValue domain, MakesValue team,
MakesValue featureName, MakesValue payload) =>
domain -> team -> featureName -> payload -> App Response
Internal.setTeamFeatureConfig domain
uid team
tid String
"legalhold" ([Pair] -> Value
object [String
"status" String -> a -> Pair
forall a. ToJSON a => String -> a -> Pair
.= a
st]) App Response -> (Response -> App ()) -> App ()
forall a b. App a -> (a -> App b) -> App b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= HasCallStack => Response -> App ()
Response -> App ()
assertSuccess
let patch :: domain -> team -> String -> App ()
patch domain
uid team
tid String
st = domain -> team -> String -> String -> App Response
forall domain team.
(HasCallStack, MakesValue domain, MakesValue team) =>
domain -> team -> String -> String -> App Response
Internal.setTeamFeatureStatus domain
uid team
tid String
"legalhold" String
st App Response -> (Response -> App ()) -> App ()
forall a b. App a -> (a -> App b) -> App b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= HasCallStack => Response -> App ()
Response -> App ()
assertSuccess
[Value -> String -> String -> App ()]
-> ((Value -> String -> String -> App ()) -> App ()) -> App ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [Value -> String -> String -> App ()
forall {domain} {team} {a}.
(MakesValue domain, MakesValue team, ToJSON a) =>
domain -> team -> a -> App ()
put, Value -> String -> String -> App ()
forall {domain} {team}.
(MakesValue domain, MakesValue team) =>
domain -> team -> String -> App ()
patch] (((Value -> String -> String -> App ()) -> App ()) -> App ())
-> ((Value -> String -> String -> App ()) -> App ()) -> App ()
forall a b. (a -> b) -> a -> b
$ \Value -> String -> String -> App ()
setFeatureStatus -> do
ServiceOverrides -> (HasCallStack => String -> App ()) -> App ()
forall a.
HasCallStack =>
ServiceOverrides -> (HasCallStack => String -> App a) -> App a
withModifiedBackend
ServiceOverrides
forall a. Default a => a
def {galleyCfg = setField "settings.featureFlags.legalhold" "disabled-by-default"}
((HasCallStack => String -> App ()) -> App ())
-> (HasCallStack => String -> App ()) -> App ()
forall a b. (a -> b) -> a -> b
$ \String
domain -> do
(owner, tid, m : _) <- String -> Int -> App (Value, String, [Value])
forall domain.
(HasCallStack, MakesValue domain) =>
domain -> Int -> App (Value, String, [Value])
createTeam String
domain Int
2
nonMember <- randomUser domain def
assertForbidden =<< Public.getTeamFeature nonMember tid "legalhold"
checkFeature "legalhold" m tid disabled
setFeatureStatus owner tid "enabled"
checkFeature "legalhold" owner tid enabled
setFeatureStatus owner tid "disabled"
checkFeature "legalhold" owner tid disabled
testLegalholdDisabledPermanently :: (HasCallStack) => App ()
testLegalholdDisabledPermanently :: HasCallStack => App ()
testLegalholdDisabledPermanently = do
let cfgLhDisabledPermanently :: ServiceOverrides
cfgLhDisabledPermanently =
ServiceOverrides
forall a. Default a => a
def
{ galleyCfg = setField "settings.featureFlags.legalhold" "disabled-permanently"
}
cfgLhDisabledByDefault :: ServiceOverrides
cfgLhDisabledByDefault =
ServiceOverrides
forall a. Default a => a
def
{ galleyCfg = setField "settings.featureFlags.legalhold" "disabled-by-default"
}
resourcePool <- (Env -> ResourcePool BackendResource)
-> App (ResourcePool BackendResource)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (.resourcePool)
runCodensity (acquireResources 1 resourcePool) $ \[BackendResource
testBackend] -> do
let domain :: String
domain = BackendResource
testBackend.berDomain
Codensity App String -> forall b. (String -> App b) -> App b
forall k (m :: k -> *) a.
Codensity m a -> forall (b :: k). (a -> m b) -> m b
runCodensity (HasCallStack =>
BackendResource -> ServiceOverrides -> Codensity App String
BackendResource -> ServiceOverrides -> Codensity App String
startDynamicBackend BackendResource
testBackend ServiceOverrides
cfgLhDisabledPermanently) ((String -> App ()) -> App ()) -> (String -> App ()) -> App ()
forall a b. (a -> b) -> a -> b
$ \String
_ -> do
(owner, tid, _) <- String -> Int -> App (Value, String, [Value])
forall domain.
(HasCallStack, MakesValue domain) =>
domain -> Int -> App (Value, String, [Value])
createTeam String
domain Int
1
checkFeature "legalhold" owner tid disabled
assertStatus 403 =<< Internal.setTeamFeatureStatus domain tid "legalhold" "enabled"
assertStatus 403 =<< Internal.setTeamFeatureConfig domain tid "legalhold" (object ["status" .= "enabled"])
(owner, tid) <- Codensity App String -> forall b. (String -> App b) -> App b
forall k (m :: k -> *) a.
Codensity m a -> forall (b :: k). (a -> m b) -> m b
runCodensity (HasCallStack =>
BackendResource -> ServiceOverrides -> Codensity App String
BackendResource -> ServiceOverrides -> Codensity App String
startDynamicBackend BackendResource
testBackend ServiceOverrides
cfgLhDisabledByDefault) ((String -> App (Value, String)) -> App (Value, String))
-> (String -> App (Value, String)) -> App (Value, String)
forall a b. (a -> b) -> a -> b
$ \String
_ -> do
(owner, tid, _) <- String -> Int -> App (Value, String, [Value])
forall domain.
(HasCallStack, MakesValue domain) =>
domain -> Int -> App (Value, String, [Value])
createTeam String
domain Int
1
checkFeature "legalhold" owner tid disabled
assertSuccess =<< Internal.setTeamFeatureStatus domain tid "legalhold" "enabled"
checkFeature "legalhold" owner tid enabled
pure (owner, tid)
runCodensity (startDynamicBackend testBackend cfgLhDisabledPermanently) $ \String
_ -> do
String -> Value -> String -> Value -> App ()
forall user tid.
(HasCallStack, MakesValue user, MakesValue tid) =>
String -> user -> tid -> Value -> App ()
checkFeature String
"legalhold" Value
owner String
tid Value
disabled
testLegalholdWhitelistTeamsAndImplicitConsent :: (HasCallStack) => App ()
testLegalholdWhitelistTeamsAndImplicitConsent :: HasCallStack => App ()
testLegalholdWhitelistTeamsAndImplicitConsent = do
let cfgLhWhitelistTeamsAndImplicitConsent :: ServiceOverrides
cfgLhWhitelistTeamsAndImplicitConsent =
ServiceOverrides
forall a. Default a => a
def
{ galleyCfg = setField "settings.featureFlags.legalhold" "whitelist-teams-and-implicit-consent"
}
cfgLhDisabledByDefault :: ServiceOverrides
cfgLhDisabledByDefault =
ServiceOverrides
forall a. Default a => a
def
{ galleyCfg = setField "settings.featureFlags.legalhold" "disabled-by-default"
}
resourcePool <- (Env -> ResourcePool BackendResource)
-> App (ResourcePool BackendResource)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (.resourcePool)
runCodensity (acquireResources 1 resourcePool) $ \[BackendResource
testBackend] -> do
let domain :: String
domain = BackendResource
testBackend.berDomain
(owner, tid) <- Codensity App String -> forall b. (String -> App b) -> App b
forall k (m :: k -> *) a.
Codensity m a -> forall (b :: k). (a -> m b) -> m b
runCodensity (HasCallStack =>
BackendResource -> ServiceOverrides -> Codensity App String
BackendResource -> ServiceOverrides -> Codensity App String
startDynamicBackend BackendResource
testBackend ServiceOverrides
cfgLhWhitelistTeamsAndImplicitConsent) ((String -> App (Value, String)) -> App (Value, String))
-> (String -> App (Value, String)) -> App (Value, String)
forall a b. (a -> b) -> a -> b
$ \String
_ -> do
(owner, tid, _) <- String -> Int -> App (Value, String, [Value])
forall domain.
(HasCallStack, MakesValue domain) =>
domain -> Int -> App (Value, String, [Value])
createTeam String
domain Int
1
checkFeature "legalhold" owner tid disabled
Internal.legalholdWhitelistTeam tid owner >>= assertSuccess
checkFeature "legalhold" owner tid enabled
assertStatus 403 =<< Internal.setTeamFeatureStatus domain tid "legalhold" "disabled"
assertStatus 403 =<< Internal.setTeamFeatureConfig domain tid "legalhold" (object ["status" .= "disabled"])
checkFeature "legalhold" owner tid enabled
pure (owner, tid)
runCodensity (startDynamicBackend testBackend cfgLhDisabledByDefault) $ \String
_ -> do
String -> Value -> String -> Value -> App ()
forall user tid.
(HasCallStack, MakesValue user, MakesValue tid) =>
String -> user -> tid -> Value -> App ()
checkFeature String
"legalhold" Value
owner String
tid Value
disabled
HasCallStack => Response -> App ()
Response -> App ()
assertSuccess (Response -> App ()) -> App Response -> App ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< String -> String -> String -> String -> App Response
forall domain team.
(HasCallStack, MakesValue domain, MakesValue team) =>
domain -> team -> String -> String -> App Response
Internal.setTeamFeatureStatus String
domain String
tid String
"legalhold" String
"disabled"
String -> Value -> String -> Value -> App ()
forall user tid.
(HasCallStack, MakesValue user, MakesValue tid) =>
String -> user -> tid -> Value -> App ()
checkFeature String
"legalhold" Value
owner String
tid Value
disabled
runCodensity (startDynamicBackend testBackend cfgLhWhitelistTeamsAndImplicitConsent) $ \String
_ -> do
String -> Value -> String -> Value -> App ()
forall user tid.
(HasCallStack, MakesValue user, MakesValue tid) =>
String -> user -> tid -> Value -> App ()
checkFeature String
"legalhold" Value
owner String
tid Value
enabled
testExposeInvitationURLsToTeamAdminConfig :: (HasCallStack) => App ()
testExposeInvitationURLsToTeamAdminConfig :: HasCallStack => App ()
testExposeInvitationURLsToTeamAdminConfig = do
let cfgExposeInvitationURLsTeamAllowlist :: b -> ServiceOverrides
cfgExposeInvitationURLsTeamAllowlist b
tids =
ServiceOverrides
forall a. Default a => a
def
{ galleyCfg = setField "settings.exposeInvitationURLsTeamAllowlist" tids
}
resourcePool <- (Env -> ResourcePool BackendResource)
-> App (ResourcePool BackendResource)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (.resourcePool)
runCodensity (acquireResources 1 resourcePool) $ \[BackendResource
testBackend] -> do
let domain :: String
domain = BackendResource
testBackend.berDomain
testNoAllowlistEntry :: (HasCallStack) => App (Value, String)
testNoAllowlistEntry :: HasCallStack => App (Value, String)
testNoAllowlistEntry = Codensity App String -> forall b. (String -> App b) -> App b
forall k (m :: k -> *) a.
Codensity m a -> forall (b :: k). (a -> m b) -> m b
runCodensity (HasCallStack =>
BackendResource -> ServiceOverrides -> Codensity App String
BackendResource -> ServiceOverrides -> Codensity App String
startDynamicBackend BackendResource
testBackend (ServiceOverrides -> Codensity App String)
-> ServiceOverrides -> Codensity App String
forall a b. (a -> b) -> a -> b
$ [String] -> ServiceOverrides
forall {b}. ToJSON b => b -> ServiceOverrides
cfgExposeInvitationURLsTeamAllowlist ([] :: [String])) ((String -> App (Value, String)) -> App (Value, String))
-> (String -> App (Value, String)) -> App (Value, String)
forall a b. (a -> b) -> a -> b
$ \String
_ -> do
(owner, tid, _) <- String -> Int -> App (Value, String, [Value])
forall domain.
(HasCallStack, MakesValue domain) =>
domain -> Int -> App (Value, String, [Value])
createTeam String
domain Int
1
checkFeature "exposeInvitationURLsToTeamAdmin" owner tid disabledLocked
assertSuccess =<< Internal.setTeamFeatureStatus domain tid "exposeInvitationURLsToTeamAdmin" "enabled"
checkFeature "exposeInvitationURLsToTeamAdmin" owner tid disabledLocked
assertStatus 409 =<< Public.setTeamFeatureConfig owner tid "exposeInvitationURLsToTeamAdmin" (object ["status" .= "enabled"])
assertSuccess =<< Internal.setTeamFeatureStatus domain tid "exposeInvitationURLsToTeamAdmin" "disabled"
pure (owner, tid)
(owner, tid) <- App (Value, String)
HasCallStack => App (Value, String)
testNoAllowlistEntry
runCodensity (startDynamicBackend testBackend $ cfgExposeInvitationURLsTeamAllowlist [tid]) $ \String
_ -> do
String -> Value -> String -> Value -> App ()
forall user tid.
(HasCallStack, MakesValue user, MakesValue tid) =>
String -> user -> tid -> Value -> App ()
checkFeature String
"exposeInvitationURLsToTeamAdmin" Value
owner String
tid Value
disabled
HasCallStack => Response -> App ()
Response -> App ()
assertSuccess (Response -> App ()) -> App Response -> App ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< String -> String -> String -> String -> App Response
forall domain team.
(HasCallStack, MakesValue domain, MakesValue team) =>
domain -> team -> String -> String -> App Response
Internal.setTeamFeatureStatus String
domain String
tid String
"exposeInvitationURLsToTeamAdmin" String
"enabled"
String -> Value -> String -> Value -> App ()
forall user tid.
(HasCallStack, MakesValue user, MakesValue tid) =>
String -> user -> tid -> Value -> App ()
checkFeature String
"exposeInvitationURLsToTeamAdmin" Value
owner String
tid Value
enabled
HasCallStack => Response -> App ()
Response -> App ()
assertSuccess (Response -> App ()) -> App Response -> App ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< String -> String -> String -> String -> App Response
forall domain team.
(HasCallStack, MakesValue domain, MakesValue team) =>
domain -> team -> String -> String -> App Response
Internal.setTeamFeatureStatus String
domain String
tid String
"exposeInvitationURLsToTeamAdmin" String
"disabled"
String -> Value -> String -> Value -> App ()
forall user tid.
(HasCallStack, MakesValue user, MakesValue tid) =>
String -> user -> tid -> Value -> App ()
checkFeature String
"exposeInvitationURLsToTeamAdmin" Value
owner String
tid Value
disabled
HasCallStack => Response -> App ()
Response -> App ()
assertSuccess (Response -> App ()) -> App Response -> App ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< String -> String -> String -> String -> App Response
forall domain team.
(HasCallStack, MakesValue domain, MakesValue team) =>
domain -> team -> String -> String -> App Response
Internal.setTeamFeatureStatus String
domain String
tid String
"exposeInvitationURLsToTeamAdmin" String
"enabled"
String -> Value -> String -> Value -> App ()
forall user tid.
(HasCallStack, MakesValue user, MakesValue tid) =>
String -> user -> tid -> Value -> App ()
checkFeature String
"exposeInvitationURLsToTeamAdmin" Value
owner String
tid Value
enabled
void testNoAllowlistEntry