NCCapabilities.swift 4.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //
  2. // NCCapabilities.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 21/08/24.
  6. // Copyright © 2024 Marino Faggiana. All rights reserved.
  7. //
  8. //
  9. // NCSession.swift
  10. // Nextcloud
  11. //
  12. // Created by Marino Faggiana on 02/08/24.
  13. // Copyright © 2024 Marino Faggiana. All rights reserved.
  14. //
  15. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  16. //
  17. // This program is free software: you can redistribute it and/or modify
  18. // it under the terms of the GNU General Public License as published by
  19. // the Free Software Foundation, either version 3 of the License, or
  20. // (at your option) any later version.
  21. //
  22. // This program is distributed in the hope that it will be useful,
  23. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. // GNU General Public License for more details.
  26. //
  27. // You should have received a copy of the GNU General Public License
  28. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  29. //
  30. import Foundation
  31. import UIKit
  32. public class NCCapabilities: NSObject {
  33. static let shared = NCCapabilities()
  34. public class Capabilities {
  35. var capabilityServerVersionMajor: Int = 0
  36. var capabilityServerVersion: String = ""
  37. var capabilityFileSharingApiEnabled: Bool = false
  38. var capabilityFileSharingPubPasswdEnforced: Bool = false
  39. var capabilityFileSharingPubExpireDateEnforced: Bool = false
  40. var capabilityFileSharingPubExpireDateDays: Int = 0
  41. var capabilityFileSharingInternalExpireDateEnforced: Bool = false
  42. var capabilityFileSharingInternalExpireDateDays: Int = 0
  43. var capabilityFileSharingRemoteExpireDateEnforced: Bool = false
  44. var capabilityFileSharingRemoteExpireDateDays: Int = 0
  45. var capabilityFileSharingDefaultPermission: Int = 0
  46. var capabilityThemingColor: String = ""
  47. var capabilityThemingColorElement: String = ""
  48. var capabilityThemingColorText: String = ""
  49. var capabilityThemingName: String = ""
  50. var capabilityThemingSlogan: String = ""
  51. var capabilityE2EEEnabled: Bool = false
  52. var capabilityE2EEApiVersion: String = ""
  53. var capabilityRichDocumentsEnabled: Bool = false
  54. var capabilityRichDocumentsMimetypes = ThreadSafeArray<String>()
  55. var capabilityActivity = ThreadSafeArray<String>()
  56. var capabilityNotification = ThreadSafeArray<String>()
  57. var capabilityFilesUndelete: Bool = false
  58. var capabilityFilesLockVersion: String = "" // NC 24
  59. var capabilityFilesComments: Bool = false // NC 20
  60. var capabilityFilesBigfilechunking: Bool = false
  61. var capabilityUserStatusEnabled: Bool = false
  62. var capabilityExternalSites: Bool = false
  63. var capabilityGroupfoldersEnabled: Bool = false // NC27
  64. var capabilityAssistantEnabled: Bool = false // NC28
  65. var isLivePhotoServerAvailable: Bool = false // NC28
  66. var capabilitySecurityGuardDiagnostics = false
  67. var capabilityForbiddenFileNames: [String] = []
  68. var capabilityForbiddenFileNameBasenames: [String] = []
  69. var capabilityForbiddenFileNameCharacters: [String] = []
  70. var capabilityForbiddenFileNameExtensions: [String] = []
  71. }
  72. private var capabilities = ThreadSafeDictionary<String, Capabilities>()
  73. override private init() {}
  74. func disableSharesView(account: String) -> Bool {
  75. guard let capability = capabilities[account] else {
  76. return true
  77. }
  78. return (!capability.capabilityFileSharingApiEnabled && !capability.capabilityFilesComments && capability.capabilityActivity.isEmpty)
  79. }
  80. func getCapabilities(account: String?) -> Capabilities {
  81. if let account, let capability = capabilities[account] {
  82. return capability
  83. }
  84. return Capabilities()
  85. }
  86. func appendCapabilities(account: String, capabilities: Capabilities) {
  87. self.capabilities[account] = capabilities
  88. }
  89. }