Skip to content

Commit 6af7074

Browse files
Add feature flag based on homeserver in config.json (#665)
* add feature flag for email notification based on homeserver * add config * add comments * fix prettier * activate email notification on dev and preprod * Update src/tchap/util/TchapUIFeature.ts Co-authored-by: Estelle Comment <[email protected]> * Update src/tchap/util/TchapUIFeature.ts Co-authored-by: Estelle Comment <[email protected]> * update patch name --------- Co-authored-by: Estelle Comment <[email protected]>
1 parent 28615a5 commit 6af7074

File tree

7 files changed

+97
-4
lines changed

7 files changed

+97
-4
lines changed

config.dev.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,12 @@
8383
},
8484
"permalink_prefix": "https://www.tchap.incubateur.net",
8585
"custom_translations_url_comments": "To add translations, edit /src/i18n/strings/tchap_translations.json. It gets copied over to webapp/i18n for serving.",
86-
"custom_translations_url": "/i18n/tchap_translations.json"
86+
"custom_translations_url": "/i18n/tchap_translations.json",
87+
"tchap_features": {
88+
"feature_email_notification": [
89+
"agent1.tchap.incubateur.net",
90+
"agent2.tchap.incubateur.net",
91+
"externe.tchap.incubateur.net"
92+
]
93+
}
8794
}

config.preprod.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,8 @@
7777
},
7878
"permalink_prefix": "https://www.beta.tchap.gouv.fr",
7979
"custom_translations_url_comments": "To add translations, edit /src/i18n/strings/tchap_translations.json. It gets copied over to webapp/i18n for serving.",
80-
"custom_translations_url": "/i18n/tchap_translations.json"
80+
"custom_translations_url": "/i18n/tchap_translations.json",
81+
"tchap_features": {
82+
"feature_email_notification": ["i.tchap.gouv.fr", "e.tchap.gouv.fr"]
83+
}
8184
}

config.prod.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,5 +185,8 @@
185185
},
186186
"permalink_prefix": "https://tchap.gouv.fr",
187187
"custom_translations_url_comments": "To add translations, edit /src/i18n/strings/tchap_translations.json. It gets copied over to webapp/i18n for serving.",
188-
"custom_translations_url": "/i18n/tchap_translations.json"
188+
"custom_translations_url": "/i18n/tchap_translations.json",
189+
"tchap_features": {
190+
"feature_email_notification": []
191+
}
189192
}

config.prod.lab.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,5 +185,8 @@
185185
},
186186
"permalink_prefix": "https://tchap.gouv.fr",
187187
"custom_translations_url_comments": "To add translations, edit /src/i18n/strings/tchap_translations.json. It gets copied over to webapp/i18n for serving.",
188-
"custom_translations_url": "/i18n/tchap_translations.json"
188+
"custom_translations_url": "/i18n/tchap_translations.json",
189+
"tchap_features": {
190+
"feature_email_notification": []
191+
}
189192
}

patches/patches.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,5 +217,13 @@
217217
"files": [
218218
"src/components/views/rooms/MemberList.tsx"
219219
]
220+
},
221+
"tchap-features-from-config": {
222+
"github-issue": "",
223+
"package": "matrix-react-sdk",
224+
"files": [
225+
"src/IConfigOptions.ts",
226+
"src/components/views/settings/Notifications.tsx"
227+
]
220228
}
221229
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
diff --git a/node_modules/matrix-react-sdk/src/IConfigOptions.ts b/node_modules/matrix-react-sdk/src/IConfigOptions.ts
2+
index b2e44f2..c37340d 100644
3+
--- a/node_modules/matrix-react-sdk/src/IConfigOptions.ts
4+
+++ b/node_modules/matrix-react-sdk/src/IConfigOptions.ts
5+
@@ -192,3 +192,15 @@ export interface ISsoRedirectOptions {
6+
immediate?: boolean;
7+
on_welcome_page?: boolean;
8+
}
9+
+
10+
+
11+
+/* :tchap:
12+
+* Add tchap specific options to IConfigOptions. Both interfaces get merged in compilation. https://www.typescriptlang.org/docs/handbook/declaration-merging.html#merging-interfaces
13+
+* IConfigOptions declares which options can get retrieved with SdkConfig, if not declared SdkConfig complains it does not know the parameter.
14+
+*/
15+
+export interface IConfigOptions {
16+
+ tchap_features?: {
17+
+ feature_email_notification?:[string]//activate email notification on a list of home servers, ie : "agent1.tchap.incubateur.net"
18+
+ }
19+
+}
20+
+//end :tchap:
21+
\ No newline at end of file
22+
diff --git a/node_modules/matrix-react-sdk/src/components/views/settings/Notifications.tsx b/node_modules/matrix-react-sdk/src/components/views/settings/Notifications.tsx
23+
index 3e833b3..d8bf9c5 100644
24+
--- a/node_modules/matrix-react-sdk/src/components/views/settings/Notifications.tsx
25+
+++ b/node_modules/matrix-react-sdk/src/components/views/settings/Notifications.tsx
26+
@@ -48,6 +48,7 @@ import {
27+
updatePushRuleActions,
28+
} from "../../../utils/pushRules/updatePushRuleActions";
29+
import { Caption } from "../typography/Caption";
30+
+import TchapUIFeature from "../../../../../../src/tchap/util/TchapUIFeature";
31+
32+
// TODO: this "view" component still has far too much application logic in it,
33+
// which should be factored out to other files.
34+
@@ -703,8 +704,11 @@ export default class Notifications extends React.PureComponent<IProps, IState> {
35+
/>
36+
</>
37+
)}
38+
-
39+
+ {/* :TCHAP: show button only if feature is active on homeserver
40+
{emailSwitches}
41+
+ */}
42+
+ { TchapUIFeature.isFeatureActiveForHomeserver("feature_email_notification") ? emailSwitches : null}
43+
+ {/* :TCHAP: end */}
44+
</>
45+
);
46+
}

src/tchap/util/TchapUIFeature.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
* Tchap UI Feature flags
33
*/
44

5+
import { MatrixClientPeg } from "matrix-react-sdk/src/MatrixClientPeg";
6+
import SdkConfig from "matrix-react-sdk/src/SdkConfig";
7+
58
export default class TchapUIFeature {
69
/**
710
* This flag controls weither space related settings should be displayed or not. It differs from the flag UIComponent.CreateSpaces.
@@ -24,4 +27,24 @@ export default class TchapUIFeature {
2427
*/
2528
public static activateClearCacheAndReloadAtVersion4 = true;
2629

30+
/**
31+
get list of homeservers where the feature should be activated from config.json
32+
example
33+
for feature : feature_email_notification
34+
add this in config.json
35+
{..
36+
"tchap":{
37+
"feature_email_notification": ["agent1.tchap.incubateur.net"]
38+
}
39+
..
40+
}
41+
*/
42+
public static isFeatureActiveForHomeserver(feature:string):boolean {
43+
44+
const homeserversWithFeature:[string] = SdkConfig.get("tchap_features")?.[feature] || [];
45+
const userHomeServer = MatrixClientPeg.getHomeserverName();
46+
return homeserversWithFeature.includes(userHomeServer);
47+
}
48+
49+
2750
}

0 commit comments

Comments
 (0)