1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-11-26 12:16:07 +01:00

sync folders & added org id for ciphers/logins

This commit is contained in:
Kyle Spearrin 2017-04-20 10:47:14 -04:00
parent 458de2d2e0
commit 490d1775a2
10 changed files with 27 additions and 31 deletions

View File

@ -6,7 +6,7 @@ namespace Bit.App.Abstractions
public interface ISyncService
{
bool SyncInProgress { get; }
Task<bool> SyncAsync(string id);
Task<bool> SyncCipherAsync(string id);
Task<bool> SyncDeleteFolderAsync(string id, DateTime revisionDate);
Task<bool> SyncDeleteLoginAsync(string id);
Task<bool> FullSyncAsync(bool forceSync = false);

View File

@ -2,7 +2,8 @@
{
public enum CipherType : short
{
Folder = 0,
// Folder deprecated
//Folder = 0,
Login = 1
}
}

View File

@ -4,6 +4,7 @@
{
public LoginRequest(Login login)
{
OrganizationId = login.OrganizationId;
FolderId = login.FolderId;
Name = login.Name?.EncryptedString;
Uri = login.Uri?.EncryptedString;
@ -13,6 +14,7 @@
Favorite = login.Favorite;
}
public string OrganizationId { get; set; }
public string FolderId { get; set; }
public string Name { get; set; }
public string Uri { get; set; }

View File

@ -8,6 +8,8 @@ namespace Bit.App.Models.Api
{
public string Id { get; set; }
public string FolderId { get; set; }
public string UserId { get; set; }
public string OrganizationId { get; set; }
public CipherType Type { get; set; }
public bool Favorite { get; set; }
public JObject Data { get; set; }

View File

@ -6,6 +6,8 @@ namespace Bit.App.Models.Api
{
public string Id { get; set; }
public string FolderId { get; set; }
public string UserId { get; set; }
public string OrganizationId { get; set; }
public string Name { get; set; }
public string Uri { get; set; }
public string Username { get; set; }
@ -13,8 +15,5 @@ namespace Bit.App.Models.Api
public string Notes { get; set; }
public bool Favorite { get; set; }
public DateTime RevisionDate { get; set; }
// Expandables
public FolderResponse Folder { get; set; }
}
}

View File

@ -26,21 +26,6 @@ namespace Bit.App.Models.Data
RevisionDateTime = folder.RevisionDate;
}
public FolderData(CipherResponse cipher, string userId)
{
if(cipher.Type != Enums.CipherType.Folder)
{
throw new ArgumentException(nameof(cipher.Type));
}
var data = cipher.Data.ToObject<LoginDataModel>();
Id = cipher.Id;
UserId = userId;
Name = data.Name;
RevisionDateTime = cipher.RevisionDate;
}
[PrimaryKey]
public string Id { get; set; }
[Indexed]

View File

@ -16,6 +16,7 @@ namespace Bit.App.Models.Data
Id = login.Id;
FolderId = login.FolderId;
UserId = userId;
OrganizationId = login.OrganizationId;
Name = login.Name?.EncryptedString;
Uri = login.Uri?.EncryptedString;
Username = login.Username?.EncryptedString;
@ -29,6 +30,7 @@ namespace Bit.App.Models.Data
Id = login.Id;
FolderId = login.FolderId;
UserId = userId;
OrganizationId = login.OrganizationId;
Name = login.Name;
Uri = login.Uri;
Username = login.Username;
@ -50,6 +52,7 @@ namespace Bit.App.Models.Data
Id = cipher.Id;
FolderId = cipher.FolderId;
UserId = userId;
OrganizationId = cipher.OrganizationId;
Name = data.Name;
Uri = data.Uri;
Username = data.Username;
@ -64,6 +67,7 @@ namespace Bit.App.Models.Data
public string FolderId { get; set; }
[Indexed]
public string UserId { get; set; }
public string OrganizationId { get; set; }
public string Name { get; set; }
public string Uri { get; set; }
public string Username { get; set; }

View File

@ -11,6 +11,8 @@ namespace Bit.App.Models
public Login(LoginData data)
{
Id = data.Id;
UserId = data.UserId;
OrganizationId = data.OrganizationId;
FolderId = data.FolderId;
Name = data.Name != null ? new CipherString(data.Name) : null;
Uri = data.Uri != null ? new CipherString(data.Uri) : null;
@ -23,6 +25,8 @@ namespace Bit.App.Models
public Login(LoginResponse response)
{
Id = response.Id;
UserId = response.UserId;
OrganizationId = response.OrganizationId;
FolderId = response.FolderId;
Name = response.Name != null ? new CipherString(response.Name) : null;
Uri = response.Uri != null ? new CipherString(response.Uri) : null;
@ -32,6 +36,8 @@ namespace Bit.App.Models
Favorite = response.Favorite;
}
public string UserId { get; set; }
public string OrganizationId { get; set; }
public string FolderId { get; set; }
public CipherString Uri { get; set; }
public CipherString Username { get; set; }

View File

@ -64,7 +64,7 @@ namespace Bit.App.Services
{
break;
}
_syncService.SyncAsync(createUpdateMessage.Id);
_syncService.SyncCipherAsync(createUpdateMessage.Id);
break;
case Enums.PushType.SyncFolderDelete:
var folderDeleteMessage = values.ToObject<SyncCipherPushNotification>();

View File

@ -50,7 +50,7 @@ namespace Bit.App.Services
public bool SyncInProgress { get; private set; }
public async Task<bool> SyncAsync(string id)
public async Task<bool> SyncCipherAsync(string id)
{
if(!_authService.IsAuthenticated)
{
@ -77,10 +77,6 @@ namespace Bit.App.Services
{
switch(cipher.Result.Type)
{
case Enums.CipherType.Folder:
var folderData = new FolderData(cipher.Result, _authService.UserId);
await _folderRepository.UpsertAsync(folderData).ConfigureAwait(false);
break;
case Enums.CipherType.Login:
var loginData = new LoginData(cipher.Result, _authService.UserId);
await _loginRepository.UpsertAsync(loginData).ConfigureAwait(false);
@ -172,6 +168,7 @@ namespace Bit.App.Services
var now = DateTime.UtcNow;
var ciphers = await _cipherApiRepository.GetAsync().ConfigureAwait(false);
var folders = await _folderApiRepository.GetAsync().ConfigureAwait(false);
var domains = await _settingsApiRepository.GetDomains(false).ConfigureAwait(false);
if(!ciphers.Succeeded || !domains.Succeeded)
@ -193,11 +190,11 @@ namespace Bit.App.Services
return false;
}
var logins = ciphers.Result.Data.Where(c => c.Type == Enums.CipherType.Login).ToDictionary(s => s.Id);
var folders = ciphers.Result.Data.Where(c => c.Type == Enums.CipherType.Folder).ToDictionary(f => f.Id);
var loginsDict = ciphers.Result.Data.Where(c => c.Type == Enums.CipherType.Login).ToDictionary(s => s.Id);
var foldersDict = folders.Result.Data.ToDictionary(f => f.Id);
var loginTask = SyncLoginsAsync(logins);
var folderTask = SyncFoldersAsync(folders);
var loginTask = SyncLoginsAsync(loginsDict);
var folderTask = SyncFoldersAsync(foldersDict);
var domainsTask = SyncDomainsAsync(domains.Result);
await Task.WhenAll(loginTask, folderTask, domainsTask).ConfigureAwait(false);
@ -236,7 +233,7 @@ namespace Bit.App.Services
return false;
}
private async Task SyncFoldersAsync(IDictionary<string, CipherResponse> serverFolders)
private async Task SyncFoldersAsync(IDictionary<string, FolderResponse> serverFolders)
{
if(!_authService.IsAuthenticated)
{