From 6e08811d58671f193f027b037347a23726eac465 Mon Sep 17 00:00:00 2001 From: Nicolas Buquet Date: Thu, 4 Jan 2024 12:25:14 +0100 Subject: [PATCH 1/3] Setup feature activation by instance for Tchap --- Btchap/Config/BuildSettings.swift | 12 ++++++++ DevTchap/Config/BuildSettings.swift | 12 ++++++++ .../Modules/Settings/SettingsViewController.m | 4 +-- RiotNSE/BuildSettings.swift | 14 ++++++++++ RiotShareExtension/BuildSettings.swift | 14 ++++++++++ Tchap/Config/BuildSettings.swift | 14 ++++++++++ Tchap/Extensions/Account+Tchap.swift | 28 +++++++++++++++++++ 7 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 Tchap/Extensions/Account+Tchap.swift diff --git a/Btchap/Config/BuildSettings.swift b/Btchap/Config/BuildSettings.swift index 485c89ebcf..a306e0f5f4 100644 --- a/Btchap/Config/BuildSettings.swift +++ b/Btchap/Config/BuildSettings.swift @@ -229,6 +229,18 @@ final class BuildSettings: NSObject { static let allowBackgroundAudioMessagePlayback: Bool = true + // Tchap: Feature activation by Instance + static let tchapFeatureAnyFeature = "*" // To allow any feature for some instances + static let tchapFeatureAnyInstance = "*" // To allow a feature for any instance + // tchapFeatureAnyFeature : [ ] to allow any feature for an instance + // "" : [ tchapFeatureAnyInstance ] to allow a feature to any instance + static let tchapFeatureNotificationByEmail = "tchapFeatureNotificationByEmail" + static let tchapFeatureVoiceOverIP = "tchapFeatureVoiceOverIP" + static let tchapFeatureVideoOverIP = "tchapFeatureVideoOverIP" // Tchap: in pre-prod, allow any feature to any instance. + static var tchapFeatureByInstance: [String: [String]] = [ + tchapFeatureAnyFeature: [ tchapFeatureAnyInstance ] + ] + // MARK: - Side Menu static let enableSideMenu: Bool = true && !newAppLayoutEnabled static let sideMenuShowInviteFriends: Bool = true diff --git a/DevTchap/Config/BuildSettings.swift b/DevTchap/Config/BuildSettings.swift index a311ac487d..80a2fcb790 100644 --- a/DevTchap/Config/BuildSettings.swift +++ b/DevTchap/Config/BuildSettings.swift @@ -230,6 +230,18 @@ final class BuildSettings: NSObject { static let allowBackgroundAudioMessagePlayback: Bool = true + // Tchap: Feature activation by Instance + static let tchapFeatureAnyFeature = "*" // To allow any feature for some instances + static let tchapFeatureAnyInstance = "*" // To allow a feature for any instance + // tchapFeatureAnyFeature : [ ] to allow any feature for an instance + // "" : [ tchapFeatureAnyInstance ] to allow a feature to any instance + static let tchapFeatureNotificationByEmail = "tchapFeatureNotificationByEmail" + static let tchapFeatureVoiceOverIP = "tchapFeatureVoiceOverIP" + static let tchapFeatureVideoOverIP = "tchapFeatureVideoOverIP" // Tchap: in pre-prod, allow any feature to any instance. + static var tchapFeatureByInstance: [String: [String]] = [ + tchapFeatureAnyFeature: [ tchapFeatureAnyInstance ] + ] + // MARK: - Side Menu static let enableSideMenu: Bool = true && !newAppLayoutEnabled static let sideMenuShowInviteFriends: Bool = true diff --git a/Riot/Modules/Settings/SettingsViewController.m b/Riot/Modules/Settings/SettingsViewController.m index 114d996438..e76ab67acb 100644 --- a/Riot/Modules/Settings/SettingsViewController.m +++ b/Riot/Modules/Settings/SettingsViewController.m @@ -492,8 +492,8 @@ - (void)updateSections [sectionNotificationSettings addRowWithTag:NOTIFICATION_SETTINGS_SHOW_DECODED_CONTENT]; } - // Tchap: allow enabling email notifications only for DINUM homeserver - if ([account.identityServerURL isEqualToString:[BuildSettings.serverUrlPrefix stringByAppendingString:@"agent.dinum.tchap.gouv.fr"]]) { + // Tchap: allow enabling email notifications only for allowed instances + if ([account isFeatureActivated:BuildSettings.tchapFeatureNotificationByEmail]) { [sectionNotificationSettings addRowWithTag:NOTIFICATION_SETTINGS_ENABLE_BY_EMAIL_INDEX]; } [sectionNotificationSettings addRowWithTag:NOTIFICATION_SETTINGS_PIN_MISSED_NOTIFICATIONS_INDEX]; diff --git a/RiotNSE/BuildSettings.swift b/RiotNSE/BuildSettings.swift index dfeaa5da35..7ea3b2ce16 100644 --- a/RiotNSE/BuildSettings.swift +++ b/RiotNSE/BuildSettings.swift @@ -259,6 +259,20 @@ final class BuildSettings: NSObject { static let allowBackgroundAudioMessagePlayback: Bool = true + // Tchap: Feature activation by Instance + static let tchapFeatureAnyFeature = "*" // To allow any feature for some instances + static let tchapFeatureAnyInstance = "*" // To allow a feature for any instance + // tchapFeatureAnyFeature : [ ] to allow any feature for an instance + // "" : [ tchapFeatureAnyInstance ] to allow a feature to any instance + static let tchapFeatureNotificationByEmail = "tchapFeatureNotificationByEmail" + static let tchapFeatureVoiceOverIP = "tchapFeatureVoiceOverIP" + static let tchapFeatureVideoOverIP = "tchapFeatureVideoOverIP" + static var tchapFeatureByInstance: [String: [String]] = [ + tchapFeatureNotificationByEmail: [ + "agent.dinum.tchap.gouv.fr" + ] + ] + // MARK: - Side Menu static let enableSideMenu: Bool = true && !newAppLayoutEnabled static let sideMenuShowInviteFriends: Bool = true diff --git a/RiotShareExtension/BuildSettings.swift b/RiotShareExtension/BuildSettings.swift index dfeaa5da35..7ea3b2ce16 100644 --- a/RiotShareExtension/BuildSettings.swift +++ b/RiotShareExtension/BuildSettings.swift @@ -259,6 +259,20 @@ final class BuildSettings: NSObject { static let allowBackgroundAudioMessagePlayback: Bool = true + // Tchap: Feature activation by Instance + static let tchapFeatureAnyFeature = "*" // To allow any feature for some instances + static let tchapFeatureAnyInstance = "*" // To allow a feature for any instance + // tchapFeatureAnyFeature : [ ] to allow any feature for an instance + // "" : [ tchapFeatureAnyInstance ] to allow a feature to any instance + static let tchapFeatureNotificationByEmail = "tchapFeatureNotificationByEmail" + static let tchapFeatureVoiceOverIP = "tchapFeatureVoiceOverIP" + static let tchapFeatureVideoOverIP = "tchapFeatureVideoOverIP" + static var tchapFeatureByInstance: [String: [String]] = [ + tchapFeatureNotificationByEmail: [ + "agent.dinum.tchap.gouv.fr" + ] + ] + // MARK: - Side Menu static let enableSideMenu: Bool = true && !newAppLayoutEnabled static let sideMenuShowInviteFriends: Bool = true diff --git a/Tchap/Config/BuildSettings.swift b/Tchap/Config/BuildSettings.swift index dfeaa5da35..7ea3b2ce16 100644 --- a/Tchap/Config/BuildSettings.swift +++ b/Tchap/Config/BuildSettings.swift @@ -259,6 +259,20 @@ final class BuildSettings: NSObject { static let allowBackgroundAudioMessagePlayback: Bool = true + // Tchap: Feature activation by Instance + static let tchapFeatureAnyFeature = "*" // To allow any feature for some instances + static let tchapFeatureAnyInstance = "*" // To allow a feature for any instance + // tchapFeatureAnyFeature : [ ] to allow any feature for an instance + // "" : [ tchapFeatureAnyInstance ] to allow a feature to any instance + static let tchapFeatureNotificationByEmail = "tchapFeatureNotificationByEmail" + static let tchapFeatureVoiceOverIP = "tchapFeatureVoiceOverIP" + static let tchapFeatureVideoOverIP = "tchapFeatureVideoOverIP" + static var tchapFeatureByInstance: [String: [String]] = [ + tchapFeatureNotificationByEmail: [ + "agent.dinum.tchap.gouv.fr" + ] + ] + // MARK: - Side Menu static let enableSideMenu: Bool = true && !newAppLayoutEnabled static let sideMenuShowInviteFriends: Bool = true diff --git a/Tchap/Extensions/Account+Tchap.swift b/Tchap/Extensions/Account+Tchap.swift new file mode 100644 index 0000000000..0748194b46 --- /dev/null +++ b/Tchap/Extensions/Account+Tchap.swift @@ -0,0 +1,28 @@ +// +// Copyright 2024 New Vector Ltd +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import Foundation + +@objc extension MXKAccount { + + func isFeatureActivated(_ featureId: String) -> Bool { + guard let targetedFeature = BuildSettings.tchapFeatureByInstance[featureId] ?? BuildSettings.tchapFeatureByInstance[BuildSettings.tchapFeatureAnyFeature] else { + return false + } + + return targetedFeature.contains(BuildSettings.tchapFeatureAnyInstance) || targetedFeature.contains(self.identityServerURL.replacingOccurrences(of: BuildSettings.serverUrlPrefix, with: "")) + } +} From 33eab162eaf4e09a4698dd536df599d80d47b2f6 Mon Sep 17 00:00:00 2001 From: Nicolas Buquet Date: Thu, 4 Jan 2024 12:27:52 +0100 Subject: [PATCH 2/3] Add changelog --- changelog.d/948.change | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/948.change diff --git a/changelog.d/948.change b/changelog.d/948.change new file mode 100644 index 0000000000..4fb87f7822 --- /dev/null +++ b/changelog.d/948.change @@ -0,0 +1 @@ +Autoriser l'activation de nouvelles fonctionnalités par instance de serveur \ No newline at end of file From b75012b288c2ddf12d7fe38b9a3e6d5f9889d729 Mon Sep 17 00:00:00 2001 From: Nicolas Buquet Date: Thu, 4 Jan 2024 17:02:42 +0100 Subject: [PATCH 3/3] Use homeServer rather than identityServer. Rename `featureByInstance` to `featureByHomeServer` --- Btchap/Config/BuildSettings.swift | 8 ++++---- DevTchap/Config/BuildSettings.swift | 10 +++++----- RiotNSE/BuildSettings.swift | 6 +++--- RiotShareExtension/BuildSettings.swift | 6 +++--- Tchap/Config/BuildSettings.swift | 6 +++--- Tchap/Extensions/Account+Tchap.swift | 14 ++++++++++++-- 6 files changed, 30 insertions(+), 20 deletions(-) diff --git a/Btchap/Config/BuildSettings.swift b/Btchap/Config/BuildSettings.swift index a306e0f5f4..eb0223e148 100644 --- a/Btchap/Config/BuildSettings.swift +++ b/Btchap/Config/BuildSettings.swift @@ -231,14 +231,14 @@ final class BuildSettings: NSObject { // Tchap: Feature activation by Instance static let tchapFeatureAnyFeature = "*" // To allow any feature for some instances - static let tchapFeatureAnyInstance = "*" // To allow a feature for any instance + static let tchapFeatureAnyHomeServer = "*" // To allow a feature for any instance // tchapFeatureAnyFeature : [ ] to allow any feature for an instance - // "" : [ tchapFeatureAnyInstance ] to allow a feature to any instance + // "" : [ tchapFeatureAnyHomeServer ] to allow a feature to any instance static let tchapFeatureNotificationByEmail = "tchapFeatureNotificationByEmail" static let tchapFeatureVoiceOverIP = "tchapFeatureVoiceOverIP" static let tchapFeatureVideoOverIP = "tchapFeatureVideoOverIP" // Tchap: in pre-prod, allow any feature to any instance. - static var tchapFeatureByInstance: [String: [String]] = [ - tchapFeatureAnyFeature: [ tchapFeatureAnyInstance ] + static var tchapFeatureByHomeServer: [String: [String]] = [ + tchapFeatureAnyFeature: [ tchapFeatureAnyHomeServer ] ] // MARK: - Side Menu diff --git a/DevTchap/Config/BuildSettings.swift b/DevTchap/Config/BuildSettings.swift index 80a2fcb790..7e040064b5 100644 --- a/DevTchap/Config/BuildSettings.swift +++ b/DevTchap/Config/BuildSettings.swift @@ -232,14 +232,14 @@ final class BuildSettings: NSObject { // Tchap: Feature activation by Instance static let tchapFeatureAnyFeature = "*" // To allow any feature for some instances - static let tchapFeatureAnyInstance = "*" // To allow a feature for any instance + static let tchapFeatureAnyHomeServer = "*" // To allow a feature for any instance // tchapFeatureAnyFeature : [ ] to allow any feature for an instance - // "" : [ tchapFeatureAnyInstance ] to allow a feature to any instance + // "" : [ tchapFeatureAnyHomeServer ] to allow a feature to any instance static let tchapFeatureNotificationByEmail = "tchapFeatureNotificationByEmail" static let tchapFeatureVoiceOverIP = "tchapFeatureVoiceOverIP" - static let tchapFeatureVideoOverIP = "tchapFeatureVideoOverIP" // Tchap: in pre-prod, allow any feature to any instance. - static var tchapFeatureByInstance: [String: [String]] = [ - tchapFeatureAnyFeature: [ tchapFeatureAnyInstance ] + static let tchapFeatureVideoOverIP = "tchapFeatureVideoOverIP" // Tchap: in Dev, allow any feature to any instance. + static var tchapFeatureByHomeServer: [String: [String]] = [ + tchapFeatureAnyFeature: [ tchapFeatureAnyHomeServer ] ] // MARK: - Side Menu diff --git a/RiotNSE/BuildSettings.swift b/RiotNSE/BuildSettings.swift index 7ea3b2ce16..319f939bce 100644 --- a/RiotNSE/BuildSettings.swift +++ b/RiotNSE/BuildSettings.swift @@ -261,13 +261,13 @@ final class BuildSettings: NSObject { // Tchap: Feature activation by Instance static let tchapFeatureAnyFeature = "*" // To allow any feature for some instances - static let tchapFeatureAnyInstance = "*" // To allow a feature for any instance + static let tchapFeatureAnyHomeServer = "*" // To allow a feature for any instance // tchapFeatureAnyFeature : [ ] to allow any feature for an instance - // "" : [ tchapFeatureAnyInstance ] to allow a feature to any instance + // "" : [ tchapFeatureAnyHomeServer ] to allow a feature to any instance static let tchapFeatureNotificationByEmail = "tchapFeatureNotificationByEmail" static let tchapFeatureVoiceOverIP = "tchapFeatureVoiceOverIP" static let tchapFeatureVideoOverIP = "tchapFeatureVideoOverIP" - static var tchapFeatureByInstance: [String: [String]] = [ + static var tchapFeatureByHomeServer: [String: [String]] = [ tchapFeatureNotificationByEmail: [ "agent.dinum.tchap.gouv.fr" ] diff --git a/RiotShareExtension/BuildSettings.swift b/RiotShareExtension/BuildSettings.swift index 7ea3b2ce16..319f939bce 100644 --- a/RiotShareExtension/BuildSettings.swift +++ b/RiotShareExtension/BuildSettings.swift @@ -261,13 +261,13 @@ final class BuildSettings: NSObject { // Tchap: Feature activation by Instance static let tchapFeatureAnyFeature = "*" // To allow any feature for some instances - static let tchapFeatureAnyInstance = "*" // To allow a feature for any instance + static let tchapFeatureAnyHomeServer = "*" // To allow a feature for any instance // tchapFeatureAnyFeature : [ ] to allow any feature for an instance - // "" : [ tchapFeatureAnyInstance ] to allow a feature to any instance + // "" : [ tchapFeatureAnyHomeServer ] to allow a feature to any instance static let tchapFeatureNotificationByEmail = "tchapFeatureNotificationByEmail" static let tchapFeatureVoiceOverIP = "tchapFeatureVoiceOverIP" static let tchapFeatureVideoOverIP = "tchapFeatureVideoOverIP" - static var tchapFeatureByInstance: [String: [String]] = [ + static var tchapFeatureByHomeServer: [String: [String]] = [ tchapFeatureNotificationByEmail: [ "agent.dinum.tchap.gouv.fr" ] diff --git a/Tchap/Config/BuildSettings.swift b/Tchap/Config/BuildSettings.swift index 7ea3b2ce16..319f939bce 100644 --- a/Tchap/Config/BuildSettings.swift +++ b/Tchap/Config/BuildSettings.swift @@ -261,13 +261,13 @@ final class BuildSettings: NSObject { // Tchap: Feature activation by Instance static let tchapFeatureAnyFeature = "*" // To allow any feature for some instances - static let tchapFeatureAnyInstance = "*" // To allow a feature for any instance + static let tchapFeatureAnyHomeServer = "*" // To allow a feature for any instance // tchapFeatureAnyFeature : [ ] to allow any feature for an instance - // "" : [ tchapFeatureAnyInstance ] to allow a feature to any instance + // "" : [ tchapFeatureAnyHomeServer ] to allow a feature to any instance static let tchapFeatureNotificationByEmail = "tchapFeatureNotificationByEmail" static let tchapFeatureVoiceOverIP = "tchapFeatureVoiceOverIP" static let tchapFeatureVideoOverIP = "tchapFeatureVideoOverIP" - static var tchapFeatureByInstance: [String: [String]] = [ + static var tchapFeatureByHomeServer: [String: [String]] = [ tchapFeatureNotificationByEmail: [ "agent.dinum.tchap.gouv.fr" ] diff --git a/Tchap/Extensions/Account+Tchap.swift b/Tchap/Extensions/Account+Tchap.swift index 0748194b46..9223e9cd33 100644 --- a/Tchap/Extensions/Account+Tchap.swift +++ b/Tchap/Extensions/Account+Tchap.swift @@ -19,10 +19,20 @@ import Foundation @objc extension MXKAccount { func isFeatureActivated(_ featureId: String) -> Bool { - guard let targetedFeature = BuildSettings.tchapFeatureByInstance[featureId] ?? BuildSettings.tchapFeatureByInstance[BuildSettings.tchapFeatureAnyFeature] else { + guard let targetedFeature = BuildSettings.tchapFeatureByHomeServer[featureId] ?? BuildSettings.tchapFeatureByHomeServer[BuildSettings.tchapFeatureAnyFeature] else { return false } - return targetedFeature.contains(BuildSettings.tchapFeatureAnyInstance) || targetedFeature.contains(self.identityServerURL.replacingOccurrences(of: BuildSettings.serverUrlPrefix, with: "")) + if targetedFeature.contains(BuildSettings.tchapFeatureAnyHomeServer) { + return true + } + + guard let homeServerURL = self.mxCredentials.homeServer else { + return false + } + + let homeServerDomain = homeServerURL.replacingOccurrences(of: BuildSettings.serverUrlPrefix, with: "") + + return targetedFeature.contains(homeServerDomain) } }