1
0
mirror of https://github.com/bitwarden/directory-connector synced 2025-12-18 17:23:27 +00:00

restore deltas when sync is not sent to server

This commit is contained in:
Kyle Spearrin
2017-05-16 17:06:12 -04:00
parent 98b2b8aa33
commit 23d3300c4f
2 changed files with 21 additions and 4 deletions

View File

@@ -29,12 +29,12 @@ namespace Bit.Core.Models
public byte[] Decrypt()
{
return ProtectedData.Unprotect(Value, IV, DataProtectionScope.CurrentUser);
return ProtectedData.Unprotect(Value, IV, DataProtectionScope.LocalMachine);
}
public string DecryptToString()
{
var bytes = ProtectedData.Unprotect(Value, IV, DataProtectionScope.CurrentUser);
var bytes = ProtectedData.Unprotect(Value, IV, DataProtectionScope.LocalMachine);
return Encoding.UTF8.GetString(bytes);
}

View File

@@ -11,6 +11,9 @@ namespace Bit.Core.Utilities
{
public static async Task<SyncResult> SyncAllAsync(bool force = false, bool sendToServer = true)
{
var startingGroupDelta = SettingsService.Instance.GroupDeltaToken;
var startingUserDelta = SettingsService.Instance.UserDeltaToken;
try
{
var now = DateTime.UtcNow;
@@ -20,8 +23,9 @@ namespace Bit.Core.Utilities
FlattenUsersToGroups(groups, null, groups, users);
if(!sendToServer)
if(!sendToServer || (groups.Count == 0 && users.Count == 0))
{
RestoreDeltas(startingGroupDelta, startingUserDelta);
return new SyncResult
{
Success = true,
@@ -53,6 +57,7 @@ namespace Bit.Core.Utilities
}
else
{
RestoreDeltas(startingGroupDelta, startingUserDelta);
return new SyncResult
{
Success = false,
@@ -60,14 +65,20 @@ namespace Bit.Core.Utilities
};
}
}
catch (ApplicationException e)
catch(ApplicationException e)
{
RestoreDeltas(startingGroupDelta, startingUserDelta);
return new SyncResult
{
Success = false,
ErrorMessage = e.Message
};
}
catch
{
RestoreDeltas(startingGroupDelta, startingUserDelta);
throw;
}
}
private static IDirectoryService GetDirectoryService()
@@ -114,5 +125,11 @@ namespace Bit.Core.Utilities
FlattenUsersToGroups(groupsInThisGroup, usersInThisGroup, allGroups, allUsers);
}
}
private static void RestoreDeltas(string groupDelta, string userDelta)
{
SettingsService.Instance.GroupDeltaToken = groupDelta;
SettingsService.Instance.UserDeltaToken = userDelta;
}
}
}