Browse Source

change getUserProfile

marinofaggiana 4 years ago
parent
commit
bbca39511b

+ 1 - 1
Cartfile.resolved

@@ -16,7 +16,7 @@ github "krzyzanowskim/OpenSSL" "1.0.218"
 github "malcommac/SwiftRichString" "3.7.1"
 github "marinofaggiana/AFNetworking" "2967678c3e0e98c9b8d7e06222ad12d1f49c26f2"
 github "marinofaggiana/KTVHTTPCache" "2.0.2"
-github "nextcloud/ios-communication-library" "29dd07d6c8cb8c8d551683160c663def50d17143"
+github "nextcloud/ios-communication-library" "821b7ca280fbb8ef2b6158dd4fc8de10e2e3edcf"
 github "realm/realm-cocoa" "v4.4.1"
 github "rechsteiner/Parchment" "v1.7.0"
 github "scenee/FloatingPanel" "v1.7.4"

+ 1 - 1
iOSClient/CCGlobal.h

@@ -84,7 +84,7 @@
 
 // Database Realm
 #define k_databaseDefault                               @"nextcloud.realm"
-#define k_databaseSchemaVersion                         96
+#define k_databaseSchemaVersion                         97
 
 // Intro selector
 #define k_intro_login                                   0

+ 9 - 0
iOSClient/Database/NCDatabase.swift

