-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Emit event notification for file sharing feature update. (#1655)
Authored-by: Stefan Matting <stefan@wire.com>
- Loading branch information
Showing
12 changed files
with
251 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
-- This file is part of the Wire Server implementation. | ||
-- | ||
-- Copyright (C) 2020 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 Wire.API.Event.FeatureConfig | ||
( Event (..), | ||
EventType (..), | ||
EventData (..), | ||
) | ||
where | ||
|
||
import Control.Arrow ((&&&)) | ||
import Control.Lens (makePrisms, _1) | ||
import Data.Aeson (FromJSON (..), ToJSON (..)) | ||
import qualified Data.HashMap.Strict as HashMap | ||
import Data.Json.Util (ToJSONObject (..)) | ||
import Data.Schema | ||
import qualified Data.Swagger as S | ||
import Imports | ||
import Wire.API.Team.Feature (TeamFeatureAppLockConfig, TeamFeatureClassifiedDomainsConfig, TeamFeatureName (..), TeamFeatureStatusNoConfig, TeamFeatureStatusWithConfig) | ||
|
||
data Event = Event | ||
{ _eventType :: EventType, | ||
_eventFeatureName :: TeamFeatureName, | ||
_eventData :: EventData | ||
} | ||
deriving (Eq, Show, Generic) | ||
|
||
data EventType = Update | ||
deriving (Eq, Show) | ||
|
||
instance ToSchema EventType where | ||
schema = | ||
enum @Text "EventType" $ | ||
mconcat | ||
[ element "feature-config.update" Update | ||
] | ||
|
||
data EventData | ||
= EdFeatureWithoutConfigChanged TeamFeatureStatusNoConfig | ||
| EdFeatureApplockChanged (TeamFeatureStatusWithConfig TeamFeatureAppLockConfig) | ||
| EdFeatureClassifiedDomainsChanged (TeamFeatureStatusWithConfig TeamFeatureClassifiedDomainsConfig) | ||
deriving (Eq, Show, Generic) | ||
|
||
makePrisms ''EventData | ||
|
||
taggedEventDataSchema :: ObjectSchema SwaggerDoc (TeamFeatureName, EventData) | ||
taggedEventDataSchema = | ||
bind | ||
(fst .= field "name" schema) | ||
(snd .= fieldOver _1 "data" edata) | ||
where | ||
edata = dispatch $ \case | ||
TeamFeatureLegalHold -> tag _EdFeatureWithoutConfigChanged (unnamed schema) | ||
TeamFeatureSSO -> tag _EdFeatureWithoutConfigChanged (unnamed schema) | ||
TeamFeatureSearchVisibility -> tag _EdFeatureWithoutConfigChanged (unnamed schema) | ||
TeamFeatureValidateSAMLEmails -> tag _EdFeatureWithoutConfigChanged (unnamed schema) | ||
TeamFeatureDigitalSignatures -> tag _EdFeatureWithoutConfigChanged (unnamed schema) | ||
TeamFeatureAppLock -> tag _EdFeatureApplockChanged (unnamed schema) | ||
TeamFeatureFileSharing -> tag _EdFeatureWithoutConfigChanged (unnamed schema) | ||
TeamFeatureClassifiedDomains -> tag _EdFeatureClassifiedDomainsChanged (unnamed schema) | ||
|
||
eventObjectSchema :: ObjectSchema SwaggerDoc Event | ||
eventObjectSchema = | ||
mkEvent | ||
<$> (_eventFeatureName &&& _eventData) .= taggedEventDataSchema | ||
<*> _eventType .= field "type" schema | ||
where | ||
mkEvent :: (TeamFeatureName, EventData) -> EventType -> Event | ||
mkEvent (feature, eventData) eventType = Event eventType feature eventData | ||
|
||
instance ToSchema Event where | ||
schema = object "Event" eventObjectSchema | ||
|
||
instance ToJSONObject Event where | ||
toJSONObject = | ||
HashMap.fromList | ||
. fromMaybe [] | ||
. schemaOut eventObjectSchema | ||
|
||
instance FromJSON Event where | ||
parseJSON = schemaParseJSON | ||
|
||
instance ToJSON Event where | ||
toJSON = schemaToJSON | ||
|
||
instance S.ToSchema Event where | ||
declareNamedSchema = schemaToSwagger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
libs/wire-api/test/golden/testObject_FeatureConfigEvent_1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"data": { | ||
"status": "enabled" | ||
}, | ||
"name": "fileSharing", | ||
"type": "feature-config.update" | ||
} |
7 changes: 7 additions & 0 deletions
7
libs/wire-api/test/golden/testObject_FeatureConfigEvent_2.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"data": { | ||
"status": "disabled" | ||
}, | ||
"name": "sso", | ||
"type": "feature-config.update" | ||
} |
11 changes: 11 additions & 0 deletions
11
libs/wire-api/test/golden/testObject_FeatureConfigEvent_3.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"data": { | ||
"status": "disabled", | ||
"config": { | ||
"enforceAppLock": true, | ||
"inactivityTimeoutSecs": 300 | ||
} | ||
}, | ||
"name": "appLock", | ||
"type": "feature-config.update" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
libs/wire-api/test/unit/Test/Wire/API/Golden/Manual/FeatureConfigEvent.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Test.Wire.API.Golden.Manual.FeatureConfigEvent where | ||
|
||
import Imports | ||
import Wire.API.Event.FeatureConfig | ||
import Wire.API.Team.Feature | ||
|
||
testObject_FeatureConfigEvent_1 :: Event | ||
testObject_FeatureConfigEvent_1 = Event Update TeamFeatureFileSharing (EdFeatureWithoutConfigChanged (TeamFeatureStatusNoConfig TeamFeatureEnabled)) | ||
|
||
testObject_FeatureConfigEvent_2 :: Event | ||
testObject_FeatureConfigEvent_2 = Event Update TeamFeatureSSO (EdFeatureWithoutConfigChanged (TeamFeatureStatusNoConfig TeamFeatureDisabled)) | ||
|
||
testObject_FeatureConfigEvent_3 :: Event | ||
testObject_FeatureConfigEvent_3 = | ||
Event | ||
Update | ||
TeamFeatureAppLock | ||
( EdFeatureApplockChanged | ||
( TeamFeatureStatusWithConfig | ||
TeamFeatureDisabled | ||
(TeamFeatureAppLockConfig (EnforceAppLock True) 300) | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.