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
1 change: 1 addition & 0 deletions changelog.d/5-internal/SQSERVICES-1559
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`AllFeatureConfigs` is now typed
71 changes: 56 additions & 15 deletions libs/wire-api/src/Wire/API/Team/Feature.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ module Wire.API.Team.Feature
where

import qualified Cassandra.CQL as Cass
import Control.Lens.Combinators (dimap)
import qualified Data.Aeson as Aeson
import qualified Data.Attoparsec.ByteString as Parser
import Data.ByteString.Conversion (FromByteString (..), ToByteString (..), fromByteString, toByteString')
import Data.Domain (Domain)
Expand All @@ -85,7 +83,7 @@ import Wire.API.Arbitrary (Arbitrary, GenericUniform (..))
----------------------------------------------------------------------
-- TeamFeatureName

-- | If you add a constructor here, you need extend multiple defintions, which
-- | If you add a constructor here, you need extend multiple definitions, which
-- aren't checked by GHC.
--
-- Follow this Checklist:
Expand All @@ -102,9 +100,8 @@ import Wire.API.Arbitrary (Arbitrary, GenericUniform (..))
-- * Update the Arbitrary instance of FeatureFlags
-- in libs/galley-types/test/unit/Test/Galley/Types.hs
-- * roleHiddenPermissions ChangeTeamFeature and ViewTeamFeature
-- * services/galley/src/Galley/API/Teams/Features.hs
-- * maybe extend getAllFeatureConfigs (if feature status is user-visibile)
-- * maybe extend getAllFeatures (if feature status is user-visibile)
-- * add the feature status to `AllFeatureConfigs` (see below)
-- * follow the type errors and fix them (e.g. in services/galley/src/Galley/API/Teams/Features.hs)
-- * services/galley/schema/src/
-- * add a migration like the one in "V43_TeamFeatureDigitalSignatures.hs"
-- * services/galley/test/integration/API/Teams/Feature.hs
Expand Down Expand Up @@ -362,6 +359,59 @@ modelForTeamFeature TeamFeatureGuestLinks = modelTeamFeatureStatusNoConfig
modelForTeamFeature TeamFeatureSndFactorPasswordChallenge = modelTeamFeatureStatusNoConfig
modelForTeamFeature TeamFeatureSearchVisibilityInbound = modelTeamFeatureStatusNoConfig

data AllFeatureConfigs = AllFeatureConfigs
{ afcLegalholdStatusInternal :: TeamFeatureStatus 'WithoutLockStatus 'TeamFeatureLegalHold,
afcSSOStatusInternal :: TeamFeatureStatus 'WithoutLockStatus 'TeamFeatureSSO,
afcTeamSearchVisibilityAvailableInternal :: TeamFeatureStatus 'WithoutLockStatus 'TeamFeatureSearchVisibility,
afcValidateSAMLEmailsInternal :: TeamFeatureStatus 'WithoutLockStatus 'TeamFeatureValidateSAMLEmails,
afcDigitalSignaturesInternal :: TeamFeatureStatus 'WithoutLockStatus 'TeamFeatureDigitalSignatures,
afcAppLockInternal :: TeamFeatureStatus 'WithoutLockStatus 'TeamFeatureAppLock,
afcFileSharingInternal :: TeamFeatureStatus 'WithLockStatus 'TeamFeatureFileSharing,
afcClassifiedDomainsInternal :: TeamFeatureStatus 'WithoutLockStatus 'TeamFeatureClassifiedDomains,
afcConferenceCallingInternal :: TeamFeatureStatus 'WithoutLockStatus 'TeamFeatureConferenceCalling,
afcSelfDeletingMessagesInternal :: TeamFeatureStatus 'WithLockStatus 'TeamFeatureSelfDeletingMessages,
afcGuestLinkInternal :: TeamFeatureStatus 'WithLockStatus 'TeamFeatureGuestLinks,
afcSndFactorPasswordChallengeInternal :: TeamFeatureStatus 'WithLockStatus 'TeamFeatureSndFactorPasswordChallenge
}
deriving stock (Eq, Show)
deriving (FromJSON, ToJSON, S.ToSchema) via (Schema AllFeatureConfigs)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
deriving (Arbitrary) via (GenericUniform AllFeatureConfigs)

(not tested! but if it works, you can drop the implicit implementation below.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't get it to wrok

instance ToSchema AllFeatureConfigs where
schema =
object "AllFeatureConfigs" $
AllFeatureConfigs
<$> afcLegalholdStatusInternal .= field (name @'TeamFeatureLegalHold) schema
<*> afcSSOStatusInternal .= field (name @'TeamFeatureSSO) schema
<*> afcTeamSearchVisibilityAvailableInternal .= field (name @'TeamFeatureSearchVisibility) schema
<*> afcValidateSAMLEmailsInternal .= field (name @'TeamFeatureValidateSAMLEmails) schema
<*> afcDigitalSignaturesInternal .= field (name @'TeamFeatureDigitalSignatures) schema
<*> afcAppLockInternal .= field (name @'TeamFeatureAppLock) schema
<*> afcFileSharingInternal .= field (name @'TeamFeatureFileSharing) schema
<*> afcClassifiedDomainsInternal .= field (name @'TeamFeatureClassifiedDomains) schema
<*> afcConferenceCallingInternal .= field (name @'TeamFeatureConferenceCalling) schema
<*> afcSelfDeletingMessagesInternal .= field (name @'TeamFeatureSelfDeletingMessages) schema
<*> afcGuestLinkInternal .= field (name @'TeamFeatureGuestLinks) schema
<*> afcSndFactorPasswordChallengeInternal .= field (name @'TeamFeatureSndFactorPasswordChallenge) schema
where
name :: forall a. KnownTeamFeatureName a => Text
name = cs (toByteString' (knownTeamFeatureName @a))

instance Arbitrary AllFeatureConfigs where
arbitrary =
AllFeatureConfigs
<$> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary

----------------------------------------------------------------------
-- TeamFeatureStatusNoConfig

Expand Down Expand Up @@ -665,12 +715,3 @@ data LowerCaseFirst
instance StringModifier LowerCaseFirst where
getStringModifier (x : xs) = toLower x : xs
getStringModifier [] = []

newtype AllFeatureConfigs = AllFeatureConfigs {_allFeatureConfigs :: Aeson.Object}
deriving stock (Eq, Show)
deriving (FromJSON, ToJSON, S.ToSchema) via (Schema AllFeatureConfigs)

instance ToSchema AllFeatureConfigs where
schema =
named "AllFeatureConfigs" $
dimap _allFeatureConfigs AllFeatureConfigs jsonObject
1 change: 1 addition & 0 deletions libs/wire-api/test/unit/Test/Wire/API/Roundtrip/Aeson.hs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ tests =
testRoundTrip @(Team.Feature.TeamFeatureStatus 'Team.Feature.WithLockStatus 'Team.Feature.TeamFeatureSelfDeletingMessages),
testRoundTrip @(Team.Feature.TeamFeatureStatus 'Team.Feature.WithoutLockStatus 'Team.Feature.TeamFeatureSelfDeletingMessages),
testRoundTrip @(Team.Feature.TeamFeatureStatus 'Team.Feature.WithoutLockStatus 'Team.Feature.TeamFeatureSearchVisibilityInbound),
testRoundTrip @Team.Feature.AllFeatureConfigs,
testRoundTrip @Team.Feature.TeamFeatureStatusValue,
testRoundTrip @Team.Feature.LockStatusValue,
testRoundTrip @Team.Feature.LockStatus,
Expand Down
4 changes: 2 additions & 2 deletions services/galley/src/Galley/API/Public/Servant.hs
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ servantSitemap =
setSndFactorPasswordChallengeInternal
. DoAuth
)
<@> mkNamedAPI @"get-all-feature-configs" getAllFeatureConfigs
<@> mkNamedAPI @"get-all-features" (\luid tid -> AllFeatureConfigs <$> getAllFeatures luid tid)
<@> mkNamedAPI @"get-all-feature-configs" getAllFeatureConfigsForUser
<@> mkNamedAPI @"get-all-features" getAllFeatureConfigsForTeam
<@> mkNamedAPI @'("get-config", 'TeamFeatureLegalHold)
( getFeatureConfig @'WithoutLockStatus @'TeamFeatureLegalHold
getLegalholdStatusInternal
Expand Down
Loading