testing changes

sync3
Laurent 6 months ago
parent 9c5ddf30fa
commit a3680f14bd
  1. 10
      LeStorage/Codables/GetSyncData.swift
  2. 1
      LeStorage/Codables/Log.swift
  3. 24
      LeStorage/StoreCenter.swift

@ -10,13 +10,19 @@ import Foundation
class GetSyncData: SyncedModelObject, SyncedStorable, URLParameterConvertible {
var date: String = ""
enum CodingKeys: String, CodingKey {
case date
}
override required init() {
super.init()
}
required public init(from decoder: Decoder) throws {
fatalError("init(from:) has not been implemented")
let container = try decoder.container(keyedBy: CodingKeys.self)
date = try container.decode(String.self, forKey: .date)
try super.init(from: decoder)
}
static func tokenExemptedMethods() -> [HTTPMethod] { return [] }

@ -30,6 +30,7 @@ class Log: SyncedModelObject, SyncedStorable {
}
// MARK: - Codable
enum CodingKeys: String, CodingKey {
case id
case date

@ -640,6 +640,8 @@ public class StoreCenter {
self._syncAddOrUpdate(syncData.sharedRelationshipSets)
self._syncRevoke(syncData.sharedRelationshipRemovals)
Logger.log("sync content: updates = \(syncData.updates.count) / deletions = \(syncData.deletions.count), grants = \(syncData.grants.count)")
if let dateString = syncData.date {
Logger.log("Sets sync date = \(dateString)")
self._settingsStorage.update { settings in
@ -1028,8 +1030,8 @@ public class StoreCenter {
return []
}
/// Sets the the list of authorized users for an instance
public func setAuthorizedUsers<T: SyncedStorable>(for instance: T, users: [String]) throws {
public func setAuthorizedUsersAsync<T: SyncedStorable>(for instance: T, users: [String]) async throws {
guard let dataAccessCollection = self._dataAccess else {
return
}
@ -1039,15 +1041,27 @@ public class StoreCenter {
if let dataAccess = dataAccessCollection.first(where: { $0.modelId == instance.stringId }) {
if users.isEmpty {
dataAccessCollection.delete(instance: dataAccess)
await dataAccessCollection.deleteAsync(instance: dataAccess)
} else {
dataAccess.sharedWith.removeAll()
dataAccess.sharedWith = users
dataAccessCollection.addOrUpdate(instance: dataAccess)
await dataAccessCollection.addOrUpdateAsync(instance: dataAccess)
}
} else {
let dataAccess = DataAccess(owner: userId, sharedWith: users, modelName: String(describing: type(of: instance)), modelId: instance.stringId)
dataAccessCollection.addOrUpdate(instance: dataAccess)
await dataAccessCollection.addOrUpdateAsync(instance: dataAccess)
}
}
/// Sets the the list of authorized users for an instance
public func setAuthorizedUsers<T: SyncedStorable>(for instance: T, users: [String]) throws {
Task {
do {
try await self.setAuthorizedUsersAsync(for: instance, users: users)
} catch {
Logger.error(error)
}
}
}

Loading…
Cancel
Save