Skip to content

Commit

Permalink
Enable email notifications for all servers
Browse files Browse the repository at this point in the history
  • Loading branch information
estellecomment committed Mar 25, 2024
1 parent e3771e2 commit 797a272
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 19 deletions.
6 changes: 1 addition & 5 deletions config.dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
2 changes: 1 addition & 1 deletion config.preprod.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
2 changes: 1 addition & 1 deletion config.prod.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
2 changes: 1 addition & 1 deletion config.prod.lab.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
27 changes: 16 additions & 11 deletions src/tchap/util/TchapUIFeature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
56 changes: 56 additions & 0 deletions test/unit-tests/tchap/util/TchapUIFeature-test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});

0 comments on commit 797a272

Please sign in to comment.