Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
bba8ade
WIP
akshaymankar Apr 15, 2024
4752915
More WIP
akshaymankar Apr 15, 2024
d9e21ab
Finish implementing getAllFeatureConfigs for teams in the interpreter
akshaymankar Apr 16, 2024
ba73724
Use TeamFeatures.getAllFeatureConfigs
akshaymankar Apr 16, 2024
39c3e57
[wip] legalhold config tests
battermann Apr 16, 2024
9c8e023
wip tests, todo: allow listed config
battermann Apr 16, 2024
b017752
Failing test for legalhold
akshaymankar Apr 17, 2024
9dee21e
Add test for legalhold whitelist team and implicit consent
akshaymankar Apr 17, 2024
1499734
Better errors
akshaymankar Apr 17, 2024
63717f0
Slightly faster test
akshaymankar Apr 17, 2024
3cbec66
More complete test for LH setting being "whitelist-teams-and-implicit…
akshaymankar Apr 17, 2024
89df08d
WIP: TeamFeatures.testExposeInvitationURLsToTeamAdminConfig
akshaymankar Apr 17, 2024
6feabb2
tests for expose invitation url feature flag
battermann Apr 17, 2024
8529272
Merge remote-tracking branch 'origin/optimize-feature-configs-tests' …
fisx Apr 17, 2024
306be9e
Implement special cases.
fisx Apr 17, 2024
ca704c4
wip
battermann Apr 17, 2024
390ebc6
wip
battermann Apr 18, 2024
eca8f4b
Merge remote-tracking branch 'origin/develop' into optimize-feature-c…
battermann Apr 18, 2024
a2e262e
in the middle of debugging
battermann Apr 18, 2024
bb6127a
wip writing more tests
battermann Apr 18, 2024
63207f8
make expose url feature test pass
battermann Apr 18, 2024
a685b15
make lh tests pass
battermann Apr 18, 2024
49ad00a
changelog
fisx Apr 19, 2024
ecd67c7
clean up old tests
battermann Apr 19, 2024
3eb9132
more cleanup
battermann Apr 19, 2024
fdff77e
clean up tests
battermann Apr 19, 2024
c8c7cf8
lint
fisx Apr 19, 2024
46bc398
Fixup
fisx Apr 19, 2024
672ba31
Make TODO a FUTUREWORK.
fisx Apr 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions services/galley/galley.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ library
Galley.Aws
Galley.Cassandra
Galley.Cassandra.Access
Galley.Cassandra.AllFeatureConfigsRow
Galley.Cassandra.Client
Galley.Cassandra.Code
Galley.Cassandra.Conversation
Expand Down Expand Up @@ -302,6 +303,7 @@ library
, cereal >=0.4
, comonad
, containers >=0.5
, cql
, crypton
, crypton-x509
, currency-codes >=2.0
Expand Down
189 changes: 189 additions & 0 deletions services/galley/src/Galley/Cassandra/AllFeatureConfigsRow.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
{-# LANGUAGE TemplateHaskell #-}

module Galley.Cassandra.AllFeatureConfigsRow where

import Cassandra
import Cassandra qualified as C
import Data.Id
import Data.Misc (HttpsUrl)
import Data.Time
import Database.CQL.Protocol
import GHC.Records
import Galley.Cassandra.Instances ()
import Imports
import Wire.API.Conversation.Protocol (ProtocolTag)
import Wire.API.MLS.CipherSuite
import Wire.API.Team.Feature

data AllFeatureConfigsRow = AllFeatureConfigsRow
{ -- legalhold
legalhold :: Maybe FeatureStatus,
-- sso
sso :: Maybe FeatureStatus,
-- search visibility
searchVisibility :: Maybe FeatureStatus,
-- validate saml emails
validateSamlEmails :: Maybe FeatureStatus,
-- digital signatures
digitalSignatures :: Maybe FeatureStatus,
-- app lock
appLock :: Maybe FeatureStatus,
appLockEnforce :: Maybe EnforceAppLock,
appLockInactivityTimeoutSecs :: Maybe Int32,
-- file sharing
fileSharing :: Maybe FeatureStatus,
fileSharingLock :: Maybe LockStatus,
-- self deleting messages
selfDeletingMessages :: Maybe FeatureStatus,
selfDeletingMessagesTtl :: Maybe Int32,
selfDeletingMessagesLock :: Maybe LockStatus,
-- conference calling
conferenceCalling :: Maybe FeatureStatus,
conferenceCallingTtl :: Maybe FeatureTTL,
-- guest links
guestLinks :: Maybe FeatureStatus,
guestLinksLock :: Maybe LockStatus,
-- snd factor
sndFactor :: Maybe FeatureStatus,
sndFactorLock :: Maybe LockStatus,
-- mls
mls :: Maybe FeatureStatus,
mlsDefaultProtocol :: Maybe ProtocolTag,
mlsToggleUsers :: Maybe (C.Set UserId),
mlsAllowedCipherSuites :: Maybe (C.Set CipherSuiteTag),
mlsDefaultCipherSuite :: Maybe CipherSuiteTag,
mlsSupportedProtocols :: Maybe (C.Set ProtocolTag),
mlsLock :: Maybe LockStatus,
-- mls e2eid
mlsE2eid :: Maybe FeatureStatus,
mlsE2eidGracePeriod :: Maybe Int32,
mlsE2eidAcmeDiscoverUrl :: Maybe HttpsUrl,
mlsE2eidLock :: Maybe LockStatus,
-- mls migration
mlsMigration :: Maybe FeatureStatus,
mlsMigrationStartTime :: Maybe UTCTime,
mlsMigrationFinalizeRegardlessAfter :: Maybe UTCTime,
mlsMigrationLock :: Maybe LockStatus,
-- expose invitation urls
exposeInvitationUrls :: Maybe FeatureStatus,
-- outlook calendar integration
outlookCalIntegration :: Maybe FeatureStatus,
outlookCalIntegrationLock :: Maybe LockStatus,
-- enforce download location
enforceDownloadLocation :: Maybe FeatureStatus,
enforceDownloadLocation_Location :: Maybe Text,
enforceDownloadLocationLock :: Maybe LockStatus,
-- limit event fanout
limitEventFanout :: Maybe FeatureStatus
}

recordInstance ''AllFeatureConfigsRow

allFeatureConfigsFromRow :: AllFeatureConfigs -> AllFeatureConfigsRow -> AllFeatureConfigs
allFeatureConfigsFromRow serverConfigs row =
AllFeatureConfigs
{ afcLegalholdStatus = mkSimple @"legalhold" @"afcLegalholdStatus",
afcSSOStatus = mkSimple @"sso" @"afcSSOStatus",
afcTeamSearchVisibilityAvailable = mkSimple @"searchVisibility" @"afcTeamSearchVisibilityAvailable",
afcSearchVisibilityInboundConfig = mkSimple @"searchVisibility" @"afcSearchVisibilityInboundConfig",
afcValidateSAMLEmails = mkSimple @"validateSamlEmails" @"afcValidateSAMLEmails",
afcDigitalSignatures = mkSimple @"digitalSignatures" @"afcDigitalSignatures",
afcAppLock = mkWithConfig @"appLock" @"afcAppLock" appLockConfig,
afcFileSharing = mkSimpleWithLock @"fileSharing" @"fileSharingLock" @"afcFileSharing",
afcClassifiedDomains = computeFeatureConfigForTeamUser Nothing Nothing serverConfigs.afcClassifiedDomains,
afcConferenceCalling = undefined,
afcSelfDeletingMessages = undefined,
afcGuestLink = undefined,
afcSndFactorPasswordChallenge = undefined,
afcMLS = undefined,
afcExposeInvitationURLsToTeamAdmin = undefined,
afcOutlookCalIntegration = undefined,
afcMlsE2EId = undefined,
afcMlsMigration = undefined,
afcEnforceFileDownloadLocation = undefined,
afcLimitedEventFanout = undefined
}
where
mkWithStatusNoLockNoConfig :: forall cfg. IsFeatureConfig cfg => Maybe FeatureStatus -> Maybe (WithStatusNoLock cfg)
mkWithStatusNoLockNoConfig = fmap (forgetLock . (flip setStatus defFeatureStatus))

mkSimple ::
forall rowName afcName cfg.
( IsFeatureConfig cfg,
HasField rowName AllFeatureConfigsRow (Maybe FeatureStatus),
HasField afcName AllFeatureConfigs (WithStatus cfg)
) =>
WithStatus cfg
mkSimple =
computeFeatureConfigForTeamUser (mkWithStatusNoLockNoConfig (getField @rowName row)) Nothing (getField @afcName serverConfigs)

mkSimpleWithLock ::
forall rowName rowLockName afcName cfg.
( IsFeatureConfig cfg,
HasField rowName AllFeatureConfigsRow (Maybe FeatureStatus),
HasField rowLockName AllFeatureConfigsRow (Maybe LockStatus),
HasField afcName AllFeatureConfigs (WithStatus cfg)
) =>
WithStatus cfg
mkSimpleWithLock =
computeFeatureConfigForTeamUser (mkWithStatusNoLockNoConfig (getField @rowName row)) (getField @rowLockName row) (getField @afcName serverConfigs)

mkWithConfig ::
forall rowName afcName cfg.
( HasField rowName AllFeatureConfigsRow (Maybe FeatureStatus),
HasField afcName AllFeatureConfigs (WithStatus cfg)
) =>
Maybe cfg ->
WithStatus cfg
mkWithConfig mCfg =
let withoutLock =
WithStatusNoLock
<$> (getField @rowName row)
<*> mCfg
<*> Just FeatureTTLUnlimited
in computeFeatureConfigForTeamUser withoutLock Nothing (getField @afcName serverConfigs)

appLockConfig = AppLockConfig <$> row.appLockEnforce <*> row.appLockInactivityTimeoutSecs

-- mkAppLock :: WithStatus AppLockConfig
-- mkAppLock =
-- let withoutLock = WithStatusNoLock <$> row.appLock <*> fmap SelfDeletingMessagesConfig row.appLockInactivityTimeoutSecs <*> Just FeatureTTLUnlimited
-- computeFeatureConfigForTeamUser withoutLock Nothing serverConfig.afcAppLock

getAllFeatureConfigs :: MonadClient m => AllFeatureConfigs -> TeamId -> m (Maybe AllFeatureConfigs)
getAllFeatureConfigs serverConfigs tid = do
row <- retry x1 $ query1 select (params LocalQuorum (Identity tid))
pure $ allFeatureConfigsFromRow serverConfigs . asRecord <$> row
where
select ::
PrepQuery
R
(Identity TeamId)
(TupleType AllFeatureConfigsRow)
select =
"select \
\legalhold_status, \
\sso_status, \
\search_visibility_status, \
\validate_saml_emails, \
\digital_signatures, \
\app_lock_status, app_lock_enforce, app_lock_inactivity_timeout_secs, \
\file_sharing, file_sharing_lock_status, \
\self_deleting_messages_status, self_deleting_messages_ttl, self_deleting_messages_lock_status, \
\conference_calling, ttl(conference_calling), \
\guest_links_status, guest_links_lock_status, \
\snd_factor_password_challenge_status, snd_factor_password_challenge_lock_status, \
\\
\mls_status, mls_default_protocol, mls_protocol_toggle_users, mls_allowed_ciphersuites, \
\mls_default_ciphersuite, mls_supported_protocols, mls_lock_status, \
\\
\mls_e2eid_status, mls_e2eid_grace_period, mls_e2eid_acme_discovery_url, mls_e2eid_lock_status, \
\\
\mls_migration_status, mls_migration_start_time, mls_migration_finalise_regardless_after, \
\mls_migration_lock_status, \
\\
\expose_invitation_urls_to_team_admin, \
\outlook_cal_integration_status, outlook_cal_integration_lock_status, \
\enforce_file_download_location_status, enforce_file_download_location, enforce_file_download_location_lock_status, \
\limited_event_fanout_status \
\from team_features where team_id = ?"
46 changes: 46 additions & 0 deletions services/galley/src/Galley/Cassandra/TeamFeatures.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
Comment thread
elland marked this conversation as resolved.
Outdated

-- This file is part of the Wire Server implementation.
--
-- Copyright (C) 2022 Wire Swiss GmbH <opensource@wire.com>
Expand Down Expand Up @@ -63,6 +65,7 @@ interpretTeamFeatureStoreToCassandra = interpret $ \case
TFS.SetFeatureLockStatus sing tid ls -> do
logEffect "TeamFeatureStore.SetFeatureLockStatus"
embedClient $ setFeatureLockStatus sing tid ls
TFS.GetAllFeatureConfigs _tid -> undefined

getFeatureConfig :: MonadClient m => FeatureSingleton cfg -> TeamId -> m (Maybe (WithStatusNoLock cfg))
getFeatureConfig FeatureSingletonLegalholdConfig tid = getTrivialConfigC "legalhold_status" tid
Expand Down Expand Up @@ -185,6 +188,49 @@ getFeatureConfig FeatureSingletonEnforceFileDownloadLocationConfig tid = do
getFeatureConfig FeatureSingletonLimitedEventFanoutConfig tid =
getTrivialConfigC "limited_event_fanout_status" tid

{- ORMOLU_DISABLE -}
type Foo =
(
-- legalhold
Maybe FeatureStatus,
-- sso
Maybe FeatureStatus,
-- search visibility
Maybe FeatureStatus,
-- validate saml emails
Maybe FeatureStatus,
-- digital signatures
Maybe FeatureStatus,
-- app lock
Maybe FeatureStatus, Maybe EnforceAppLock, Maybe Int32,
-- file sharing
Maybe FeatureStatus, Maybe LockStatus,
-- self deleting messages
Maybe FeatureStatus, Maybe Int32, Maybe LockStatus,
-- conference calling
Maybe FeatureStatus, Maybe FeatureTTL,
-- guest links
Maybe FeatureStatus, Maybe LockStatus,
-- snd factor
Maybe FeatureStatus, Maybe LockStatus,
-- mls
Maybe FeatureStatus, Maybe ProtocolTag, Maybe (C.Set UserId), Maybe (C.Set CipherSuiteTag),
Maybe CipherSuiteTag, Maybe (C.Set ProtocolTag), Maybe LockStatus,
-- mls e2eid
Maybe FeatureStatus, Maybe Int32, Maybe HttpsUrl, Maybe LockStatus,
-- mls migration
Maybe FeatureStatus, Maybe UTCTime, Maybe UTCTime, Maybe LockStatus,
-- expore invitation urls
Maybe FeatureStatus,
-- outlook calendar integration
Maybe FeatureStatus, Maybe LockStatus,
-- enforce download location
Maybe FeatureStatus, Maybe Text, Maybe LockStatus,
-- limit event fanout
Maybe FeatureStatus
)
{- ORMOLU_ENABLE -}

setFeatureConfig :: MonadClient m => FeatureSingleton cfg -> TeamId -> WithStatusNoLock cfg -> m ()
setFeatureConfig FeatureSingletonLegalholdConfig tid statusNoLock = setFeatureStatusC "legalhold_status" tid (wssStatus statusNoLock)
setFeatureConfig FeatureSingletonSSOConfig tid statusNoLock = setFeatureStatusC "sso_status" tid (wssStatus statusNoLock)
Expand Down
13 changes: 4 additions & 9 deletions services/galley/src/Galley/Effects/TeamFeatureStore.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,7 @@
-- You should have received a copy of the GNU Affero General Public License along
-- with this program. If not, see <https://www.gnu.org/licenses/>.

module Galley.Effects.TeamFeatureStore
( TeamFeatureStore (..),
getFeatureConfig,
getFeatureConfigMulti,
setFeatureConfig,
getFeatureLockStatus,
setFeatureLockStatus,
)
where
module Galley.Effects.TeamFeatureStore where

import Data.Id
import Imports
Expand Down Expand Up @@ -55,5 +47,8 @@ data TeamFeatureStore m a where
TeamId ->
LockStatus ->
TeamFeatureStore m ()
GetAllFeatureConfigs ::
TeamId ->
TeamFeatureStore m AllFeatureConfigs

makeSem ''TeamFeatureStore