|
|
|
|
@ -48,7 +48,7 @@ public class StoreCenter { |
|
|
|
|
lazy fileprivate var _deleteLogs: StoredCollection<DataLog> = { self.mainStore.registerCollection() }() |
|
|
|
|
|
|
|
|
|
/// A synchronized collection of DataAccess |
|
|
|
|
fileprivate var _dataAccess: SyncedCollection<DataAccess>? = nil |
|
|
|
|
fileprivate(set) var dataAccessCollection: SyncedCollection<DataAccess>? = nil |
|
|
|
|
|
|
|
|
|
/// A collection storing FailedAPICall objects |
|
|
|
|
fileprivate var _failedAPICallsCollection: SyncedCollection<FailedAPICall>? = nil |
|
|
|
|
@ -101,7 +101,7 @@ public class StoreCenter { |
|
|
|
|
self.tokenKeychain = KeychainStore(serverId: urlManager.api) |
|
|
|
|
|
|
|
|
|
if self.useSynchronization { |
|
|
|
|
self._dataAccess = self.mainStore.registerSynchronizedCollection() |
|
|
|
|
self.dataAccessCollection = self.mainStore.registerSynchronizedCollection() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Logger.log("Sync URL: \(urlManager.api)") |
|
|
|
|
@ -250,7 +250,7 @@ public class StoreCenter { |
|
|
|
|
self._failedAPICallsCollection?.reset() |
|
|
|
|
|
|
|
|
|
self._stores.removeAll() |
|
|
|
|
self._dataAccess?.reset() |
|
|
|
|
self.dataAccessCollection?.reset() |
|
|
|
|
self._deleteLogs.reset() |
|
|
|
|
|
|
|
|
|
self._settingsStorage.update { settings in |
|
|
|
|
@ -557,7 +557,7 @@ public class StoreCenter { |
|
|
|
|
if self.useSynchronization { |
|
|
|
|
Task { |
|
|
|
|
do { |
|
|
|
|
try await self.service().getUserDataAccess() |
|
|
|
|
try await self.service().getUserDataAccessContent() |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
@ -637,8 +637,8 @@ public class StoreCenter { |
|
|
|
|
await self._syncDelete(syncData.deletions) |
|
|
|
|
self._syncAddOrUpdate(syncData.grants, shared: true) |
|
|
|
|
await self.syncRevoke(syncData.revocations, parents: syncData.revocationParents) |
|
|
|
|
self._syncAddOrUpdate(syncData.relationshipSets) |
|
|
|
|
await self._syncDelete(syncData.relationshipRemovals) |
|
|
|
|
// self._syncAddOrUpdate(syncData.relationshipSets) |
|
|
|
|
// await self._syncDelete(syncData.relationshipRemovals) |
|
|
|
|
self._syncAddOrUpdate(syncData.sharedRelationshipSets, shared: true) |
|
|
|
|
self._syncRevoke(syncData.sharedRelationshipRemovals) |
|
|
|
|
|
|
|
|
|
@ -1020,7 +1020,7 @@ public class StoreCenter { |
|
|
|
|
|
|
|
|
|
/// Returns the list of users have access to a data given its id |
|
|
|
|
public func authorizedUsers(for modelId: String) -> [String] { |
|
|
|
|
guard let dataAccessCollection = self._dataAccess else { |
|
|
|
|
guard let dataAccessCollection = self.dataAccessCollection else { |
|
|
|
|
return [] |
|
|
|
|
} |
|
|
|
|
if let dataAccess = dataAccessCollection.first(where: { $0.modelId == modelId }) { |
|
|
|
|
@ -1031,7 +1031,7 @@ public class StoreCenter { |
|
|
|
|
|
|
|
|
|
public func setAuthorizedUsersAsync<T: SyncedStorable>(for instance: T, users: [String]) async throws { |
|
|
|
|
|
|
|
|
|
guard let dataAccessCollection = self._dataAccess else { |
|
|
|
|
guard let dataAccessCollection = self.dataAccessCollection else { |
|
|
|
|
throw StoreError.synchronizationInactive |
|
|
|
|
} |
|
|
|
|
guard let userId = self.userId else { |
|
|
|
|
@ -1040,15 +1040,15 @@ public class StoreCenter { |
|
|
|
|
|
|
|
|
|
if let dataAccess = dataAccessCollection.first(where: { $0.modelId == instance.stringId }) { |
|
|
|
|
if users.isEmpty { |
|
|
|
|
await dataAccessCollection.deleteAsync(instance: dataAccess) |
|
|
|
|
try await dataAccessCollection.deleteAsync(instance: dataAccess) |
|
|
|
|
} else { |
|
|
|
|
dataAccess.sharedWith.removeAll() |
|
|
|
|
dataAccess.sharedWith = users |
|
|
|
|
await dataAccessCollection.addOrUpdateAsync(instance: dataAccess) |
|
|
|
|
try await dataAccessCollection.addOrUpdateAsync(instance: dataAccess) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
let dataAccess = DataAccess(owner: userId, sharedWith: users, modelName: String(describing: type(of: instance)), modelId: instance.stringId) |
|
|
|
|
await dataAccessCollection.addOrUpdateAsync(instance: dataAccess) |
|
|
|
|
try await dataAccessCollection.addOrUpdateAsync(instance: dataAccess) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|