@@ -38,6 +38,9 @@ class tableAccount: Object {
     @objc dynamic var autoUploadVideo: Bool = false
     @objc dynamic var autoUploadWWAnPhoto: Bool = false
     @objc dynamic var autoUploadWWAnVideo: Bool = false
+    @objc dynamic var backend = ""
+    @objc dynamic var backendCapabilitiesSetDisplayName: Bool = false
+    @objc dynamic var backendCapabilitiesSetPassword: Bool = false
     @objc dynamic var businessSize: String = ""
     @objc dynamic var businessType = ""
     @objc dynamic var dateSearchContentTypeImageVideo = NSDate.distantPast
@@ -47,6 +50,10 @@ class tableAccount: Object {
     @objc dynamic var displayName = ""
     @objc dynamic var email = ""
     @objc dynamic var enabled: Bool = false
+    @objc dynamic var groups = ""
+    @objc dynamic var language = ""
+    @objc dynamic var lastLogin: Double = 0
+    @objc dynamic var locale = ""
     @objc dynamic var optimization = NSDate()
     @objc dynamic var password = ""
     @objc dynamic var phone = ""
@@ -57,6 +64,8 @@ class tableAccount: Object {
     @objc dynamic var quotaUsed: Double = 0
     @objc dynamic var role = ""
     @objc dynamic var startDirectoryPhotosTab = ""
+    @objc dynamic var storageLocation = ""
+    @objc dynamic var subadmin = ""
     @objc dynamic var twitter = ""
     @objc dynamic var url = ""
     @objc dynamic var user = ""

+ 48 - 24
iOSClient/Database/NCManageDatabase.swift

@@ -548,8 +548,7 @@ class NCManageDatabase: NSObject {
         }
     }
     
-    #if !EXTENSION
-    @objc func setAccountUserProfile(_ userProfile: OCUserProfile, HCProperties: Bool) -> tableAccount? {
+    @objc func setAccountUserProfile(_ userProfile: NCUserProfile) -> tableAccount? {
      
         let realm = try! Realm()
 
@@ -566,36 +565,62 @@ class NCManageDatabase: NSObject {
                     return
                 }
                 
-                // Update userID
-                if userProfile.id.count == 0 { // for old config.
-                    result.userID = result.user
-                } else {
-                    result.userID = userProfile.id
-                }
-                
-                result.enabled = userProfile.enabled
                 result.address = userProfile.address
+                result.backend = userProfile.backend
+                result.backendCapabilitiesSetDisplayName = userProfile.backendCapabilitiesSetDisplayName
+                result.backendCapabilitiesSetPassword = userProfile.backendCapabilitiesSetPassword
                 result.displayName = userProfile.displayName
                 result.email = userProfile.email
+                result.enabled = userProfile.enabled
+                result.groups = userProfile.groups.joined(separator: ",")
+                result.language = userProfile.language
+                result.lastLogin = userProfile.lastLogin
+                result.locale = userProfile.locale
                 result.phone = userProfile.phone
-                result.twitter = userProfile.twitter
-                result.webpage = userProfile.webpage
-                
-                if HCProperties {
-                    result.businessSize = userProfile.businessSize
-                    result.businessType = userProfile.businessType
-                    result.city = userProfile.city
-                    result.country = userProfile.country
-                    result.company = userProfile.company
-                    result.role = userProfile.role
-                    result.zip = userProfile.zip
-                }
-                
                 result.quota = userProfile.quota
                 result.quotaFree = userProfile.quotaFree
                 result.quotaRelative = userProfile.quotaRelative
                 result.quotaTotal = userProfile.quotaTotal
                 result.quotaUsed = userProfile.quotaUsed
+                result.storageLocation = userProfile.storageLocation
+                result.subadmin = userProfile.subadmin.joined(separator: ",")
+                result.twitter = userProfile.twitter
+                result.userID = userProfile.userID
+                result.webpage = userProfile.webpage
+                
+                returnAccount = result
+            }
+        } catch let error {
+            print("[LOG] Could not write to database: ", error)
+        }
+        
+        return tableAccount.init(value: returnAccount)
+    }
+    
+    @objc func setAccountUserProfileHWC(businessSize: String, businessType: String, city: String, company: String, country: String, role: String, zip: String) -> tableAccount? {
+     
+        let realm = try! Realm()
+
+        var returnAccount = tableAccount()
+
+        do {
+            guard let activeAccount = self.getAccountActive() else {
+                return nil
+            }
+            
+            try realm.write {
+                
+                guard let result = realm.objects(tableAccount.self).filter("account == %@", activeAccount.account).first else {
+                    return
+                }
+                
+                result.businessSize = businessSize
+                result.businessType = businessType
+                result.city = city
+                result.company = company
+                result.country = country
+                result.role = role
+                result.zip = zip
                 
                 returnAccount = result
             }
@@ -605,7 +630,6 @@ class NCManageDatabase: NSObject {
         
         return tableAccount.init(value: returnAccount)
     }
-    #endif
     
     #if !EXTENSION
     @objc func setAccountHCFeatures(_ features: HCFeatures) -> tableAccount? {

+ 6 - 6
iOSClient/Networking/NCService.swift

@@ -55,12 +55,12 @@ class NCService: NSObject {
             return
         }
         
-        OCNetworking.sharedManager().getUserProfile(withAccount: appDelegate.activeAccount, completion: { (account, userProfile, message, errorCode) in
-            
+        NCCommunication.sharedInstance.getUserProfile(serverUrl: appDelegate.activeUrl, customUserAgent: nil, addCustomHeaders: nil, account: appDelegate.activeAccount) { (account, userProfile, errorCode, errorDescription) in
+                 
             if errorCode == 0 && account == self.appDelegate.activeAccount {
                 
                 // Update User (+ userProfile.id) & active account & account network
-                guard let tableAccount = NCManageDatabase.sharedInstance.setAccountUserProfile(userProfile!, HCProperties: false) else {
+                guard let tableAccount = NCManageDatabase.sharedInstance.setAccountUserProfile(userProfile!) else {
                     NCContentPresenter.shared.messageNotification("Accopunt", description: "Internal error : account not found on DB",  delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: Int(k_CCErrorInternalError))
                     return
                 }
@@ -119,7 +119,7 @@ class NCService: NSObject {
                 
                 print("[LOG] It has been changed user during networking process, error.")
             }
-        })
+        }
     }
     
     private func requestServerStatus() {
@@ -346,7 +346,7 @@ class NCService: NSObject {
                     CCUtility.setHCBusinessType(nil)
                     OCNetworking.sharedManager()?.getHCUserProfile(withAccount: self.appDelegate.activeAccount, serverUrl: self.appDelegate.activeUrl, completion: { (account, userProfile, message, errorCode) in
                         if errorCode == 0 && account == self.appDelegate.activeAccount {
-                            _ = NCManageDatabase.sharedInstance.setAccountUserProfile(userProfile!, HCProperties: true)
+                            _ = NCManageDatabase.sharedInstance.setAccountUserProfileHWC(businessSize: userProfile!.businessSize, businessType: userProfile!.businessType, city: userProfile!.city, company: userProfile!.company, country: userProfile!.country, role: userProfile!.role, zip: userProfile!.zip)
                         }
                     })
                 }
@@ -354,7 +354,7 @@ class NCService: NSObject {
         } else {
             OCNetworking.sharedManager()?.getHCUserProfile(withAccount: appDelegate.activeAccount, serverUrl: appDelegate.activeUrl, completion: { (account, userProfile, message, errorCode) in
                 if errorCode == 0 && account == self.appDelegate.activeAccount {
-                    _ = NCManageDatabase.sharedInstance.setAccountUserProfile(userProfile!, HCProperties: true)
+                    _ = NCManageDatabase.sharedInstance.setAccountUserProfileHWC(businessSize: userProfile!.businessSize, businessType: userProfile!.businessType, city: userProfile!.city, company: userProfile!.company, country: userProfile!.country, role: userProfile!.role, zip: userProfile!.zip)
                 }
             })
         }