Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -28,6 +28,7 @@ library
Galley.API.Internal
Galley.API.LegalHold
Galley.API.LegalHold.Conflicts
Galley.API.LegalHold.Team
Galley.API.Mapping
Galley.API.Message
Galley.API.MLS
Expand Down Expand Up @@ -59,6 +60,7 @@ library
Galley.API.Query
Galley.API.Teams
Galley.API.Teams.Features
Galley.API.Teams.Features.Get
Galley.API.Teams.Notifications
Galley.API.Update
Galley.API.Util
Expand Down
39 changes: 1 addition & 38 deletions services/galley/src/Galley/API/LegalHold.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ module Galley.API.LegalHold
requestDevice,
approveDevice,
disableForUser,
isLegalHoldEnabledForTeam,
unsetTeamLegalholdWhitelistedH,
)
where
Expand All @@ -45,6 +44,7 @@ import Data.Qualified
import Data.Range (toRange)
import Data.Time.Clock
import Galley.API.Error
import Galley.API.LegalHold.Team
import Galley.API.Query (iterateConversations)
import Galley.API.Update (removeMemberFromLocalConv)
import Galley.API.Util
Expand All @@ -55,7 +55,6 @@ import Galley.Effects.BrigAccess
import Galley.Effects.FireAndForget
import qualified Galley.Effects.LegalHoldStore as LegalHoldData
import Galley.Effects.ProposalStore
import qualified Galley.Effects.TeamFeatureStore as TeamFeatures
import Galley.Effects.TeamMemberStore
import Galley.Effects.TeamStore
import qualified Galley.External.LegalHoldService as LHService
Expand All @@ -76,7 +75,6 @@ import Wire.API.Federation.Error
import Wire.API.Provider.Service
import Wire.API.Routes.Internal.Brig.Connection
import Wire.API.Routes.Public.Galley.LegalHold
import qualified Wire.API.Team.Feature as Public
import Wire.API.Team.LegalHold
import qualified Wire.API.Team.LegalHold as Public
import Wire.API.Team.LegalHold.External hiding (userId)
Expand All @@ -85,41 +83,6 @@ import Wire.API.User.Client.Prekey
import Wire.Sem.Paging
import Wire.Sem.Paging.Cassandra

