diff --git a/iOSClient/Account Settings/NCAccountSettingsModel.swift b/iOSClient/Account Settings/NCAccountSettingsModel.swift index 08fa601180..4cdc26f904 100644 --- a/iOSClient/Account Settings/NCAccountSettingsModel.swift +++ b/iOSClient/Account Settings/NCAccountSettingsModel.swift @@ -140,6 +140,13 @@ class NCAccountSettingsModel: ObservableObject, ViewOnAppearHandling { return (nil, "", "") } + /// Is the user an Admin + func isAdminGroup() -> Bool { + guard let activeAccount else { return false } + let groups = NCManageDatabase.shared.getAccountGroups(account: activeAccount.account) + return groups.contains(NCGlobal.shared.groupAdmin) + } + /// Function to know the height of "account" data func getTableViewHeight() -> CGFloat { guard let activeAccount else { return 0 } diff --git a/iOSClient/Account Settings/NCAccountSettingsView.swift b/iOSClient/Account Settings/NCAccountSettingsView.swift index c8a9e500c7..74480985df 100644 --- a/iOSClient/Account Settings/NCAccountSettingsView.swift +++ b/iOSClient/Account Settings/NCAccountSettingsView.swift @@ -181,52 +181,54 @@ struct NCAccountSettingsView: View { } /// /// Certificate server - Button(action: { - showServerCertificate.toggle() - }, label: { - HStack { - Image(systemName: "lock") - .resizable() - .scaledToFit() - .font(Font.system(.body).weight(.light)) - .frame(width: 20, height: 20) - .foregroundStyle(Color(NCBrandColor.shared.iconImageColor)) - Text(NSLocalizedString("_certificate_details_", comment: "")) - .lineLimit(1) - .truncationMode(.middle) - .foregroundStyle(Color(NCBrandColor.shared.textColor)) - .padding(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 20)) - } - .font(.system(size: 14)) - }) - .sheet(isPresented: $showServerCertificate) { - if let url = URL(string: model.activeAccount?.urlBase), let host = url.host { - certificateDetailsView(host: host, title: NSLocalizedString("_certificate_view_", comment: "")) - } - } - /// - /// Certificate push - Button(action: { - showPushCertificate.toggle() - }, label: { - HStack { - Image(systemName: "lock") - .resizable() - .scaledToFit() - .font(Font.system(.body).weight(.light)) - .frame(width: 20, height: 20) - .foregroundStyle(Color(NCBrandColor.shared.iconImageColor)) - Text(NSLocalizedString("_certificate_pn_details_", comment: "")) - .lineLimit(1) - .truncationMode(.middle) - .foregroundStyle(Color(NCBrandColor.shared.textColor)) - .padding(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 20)) + if model.isAdminGroup() { + Button(action: { + showServerCertificate.toggle() + }, label: { + HStack { + Image(systemName: "lock") + .resizable() + .scaledToFit() + .font(Font.system(.body).weight(.light)) + .frame(width: 20, height: 20) + .foregroundStyle(Color(NCBrandColor.shared.iconImageColor)) + Text(NSLocalizedString("_certificate_details_", comment: "")) + .lineLimit(1) + .truncationMode(.middle) + .foregroundStyle(Color(NCBrandColor.shared.textColor)) + .padding(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 20)) + } + .font(.system(size: 14)) + }) + .sheet(isPresented: $showServerCertificate) { + if let url = URL(string: model.activeAccount?.urlBase), let host = url.host { + certificateDetailsView(host: host, title: NSLocalizedString("_certificate_view_", comment: "")) + } } - .font(.system(size: 14)) - }) - .sheet(isPresented: $showPushCertificate) { - if let url = URL(string: NCBrandOptions.shared.pushNotificationServerProxy), let host = url.host { - certificateDetailsView(host: host, title: NSLocalizedString("_certificate_pn_view_", comment: "")) + /// + /// Certificate push + Button(action: { + showPushCertificate.toggle() + }, label: { + HStack { + Image(systemName: "lock") + .resizable() + .scaledToFit() + .font(Font.system(.body).weight(.light)) + .frame(width: 20, height: 20) + .foregroundStyle(Color(NCBrandColor.shared.iconImageColor)) + Text(NSLocalizedString("_certificate_pn_details_", comment: "")) + .lineLimit(1) + .truncationMode(.middle) + .foregroundStyle(Color(NCBrandColor.shared.textColor)) + .padding(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 20)) + } + .font(.system(size: 14)) + }) + .sheet(isPresented: $showPushCertificate) { + if let url = URL(string: NCBrandOptions.shared.pushNotificationServerProxy), let host = url.host { + certificateDetailsView(host: host, title: NSLocalizedString("_certificate_pn_view_", comment: "")) + } } } }) diff --git a/iOSClient/Data/NCManageDatabase+Account.swift b/iOSClient/Data/NCManageDatabase+Account.swift index 567b60dfc0..91038bee94 100644 --- a/iOSClient/Data/NCManageDatabase+Account.swift +++ b/iOSClient/Data/NCManageDatabase+Account.swift @@ -407,4 +407,16 @@ extension NCManageDatabase { NextcloudKit.shared.nkCommonInstance.writeLog("[ERROR] Could not write to database: \(error)") } } + + func getAccountGroups(account: String) -> [String] { + do { + let realm = try Realm() + if let result = realm.objects(tableAccount.self).filter("account == %@", account).first { + return result.groups.components(separatedBy: ",") + } + } catch let error as NSError { + NextcloudKit.shared.nkCommonInstance.writeLog("[ERROR] Could not access database: \(error)") + } + return [] + } } diff --git a/iOSClient/NCGlobal.swift b/iOSClient/NCGlobal.swift index f5b8b12e32..f3b43df76e 100644 --- a/iOSClient/NCGlobal.swift +++ b/iOSClient/NCGlobal.swift @@ -485,4 +485,8 @@ class NCGlobal: NSObject { // DRAG & DROP // let metadataOcIdDataRepresentation = "text/com.nextcloud.ocId" + + // GROUP AMIN + // + let groupAdmin = "admin" } diff --git a/iOSClient/Settings/Advanced/NCSettingsAdvancedModel.swift b/iOSClient/Settings/Advanced/NCSettingsAdvancedModel.swift index 233cb1db94..8c8ca47fc6 100644 --- a/iOSClient/Settings/Advanced/NCSettingsAdvancedModel.swift +++ b/iOSClient/Settings/Advanced/NCSettingsAdvancedModel.swift @@ -33,6 +33,8 @@ class NCSettingsAdvancedModel: ObservableObject, ViewOnAppearHandling { let appDelegate = (UIApplication.shared.delegate as? AppDelegate)! /// Keychain access var keychain = NCKeychain() + /// State variable for indicating if the user is in Admin group + @Published var isAdminGroup: Bool = false /// State variable for indicating whether hidden files are shown. @Published var showHiddenFiles: Bool = false /// State variable for indicating the most compatible format. @@ -65,6 +67,8 @@ class NCSettingsAdvancedModel: ObservableObject, ViewOnAppearHandling { /// Triggered when the view appears. func onViewAppear() { + let groups = NCManageDatabase.shared.getAccountGroups(account: appDelegate.account) + isAdminGroup = groups.contains(NCGlobal.shared.groupAdmin) showHiddenFiles = keychain.showHiddenFiles mostCompatible = keychain.formatCompatibility livePhoto = keychain.livePhoto @@ -73,6 +77,7 @@ class NCSettingsAdvancedModel: ObservableObject, ViewOnAppearHandling { crashReporter = keychain.disableCrashservice selectedLogLevel = LogLevel(rawValue: keychain.logLevel) ?? .standard selectedInterval = CacheDeletionInterval(rawValue: keychain.cleanUpDay) ?? .never + DispatchQueue.global().async { self.calculateSize() } diff --git a/iOSClient/Settings/Advanced/NCSettingsAdvancedView.swift b/iOSClient/Settings/Advanced/NCSettingsAdvancedView.swift index 45fcf06880..6dfc43b6f6 100644 --- a/iOSClient/Settings/Advanced/NCSettingsAdvancedView.swift +++ b/iOSClient/Settings/Advanced/NCSettingsAdvancedView.swift @@ -182,26 +182,28 @@ struct NCSettingsAdvancedView: View { Text(NSLocalizedString("_diagnostics_", comment: "")) }, footer: { }) /// Set Log Level() & Capabilities - Section(content: { - NavigationLink(destination: LazyView { - NCCapabilitiesView(model: NCCapabilitiesModel()) - }) { - HStack { - Image(systemName: "list.bullet") - .resizable() - .scaledToFit() - .font(Font.system(.body).weight(.light)) - .frame(width: 25, height: 25) - .foregroundColor(Color(NCBrandColor.shared.iconImageColor)) - Text(NSLocalizedString("_capabilities_", comment: "")) + if model.isAdminGroup { + Section(content: { + NavigationLink(destination: LazyView { + NCCapabilitiesView(model: NCCapabilitiesModel()) + }) { + HStack { + Image(systemName: "list.bullet") + .resizable() + .scaledToFit() + .font(Font.system(.body).weight(.light)) + .frame(width: 25, height: 25) + .foregroundColor(Color(NCBrandColor.shared.iconImageColor)) + Text(NSLocalizedString("_capabilities_", comment: "")) + } + .font(.system(size: 16)) } - .font(.system(size: 16)) - } - }, header: { - Text(NSLocalizedString("_capabilities_", comment: "")) - }, footer: { - Text(NSLocalizedString("_capabilities_footer_", comment: "")) - }) + }, header: { + Text(NSLocalizedString("_capabilities_", comment: "")) + }, footer: { + Text(NSLocalizedString("_capabilities_footer_", comment: "")) + }) + } } /// Delete in Cache & Clear Cache Section(content: {