cascade null to sites on folder delete

This commit is contained in:
Kyle Spearrin 2016-07-31 00:19:12 -04:00
parent cf8ee2273a
commit d0fa6841c3
5 changed files with 23 additions and 4 deletions

View file

@ -8,5 +8,6 @@ namespace Bit.App.Abstractions
public interface IFolderRepository : IRepository<FolderData, string> public interface IFolderRepository : IRepository<FolderData, string>
{ {
Task<IEnumerable<FolderData>> GetAllByUserIdAsync(string userId); Task<IEnumerable<FolderData>> GetAllByUserIdAsync(string userId);
Task DeleteWithSiteUpdateAsync(string id, DateTime revisionDate);
} }
} }

View file

@ -7,7 +7,7 @@ namespace Bit.App.Abstractions
{ {
bool SyncInProgress { get; } bool SyncInProgress { get; }
Task<bool> SyncAsync(string id); Task<bool> SyncAsync(string id);
Task<bool> SyncDeleteFolderAsync(string id); Task<bool> SyncDeleteFolderAsync(string id, DateTime revisionDate);
Task<bool> SyncDeleteSiteAsync(string id); Task<bool> SyncDeleteSiteAsync(string id);
Task<bool> FullSyncAsync(); Task<bool> FullSyncAsync();
Task<bool> IncrementalSyncAsync(TimeSpan syncThreshold); Task<bool> IncrementalSyncAsync(TimeSpan syncThreshold);

View file

@ -18,5 +18,23 @@ namespace Bit.App.Repositories
var folders = Connection.Table<FolderData>().Where(f => f.UserId == userId).Cast<FolderData>(); var folders = Connection.Table<FolderData>().Where(f => f.UserId == userId).Cast<FolderData>();
return Task.FromResult(folders); return Task.FromResult(folders);
} }
public override Task DeleteAsync(string id)
{
var now = DateTime.UtcNow;
DeleteWithSiteUpdateAsync(id, now);
return Task.FromResult(0);
}
public Task DeleteWithSiteUpdateAsync(string id, DateTime revisionDate)
{
Connection.RunInTransaction(() =>
{
Connection.Execute("UPDATE Site SET FolderId = ?, RevisionDateTime = ? WHERE FolderId = ?", null, revisionDate, id);
Connection.Delete<FolderData>(id);
});
return Task.FromResult(0);
}
} }
} }

View file

@ -59,7 +59,7 @@ namespace Bit.App.Services
break; break;
case Enums.PushType.SyncFolderDelete: case Enums.PushType.SyncFolderDelete:
var folderDeleteMessage = values.ToObject<SyncCipherPushNotification>(); var folderDeleteMessage = values.ToObject<SyncCipherPushNotification>();
_syncService.SyncDeleteFolderAsync(folderDeleteMessage.Id); _syncService.SyncDeleteFolderAsync(folderDeleteMessage.Id, folderDeleteMessage.RevisionDate);
break; break;
case Enums.PushType.SyncSiteDelete: case Enums.PushType.SyncSiteDelete:
var siteDeleteMessage = values.ToObject<SyncCipherPushNotification>(); var siteDeleteMessage = values.ToObject<SyncCipherPushNotification>();

View file

@ -98,7 +98,7 @@ namespace Bit.App.Services
return true; return true;
} }
public async Task<bool> SyncDeleteFolderAsync(string id) public async Task<bool> SyncDeleteFolderAsync(string id, DateTime revisionDate)
{ {
if(!_authService.IsAuthenticated) if(!_authService.IsAuthenticated)
{ {
@ -107,7 +107,7 @@ namespace Bit.App.Services
SyncStarted(); SyncStarted();
await _folderRepository.DeleteAsync(id); await _folderRepository.DeleteWithSiteUpdateAsync(id, revisionDate);
SyncCompleted(true); SyncCompleted(true);
return true; return true;
} }