mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-16 06:28:27 +02:00
Feature/2897 restricted user
This commit is contained in:
committed by
Arnfried Griesert
parent
472dbded4e
commit
4b1ca0ff7f
@@ -462,7 +462,7 @@ final class BuildSettings: NSObject {
|
||||
static let customServerDisplayName : String = ""
|
||||
|
||||
// MARK BWI show/hide developer menu
|
||||
static let bwiShowDeveloperSettings : Bool = false
|
||||
static let bwiShowDeveloperSettings : Bool = true
|
||||
|
||||
// MARK BWI personal notes room
|
||||
static let bwiPersonalNotesRoom : Bool = true
|
||||
@@ -512,7 +512,7 @@ final class BuildSettings: NSObject {
|
||||
// MARK: - Location Sharing
|
||||
|
||||
static let tileServerMapURL = ""
|
||||
static let tileServerMapStyleURL = URL(string: "")!
|
||||
static let tileServerMapStyleURL = URL(string: "https://map.tyler.org")!
|
||||
|
||||
static let locationSharingEnabled = false
|
||||
}
|
||||
|
||||
@@ -29,4 +29,7 @@
|
||||
"bwi_settings_developer_apply_orig_app_config" = "MDM Config: BW";
|
||||
"bwi_settings_developer_reset_app_config" = "MDM Config: Reset";
|
||||
|
||||
"bwi_settings_developer_restrict_user" = "Nutzer einschränken";
|
||||
"bwi_settings_developer_unrestrict_user" = "Nutzereinschränkung aufheben";
|
||||
|
||||
"bwi_mdm_logout_message" = "Die Konfiguration hat sich geändert. Bitte melde dich neu an.";
|
||||
|
||||
@@ -29,4 +29,7 @@
|
||||
"bwi_settings_developer_apply_orig_app_config" = "MDM Config: BW";
|
||||
"bwi_settings_developer_reset_app_config" = "MDM Config: Reset";
|
||||
|
||||
"bwi_settings_developer_restrict_user" = "Restrict user";
|
||||
"bwi_settings_developer_unrestrict_user" = "Remove user restriction";
|
||||
|
||||
"bwi_mdm_logout_message" = "The configuration has changed. Please reconnect.";
|
||||
|
||||
@@ -859,8 +859,12 @@ NSString *const RecentsViewControllerDataReadyNotification = @"RecentsViewContro
|
||||
// Sanity check
|
||||
if (self.parentViewController && [self.parentViewController isKindOfClass:UnifiedSearchViewController.class])
|
||||
{
|
||||
// Show the directory screen
|
||||
[((UnifiedSearchViewController*)self.parentViewController) showPublicRoomsDirectory];
|
||||
AccountRestrictionService *service = [[AccountRestrictionService alloc] initWithMxSession:self.mainSession];
|
||||
|
||||
if (![service isRoomAccessRestriction]) {
|
||||
// Show the directory screen
|
||||
[((UnifiedSearchViewController*)self.parentViewController) showPublicRoomsDirectory];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -538,15 +538,21 @@
|
||||
|
||||
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
|
||||
{
|
||||
AccountRestrictionService* service = [[AccountRestrictionService alloc] initWithMxSession:self.mainSession];
|
||||
|
||||
if (self.selectedViewController == recentsViewController)
|
||||
{
|
||||
// As the public room search is local, it can be updated on each text change
|
||||
[self updateSearch];
|
||||
if (![service isRoomAccessRestriction]) {
|
||||
// As the public room search is local, it can be updated on each text change
|
||||
[self updateSearch];
|
||||
}
|
||||
}
|
||||
else if (self.selectedViewController == peopleSearchViewController)
|
||||
{
|
||||
// As the contact search is local, it can be updated on each text change
|
||||
[self updateSearch];
|
||||
if (![service isAddressListRestriction]) {
|
||||
// As the contact search is local, it can be updated on each text change
|
||||
[self updateSearch];
|
||||
}
|
||||
}
|
||||
else if (!self.searchBar.text.length)
|
||||
{
|
||||
|
||||
@@ -525,7 +525,9 @@
|
||||
|
||||
- (void)updateInviteButtonForRoom:(MXRoom *)room
|
||||
{
|
||||
if ((room.isDirect && !BwiBuildSettings.allowInviteOnDirectRooms) || room.isPersonalNotesRoom)
|
||||
AccountRestrictionService *service = [[AccountRestrictionService alloc] initWithMxSession:room.mxSession];
|
||||
|
||||
if ((room.isDirect && !BwiBuildSettings.allowInviteOnDirectRooms) || room.isPersonalNotesRoom || [service isAddressListRestriction])
|
||||
{
|
||||
// Remove invite members button if exists
|
||||
[self->inviteFabImageView removeFromSuperview];
|
||||
|
||||
@@ -132,6 +132,11 @@ final class ShowDirectoryViewModel: NSObject, ShowDirectoryViewModelType {
|
||||
return
|
||||
}
|
||||
|
||||
if AccountRestrictionService(mxSession: session).isRoomAccessRestriction() {
|
||||
self.update(viewState: .loadedWithoutUpdate)
|
||||
return
|
||||
}
|
||||
|
||||
self.update(viewState: .loading)
|
||||
|
||||
// Useful only when force is true
|
||||
|
||||
@@ -706,7 +706,11 @@
|
||||
|
||||
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
|
||||
{
|
||||
[contactsDataSource searchWithPattern:searchText forceReset:NO];
|
||||
AccountRestrictionService *service = [[AccountRestrictionService alloc] initWithMxSession:self.mainSession];
|
||||
|
||||
if(![service isAddressListRestriction]) {
|
||||
[contactsDataSource searchWithPattern:searchText forceReset:NO];
|
||||
}
|
||||
|
||||
self.contactsAreFilteredWithSearch = searchText.length ? YES : NO;
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ targets:
|
||||
sources:
|
||||
- path: .
|
||||
- path: ../bwi/AppConfig
|
||||
- path: ../bwi/ServerURLs
|
||||
- path: ../bwi/SecureStorage
|
||||
- path: ../bwi/BwiBuildSettings.swift
|
||||
- path: ../Config/BwiSettings.swift
|
||||
|
||||
@@ -38,6 +38,7 @@ targets:
|
||||
sources:
|
||||
- path: .
|
||||
- path: ../bwi/SecureStorage
|
||||
- path: ../bwi/ServerURLs
|
||||
- path: ../bwi/BwiBuildSettings.swift
|
||||
- path: ../Config/BwiSettings.swift
|
||||
- path: ../Riot/Modules/Common/SegmentedViewController/SegmentedViewController.m
|
||||
|
||||
29
bwi/AccountRestriction/AccountRestriction.swift
Normal file
29
bwi/AccountRestriction/AccountRestriction.swift
Normal file
@@ -0,0 +1,29 @@
|
||||
//
|
||||
/*
|
||||
* Copyright (c) 2022 BWI GmbH
|
||||
*
|
||||
* 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
|
||||
|
||||
struct AccountRestriction: Codable {
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case roomAccess = "can_access_room_directory"
|
||||
case addressListAccess = "can_access_address_book"
|
||||
}
|
||||
|
||||
let roomAccess: Bool
|
||||
let addressListAccess: Bool
|
||||
}
|
||||
69
bwi/AccountRestriction/AccountRestrictionService.swift
Normal file
69
bwi/AccountRestriction/AccountRestrictionService.swift
Normal file
@@ -0,0 +1,69 @@
|
||||
//
|
||||
/*
|
||||
* Copyright (c) 2022 BWI GmbH
|
||||
*
|
||||
* 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
|
||||
|
||||
@objcMembers class AccountRestrictionService : NSObject {
|
||||
|
||||
private enum AccountDataTypes {
|
||||
static let restrictions = "m.bwi.account_restrictions"
|
||||
}
|
||||
|
||||
let session: MXSession
|
||||
private lazy var serializationService: SerializationServiceType = SerializationService()
|
||||
|
||||
init(mxSession: MXSession) {
|
||||
self.session = mxSession
|
||||
}
|
||||
|
||||
func isRoomAccessRestriction() -> Bool {
|
||||
guard let restrictionsDict = session.accountData.accountData(forEventType: AccountDataTypes.restrictions) as? [String: Any] else {
|
||||
return false
|
||||
}
|
||||
do {
|
||||
let restriction: AccountRestriction = try serializationService.deserialize(restrictionsDict)
|
||||
|
||||
return restriction.roomAccess
|
||||
} catch {
|
||||
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func isAddressListRestriction() -> Bool {
|
||||
guard let restrictionsDict = session.accountData.accountData(forEventType: AccountDataTypes.restrictions) as? [String: Any] else {
|
||||
return false
|
||||
}
|
||||
do {
|
||||
let restriction: AccountRestriction = try serializationService.deserialize(restrictionsDict)
|
||||
|
||||
return restriction.addressListAccess
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func updateRestriction(roomAccess: Bool, addressListAccess: Bool) {
|
||||
var restrictionDict = session.accountData.accountData(forEventType: AccountDataTypes.restrictions) ?? [:]
|
||||
|
||||
restrictionDict[AccountRestriction.CodingKeys.roomAccess.rawValue] = roomAccess
|
||||
restrictionDict[AccountRestriction.CodingKeys.addressListAccess.rawValue] = addressListAccess
|
||||
|
||||
session.setAccountData(restrictionDict, forType: AccountDataTypes.restrictions, success: nil, failure: nil)
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,16 @@ struct DeveloperSettingsView: View {
|
||||
.alert(isPresented: $showAlert) {
|
||||
Alert(title: Text(NSLocalizedString("bwi_settings_developer", tableName: "Vector", comment: "")), message: Text(NSLocalizedString("bwi_settings_developer_show_matomo_privacy_notes_resetted", tableName: "Vector", comment: "")), dismissButton: .default(Text("Ok")))
|
||||
}
|
||||
Button(action: { _ = restrictUser(mxSession: session) }) {
|
||||
Text(NSLocalizedString("bwi_settings_developer_restrict_user", tableName: "Bwi", comment: ""))
|
||||
.foregroundColor(Color(ThemeService.shared().theme.tintColor))
|
||||
.font(.system(size: 17))
|
||||
}
|
||||
Button(action: { _ = unrestrictUser(mxSession: session) }) {
|
||||
Text(NSLocalizedString("bwi_settings_developer_unrestrict_user", tableName: "Bwi", comment: ""))
|
||||
.foregroundColor(Color(ThemeService.shared().theme.tintColor))
|
||||
.font(.system(size: 17))
|
||||
}
|
||||
}
|
||||
.navigationTitle(NSLocalizedString("bwi_settings_developer", tableName: "Vector", comment: ""))
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
@@ -82,3 +92,20 @@ fileprivate func resetMatomoInfoScreen() -> Bool {
|
||||
UserDefaults.standard.set(false, forKey: "bwi_matomo_info_screen_shown")
|
||||
return true
|
||||
}
|
||||
|
||||
fileprivate func restrictUser(mxSession: MXSession?) -> Bool {
|
||||
guard let mxSession = mxSession else {
|
||||
return false
|
||||
}
|
||||
AccountRestrictionService(mxSession: mxSession).updateRestriction(roomAccess: true, addressListAccess: true)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
fileprivate func unrestrictUser(mxSession: MXSession?) -> Bool {
|
||||
guard let mxSession = mxSession else {
|
||||
return false
|
||||
}
|
||||
AccountRestrictionService(mxSession: mxSession).updateRestriction(roomAccess: false, addressListAccess: false)
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -20,8 +20,10 @@ import Foundation
|
||||
@objcMembers class ServerURLHelper : NSObject {
|
||||
static let shared = ServerURLHelper()
|
||||
|
||||
private let settingsKey = "serverSettings"
|
||||
private let serverUrlKey = "serverURL"
|
||||
private let pusherUrlKey = "pusherURL"
|
||||
private let flavorUrlKey = "flavor"
|
||||
|
||||
var serverURLs = Array<ServerURLs>()
|
||||
|
||||
@@ -30,14 +32,12 @@ import Foundation
|
||||
do {
|
||||
let data = try Data(contentsOf: URL(fileURLWithPath: path), options: .mappedIfSafe)
|
||||
let jsonResult = try JSONSerialization.jsonObject(with: data, options: .mutableLeaves)
|
||||
if let jsonResult = jsonResult as? Dictionary<String, AnyObject>, let urls = jsonResult["serverURLs"] as? [Any] {
|
||||
if let jsonResult = jsonResult as? Dictionary<String, AnyObject>, let urls = jsonResult[settingsKey] as? [Any] {
|
||||
|
||||
for urlSet in urls {
|
||||
print("SERVERURL: ", urlSet)
|
||||
if let dict = urlSet as? Dictionary<String,String> {
|
||||
print("SERVERURL: ", dict)
|
||||
if let server = dict[serverUrlKey], let pusher = dict[pusherUrlKey] {
|
||||
serverURLs.append(ServerURLs(serverUrl: server, pusherUrl: pusher))
|
||||
if let server = dict[serverUrlKey], let pusher = dict[pusherUrlKey], let flavor = dict[flavorUrlKey] {
|
||||
serverURLs.append(ServerURLs(serverUrl: server, pusherUrl: pusher, flavor: flavor))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,4 +69,12 @@ import Foundation
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func flavor() -> String? {
|
||||
if serverURLs.count > 0 {
|
||||
return serverURLs[0].flavor
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,4 +20,5 @@ import Foundation
|
||||
struct ServerURLs {
|
||||
var serverUrl: String
|
||||
var pusherUrl: String
|
||||
var flavor: String
|
||||
}
|
||||
|
||||
@@ -66,7 +66,11 @@ import WebKit
|
||||
|
||||
var bwiUserAgent: String {
|
||||
|
||||
let flavor = BwiBuildSettings.flavor
|
||||
var flavor = BwiBuildSettings.flavor
|
||||
|
||||
if (ServerURLHelper.shared.flavor() != nil) {
|
||||
flavor = ServerURLHelper.shared.flavor()!
|
||||
}
|
||||
|
||||
guard let appName = Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName"),
|
||||
let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString"),
|
||||
|
||||
Reference in New Issue
Block a user