|
|
|
|
@ -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) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|