assertLegalHoldEnabledForTeam ::
forall r.
( Member LegalHoldStore r,
Member TeamStore r,
Member TeamFeatureStore r,
Member (ErrorS 'LegalHoldNotEnabled) r
) =>
TeamId ->
Sem r ()
assertLegalHoldEnabledForTeam tid =
unlessM (isLegalHoldEnabledForTeam tid) $
throwS @'LegalHoldNotEnabled

isLegalHoldEnabledForTeam ::
forall r.
( Member LegalHoldStore r,
Member TeamStore r,
Member TeamFeatureStore r
) =>
TeamId ->
Sem r Bool
isLegalHoldEnabledForTeam tid = do
getLegalHoldFlag >>= \case
FeatureLegalHoldDisabledPermanently -> do
pure False
FeatureLegalHoldDisabledByDefault -> do
statusValue <-
Public.wssStatus <$$> TeamFeatures.getFeatureConfig Public.FeatureSingletonLegalholdConfig tid
pure $ case statusValue of
Just Public.FeatureStatusEnabled -> True
Just Public.FeatureStatusDisabled -> False
Nothing -> False
FeatureLegalHoldWhitelistTeamsAndImplicitConsent ->
LegalHoldData.isTeamLegalholdWhitelisted tid

createSettings ::
forall r.
( Member (ErrorS 'NotATeamMember) r,
Expand Down
97 changes: 97 additions & 0 deletions services/galley/src/Galley/API/LegalHold/Team.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
-- This file is part of the Wire Server implementation.
--
-- Copyright (C) 2022 Wire Swiss GmbH <opensource@wire.com>
--
-- This program is free software: you can redistribute it and/or modify it under
-- the terms of the GNU Affero General Public License as published by the Free
-- Software Foundation, either version 3 of the License, or (at your option) any
-- later version.
--
-- This program is distributed in the hope that it will be useful, but WITHOUT
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-- FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
-- details.
--
-- 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.API.LegalHold.Team
( isLegalHoldEnabledForTeam,
assertLegalHoldEnabledForTeam,
ensureNotTooLargeToActivateLegalHold,
teamSizeBelowLimit,
)
where

import Data.Id
import Data.Range
import Galley.Effects
import Galley.Effects.BrigAccess
import qualified Galley.Effects.LegalHoldStore as LegalHoldData
import qualified Galley.Effects.TeamFeatureStore as TeamFeatures
import Galley.Effects.TeamStore
import Galley.Types.Teams as Team
import Imports
import Polysemy
import Wire.API.Error
import Wire.API.Error.Galley
import qualified Wire.API.Team.Feature as Public
import Wire.API.Team.Size

assertLegalHoldEnabledForTeam ::
forall r.
( Member LegalHoldStore r,
Member TeamStore r,
Member TeamFeatureStore r,
Member (ErrorS 'LegalHoldNotEnabled) r
) =>
TeamId ->
Sem r ()
assertLegalHoldEnabledForTeam tid =
unlessM (isLegalHoldEnabledForTeam tid) $
throwS @'LegalHoldNotEnabled

isLegalHoldEnabledForTeam ::
forall r.
( Member LegalHoldStore r,
Member TeamStore r,
Member TeamFeatureStore r
) =>
TeamId ->
Sem r Bool
isLegalHoldEnabledForTeam tid = do
getLegalHoldFlag >>= \case
FeatureLegalHoldDisabledPermanently -> do
pure False
FeatureLegalHoldDisabledByDefault -> do
statusValue <-
Public.wssStatus <$$> TeamFeatures.getFeatureConfig Public.FeatureSingletonLegalholdConfig tid
pure $ case statusValue of
Just Public.FeatureStatusEnabled -> True
Just Public.FeatureStatusDisabled -> False
Nothing -> False
FeatureLegalHoldWhitelistTeamsAndImplicitConsent ->
LegalHoldData.isTeamLegalholdWhitelisted tid

ensureNotTooLargeToActivateLegalHold ::
( Member BrigAccess r,
Member (ErrorS 'CannotEnableLegalHoldServiceLargeTeam) r,
Member TeamStore r
) =>
TeamId ->
Sem r ()
ensureNotTooLargeToActivateLegalHold tid = do
(TeamSize teamSize) <- getSize tid
unlessM (teamSizeBelowLimit (fromIntegral teamSize)) $
throwS @'CannotEnableLegalHoldServiceLargeTeam

teamSizeBelowLimit :: Member TeamStore r => Int -> Sem r Bool
teamSizeBelowLimit teamSize = do
limit <- fromIntegral . fromRange <$> fanoutLimit
let withinLimit = teamSize <= limit
getLegalHoldFlag >>= \case
FeatureLegalHoldDisabledPermanently -> pure withinLimit
FeatureLegalHoldDisabledByDefault -> pure withinLimit
FeatureLegalHoldWhitelistTeamsAndImplicitConsent ->
-- unlimited, see docs of 'ensureNotTooLargeForLegalHold'
pure True
25 changes: 1 addition & 24 deletions services/galley/src/Galley/API/Teams.hs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ import Data.Range as Range
import qualified Data.Set as Set
import Data.Time.Clock (UTCTime)
import Galley.API.Error as Galley
import Galley.API.LegalHold
import Galley.API.LegalHold.Team
import qualified Galley.API.Teams.Notifications as APITeamQueue
import qualified Galley.API.Update as API
import Galley.API.Util
Expand Down Expand Up @@ -1246,29 +1246,6 @@ ensureNotTooLargeForLegalHold tid teamSize =
unlessM (teamSizeBelowLimit teamSize) $
throwS @'TooManyTeamMembersOnTeamWithLegalhold

ensureNotTooLargeToActivateLegalHold ::
( Member BrigAccess r,
Member (ErrorS 'CannotEnableLegalHoldServiceLargeTeam) r,
Member TeamStore r
) =>
TeamId ->
Sem r ()
ensureNotTooLargeToActivateLegalHold tid = do
(TeamSize teamSize) <- E.getSize tid
unlessM (teamSizeBelowLimit (fromIntegral teamSize)) $
throwS @'CannotEnableLegalHoldServiceLargeTeam

teamSizeBelowLimit :: Member TeamStore r => Int -> Sem r Bool
teamSizeBelowLimit teamSize = do
limit <- fromIntegral . fromRange <$> E.fanoutLimit
let withinLimit = teamSize <= limit
E.getLegalHoldFlag >>= \case
FeatureLegalHoldDisabledPermanently -> pure withinLimit
FeatureLegalHoldDisabledByDefault -> pure withinLimit
FeatureLegalHoldWhitelistTeamsAndImplicitConsent ->
-- unlimited, see docs of 'ensureNotTooLargeForLegalHold'
pure True

addTeamMemberInternal ::
( Member BrigAccess r,
Member (ErrorS 'TooManyTeamMembers) r,
Expand Down
Loading