From 797a2728bec1166f2c295a8c2aa8dd8b204ae570 Mon Sep 17 00:00:00 2001 From: Estelle Comment Date: Thu, 21 Mar 2024 14:44:50 +0100 Subject: [PATCH] Enable email notifications for all servers --- config.dev.json | 6 +- config.preprod.json | 2 +- config.prod.json | 2 +- config.prod.lab.json | 2 +- src/tchap/util/TchapUIFeature.ts | 27 +++++---- .../tchap/util/TchapUIFeature-test.ts | 56 +++++++++++++++++++ 6 files changed, 76 insertions(+), 19 deletions(-) create mode 100644 test/unit-tests/tchap/util/TchapUIFeature-test.ts diff --git a/config.dev.json b/config.dev.json index 7462a55a10..66ffb9682f 100644 --- a/config.dev.json +++ b/config.dev.json @@ -108,11 +108,7 @@ } ], "tchap_features": { - "feature_email_notification": [ - "dev01.tchap.incubateur.net", - "dev02.tchap.incubateur.net", - "ext01.tchap.incubateur.net" - ], + "feature_email_notification": ["*"], "feature_space": ["dev01.tchap.incubateur.net", "dev02.tchap.incubateur.net", "ext01.tchap.incubateur.net"], "feature_thread": ["dev01.tchap.incubateur.net", "dev02.tchap.incubateur.net", "ext01.tchap.incubateur.net"], "feature_audio_call": [ diff --git a/config.preprod.json b/config.preprod.json index 36682c57cd..87df7d170a 100644 --- a/config.preprod.json +++ b/config.preprod.json @@ -103,7 +103,7 @@ } ], "tchap_features": { - "feature_email_notification": ["i.tchap.gouv.fr", "e.tchap.gouv.fr"], + "feature_email_notification": ["*"], "feature_thread": ["i.tchap.gouv.fr", "e.tchap.gouv.fr"], "feature_space": ["i.tchap.gouv.fr", "e.tchap.gouv.fr"], "feature_audio_call": ["i.tchap.gouv.fr", "e.tchap.gouv.fr"], diff --git a/config.prod.json b/config.prod.json index ae2bdf5791..7be715f3a3 100644 --- a/config.prod.json +++ b/config.prod.json @@ -190,7 +190,7 @@ } ], "tchap_features": { - "feature_email_notification": ["agent.dinum.tchap.gouv.fr"], + "feature_email_notification": ["*"], "feature_thread": [], "feature_space": [], "feature_audio_call": ["agent.dinum.tchap.gouv.fr"], diff --git a/config.prod.lab.json b/config.prod.lab.json index 96f8d7fe11..6fa70c5755 100644 --- a/config.prod.lab.json +++ b/config.prod.lab.json @@ -190,7 +190,7 @@ } ], "tchap_features": { - "feature_email_notification": ["agent.dinum.tchap.gouv.fr"], + "feature_email_notification": ["*"], "feature_thread": ["agent.dinum.tchap.gouv.fr"], "feature_space": ["agent.dinum.tchap.gouv.fr"], "feature_audio_call": ["agent.dinum.tchap.gouv.fr"], diff --git a/src/tchap/util/TchapUIFeature.ts b/src/tchap/util/TchapUIFeature.ts index c55a468349..bb8b17e785 100644 --- a/src/tchap/util/TchapUIFeature.ts +++ b/src/tchap/util/TchapUIFeature.ts @@ -28,20 +28,25 @@ export default class TchapUIFeature { public static activateClearCacheAndReloadAtVersion4 = true; /** - get list of homeservers where the feature should be activated from config.json - example - for feature : feature_email_notification - add this in config.json - {.. - "tchap":{ - "feature_email_notification": ["dev01.tchap.incubateur.net"] - } - .. - } + * Whether the given feature is active on the current user's homeserver. + * We get the list of homeservers where the feature should be activated from config.json + * Example : add this in config.json + * {.. + * "tchap_features":{ + * "feature_email_notification": ["dev01.tchap.incubateur.net"] // only dev01 has the feature + * "feature_thread": ["*"] // all servers have the feature + * "feature_space": ["*", "dev01.tchap.incubateur.net"] // all servers have the feature, 2rd arg is ignored. + * } + * .. + * } */ public static isFeatureActiveForHomeserver(feature:string):boolean { - const homeserversWithFeature:[string] = SdkConfig.get("tchap_features")?.[feature] || []; + + if (homeserversWithFeature.indexOf("*") > -1) { + return true; + } + const userHomeServer = MatrixClientPeg.getHomeserverName(); return homeserversWithFeature.includes(userHomeServer); } diff --git a/test/unit-tests/tchap/util/TchapUIFeature-test.ts b/test/unit-tests/tchap/util/TchapUIFeature-test.ts new file mode 100644 index 0000000000..e66edea7ff --- /dev/null +++ b/test/unit-tests/tchap/util/TchapUIFeature-test.ts @@ -0,0 +1,56 @@ +import { stubClient } from "matrix-react-sdk/test/test-utils"; +import SdkConfig, { ConfigOptions } from "matrix-react-sdk/src/SdkConfig"; +import { MatrixClientPeg } from "matrix-react-sdk/src/MatrixClientPeg"; + +import TchapUIFeature from "~tchap-web/src/tchap/util/TchapUIFeature"; + +describe("TchapUIFeature", () => { + const featureName: string = "my_funky_feature"; + const homeserverName: string = "my.home.server"; + + beforeAll(() => { + SdkConfig.reset(); // in case other tests didn't clean up + }); + + beforeEach(() => { + stubClient(); + MatrixClientPeg.getHomeserverName = () => homeserverName; + }); + + afterEach(function () { + SdkConfig.reset(); // we touch the config, so clean up + }); + + const mockFeatureConfig = (homeservers: string[]) => { + // mock SdkConfig.get("tchap_features") + const config: ConfigOptions = { tchap_features: {} }; + config.tchap_features[featureName] = homeservers; + SdkConfig.put(config); + }; + + it("returns true when the user's homeserver is listed in config", () => { + mockFeatureConfig([homeserverName, "some.other.server"]); + expect(TchapUIFeature.isFeatureActiveForHomeserver(featureName)).toEqual(true); + }); + + it("returns false when the user's homeserver is not listed in config", () => { + mockFeatureConfig(["some.other.server"]); + expect(TchapUIFeature.isFeatureActiveForHomeserver(featureName)).toEqual(false); + }); + + it("returns true when '*' is alone in config", () => { + mockFeatureConfig(["*"]); + expect(TchapUIFeature.isFeatureActiveForHomeserver(featureName)).toEqual(true); + }); + + it("returns true when '*' is anywhere in config", () => { + mockFeatureConfig(["some.other.server", "*"]); + expect(TchapUIFeature.isFeatureActiveForHomeserver(featureName)).toEqual(true); + }); + + it("returns false when no tchap_features in config", () => { + const config: ConfigOptions = {}; + SdkConfig.put(config); + expect(TchapUIFeature.isFeatureActiveForHomeserver(featureName)).toEqual(false); + }); +});