mirror of
https://github.com/bitwarden/directory-connector
synced 2025-12-18 09:13:28 +00:00
restore deltas when sync is not sent to server
This commit is contained in:
@@ -29,12 +29,12 @@ namespace Bit.Core.Models
|
|||||||
|
|
||||||
public byte[] Decrypt()
|
public byte[] Decrypt()
|
||||||
{
|
{
|
||||||
return ProtectedData.Unprotect(Value, IV, DataProtectionScope.CurrentUser);
|
return ProtectedData.Unprotect(Value, IV, DataProtectionScope.LocalMachine);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string DecryptToString()
|
public string DecryptToString()
|
||||||
{
|
{
|
||||||
var bytes = ProtectedData.Unprotect(Value, IV, DataProtectionScope.CurrentUser);
|
var bytes = ProtectedData.Unprotect(Value, IV, DataProtectionScope.LocalMachine);
|
||||||
return Encoding.UTF8.GetString(bytes);
|
return Encoding.UTF8.GetString(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ namespace Bit.Core.Utilities
|
|||||||
{
|
{
|
||||||
public static async Task<SyncResult> SyncAllAsync(bool force = false, bool sendToServer = true)
|
public static async Task<SyncResult> SyncAllAsync(bool force = false, bool sendToServer = true)
|
||||||
{
|
{
|
||||||
|
var startingGroupDelta = SettingsService.Instance.GroupDeltaToken;
|
||||||
|
var startingUserDelta = SettingsService.Instance.UserDeltaToken;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var now = DateTime.UtcNow;
|
var now = DateTime.UtcNow;
|
||||||
@@ -20,8 +23,9 @@ namespace Bit.Core.Utilities
|
|||||||
|
|
||||||
FlattenUsersToGroups(groups, null, groups, users);
|
FlattenUsersToGroups(groups, null, groups, users);
|
||||||
|
|
||||||
if(!sendToServer)
|
if(!sendToServer || (groups.Count == 0 && users.Count == 0))
|
||||||
{
|
{
|
||||||
|
RestoreDeltas(startingGroupDelta, startingUserDelta);
|
||||||
return new SyncResult
|
return new SyncResult
|
||||||
{
|
{
|
||||||
Success = true,
|
Success = true,
|
||||||
@@ -53,6 +57,7 @@ namespace Bit.Core.Utilities
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
RestoreDeltas(startingGroupDelta, startingUserDelta);
|
||||||
return new SyncResult
|
return new SyncResult
|
||||||
{
|
{
|
||||||
Success = false,
|
Success = false,
|
||||||
@@ -60,14 +65,20 @@ namespace Bit.Core.Utilities
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (ApplicationException e)
|
catch(ApplicationException e)
|
||||||
{
|
{
|
||||||
|
RestoreDeltas(startingGroupDelta, startingUserDelta);
|
||||||
return new SyncResult
|
return new SyncResult
|
||||||
{
|
{
|
||||||
Success = false,
|
Success = false,
|
||||||
ErrorMessage = e.Message
|
ErrorMessage = e.Message
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
RestoreDeltas(startingGroupDelta, startingUserDelta);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IDirectoryService GetDirectoryService()
|
private static IDirectoryService GetDirectoryService()
|
||||||
@@ -114,5 +125,11 @@ namespace Bit.Core.Utilities
|
|||||||
FlattenUsersToGroups(groupsInThisGroup, usersInThisGroup, allGroups, allUsers);
|
FlattenUsersToGroups(groupsInThisGroup, usersInThisGroup, allGroups, allUsers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void RestoreDeltas(string groupDelta, string userDelta)
|
||||||
|
{
|
||||||
|
SettingsService.Instance.GroupDeltaToken = groupDelta;
|
||||||
|
SettingsService.Instance.UserDeltaToken = userDelta;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user