1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-22 11:45:59 +01:00

sync org keys and folders

This commit is contained in:
Kyle Spearrin 2017-04-24 11:08:32 -04:00
parent 0ea89bf9da
commit 17b6061f40
4 changed files with 73 additions and 24 deletions

View File

@ -11,7 +11,7 @@ var userService = new UserService(tokenService, apiService, cryptoService);
var settingsService = new SettingsService(userService);
var loginService = new LoginService(cryptoService, userService, apiService, settingsService);
var folderService = new FolderService(cryptoService, userService, apiService);
var syncService = new SyncService(loginService, folderService, userService, apiService, settingsService);
var syncService = new SyncService(loginService, folderService, userService, apiService, settingsService, cryptoService);
var autofillService = new AutofillService();
var passwordGenerationService = new PasswordGenerationService();

View File

@ -30,13 +30,7 @@
}
cryptoService.setEncPrivateKey(response.privateKey).then(function () {
apiService.getProfile(function (profile) {
cryptoService.setOrgKeys(profile.organizations).then(function () {
loggedIn(deferred);
});
}, function () {
loggedIn(deferred);
});
loggedIn(deferred);
});
});
});

View File

@ -215,6 +215,30 @@ function initApiService() {
});
};
ApiService.prototype.getFolders = function (success, error) {
var self = this;
handleTokenState(self).then(function (token) {
$.ajax({
type: 'GET',
url: self.baseUrl + '/folders?access_token2=' + token,
dataType: 'json',
success: function (response) {
var data = [];
for (var i = 0; i < response.Data.length; i++) {
data.push(new FolderResponse(response.Data[i]));
}
success(new ListResponse(data));
},
error: function (jqXHR, textStatus, errorThrown) {
handleError(error, jqXHR, false, self);
}
});
}, function (jqXHR) {
handleError(error, jqXHR, true, self);
});
};
ApiService.prototype.postFolder = function (folderRequest, success, error) {
var self = this;
handleTokenState(self).then(function (token) {
@ -283,7 +307,7 @@ function initApiService() {
handleTokenState(self).then(function (token) {
$.ajax({
type: 'GET',
url: self.baseUrl + '/ciphers?includeFolders=true&includeShared=true&access_token2=' + token,
url: self.baseUrl + '/ciphers?includeFolders=false&includeShared=true&access_token2=' + token,
dataType: 'json',
success: function (response) {
var data = [];

View File

@ -1,9 +1,10 @@
function SyncService(loginService, folderService, userService, apiService, settingsService) {
function SyncService(loginService, folderService, userService, apiService, settingsService, cryptoService) {
this.loginService = loginService;
this.folderService = folderService;
this.userService = userService;
this.apiService = apiService;
this.settingsService = settingsService;
this.cryptoService = settingsService;
this.syncInProgress = false;
initSyncService();
@ -36,7 +37,11 @@ function initSyncService() {
return;
}
syncVault(userId).then(function () {
syncProfile().then(function () {
return syncFolders(userId);
}).then(function () {
return syncCiphers(userId);
}).then(function () {
return syncSettings(userId);
}).then(function () {
self.setLastSync(now, function () {
@ -75,33 +80,61 @@ function initSyncService() {
});
}
function syncVault(userId) {
function syncProfile() {
var deferred = Q.defer();
var self = this;
self.apiService.getProfile(function (response) {
self.cryptoService.setOrgKeys(response.organizations).then(function () {
deferred.resolve();
});
}, function () {
deferred.reject();
});
return deferred.promise
}
function syncFolders(userId) {
var deferred = Q.defer();
var self = this;
self.apiService.getFolders(function (response) {
var folders = {};
for (var i = 0; i < response.data.length; i++) {
folders[response.data.id] = new FolderData(response.data[i], userId);
}
self.folderService.replace(folders, function () {
deferred.resolve();
});
}, function () {
deferred.reject();
});
return deferred.promise
}
function syncCiphers(userId) {
var deferred = Q.defer();
var self = this;
self.apiService.getCiphers(function (response) {
var logins = {};
var folders = {};
for (var i = 0; i < response.data.length; i++) {
var data = response.data[i];
if (data.type === 1) {
logins[data.id] = new LoginData(data, userId);
}
else if (data.type === 0) {
folders[data.id] = new FolderData(data, userId);
}
}
self.folderService.replace(folders, function () {
self.loginService.replace(logins, function () {
deferred.resolve();
return;
});
self.loginService.replace(logins, function () {
deferred.resolve();
});
}, function () {
deferred.reject();
return;
});
return deferred.promise
@ -126,11 +159,9 @@ function initSyncService() {
self.settingsService.setEquivalentDomains(eqDomains, function () {
deferred.resolve();
return;
});
}, function () {
deferred.reject();
return;
});
return deferred.promise;