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:
parent
0ea89bf9da
commit
17b6061f40
@ -11,7 +11,7 @@ var userService = new UserService(tokenService, apiService, cryptoService);
|
|||||||
var settingsService = new SettingsService(userService);
|
var settingsService = new SettingsService(userService);
|
||||||
var loginService = new LoginService(cryptoService, userService, apiService, settingsService);
|
var loginService = new LoginService(cryptoService, userService, apiService, settingsService);
|
||||||
var folderService = new FolderService(cryptoService, userService, apiService);
|
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 autofillService = new AutofillService();
|
||||||
var passwordGenerationService = new PasswordGenerationService();
|
var passwordGenerationService = new PasswordGenerationService();
|
||||||
|
|
||||||
|
@ -30,13 +30,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
cryptoService.setEncPrivateKey(response.privateKey).then(function () {
|
cryptoService.setEncPrivateKey(response.privateKey).then(function () {
|
||||||
apiService.getProfile(function (profile) {
|
loggedIn(deferred);
|
||||||
cryptoService.setOrgKeys(profile.organizations).then(function () {
|
|
||||||
loggedIn(deferred);
|
|
||||||
});
|
|
||||||
}, function () {
|
|
||||||
loggedIn(deferred);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -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) {
|
ApiService.prototype.postFolder = function (folderRequest, success, error) {
|
||||||
var self = this;
|
var self = this;
|
||||||
handleTokenState(self).then(function (token) {
|
handleTokenState(self).then(function (token) {
|
||||||
@ -283,7 +307,7 @@ function initApiService() {
|
|||||||
handleTokenState(self).then(function (token) {
|
handleTokenState(self).then(function (token) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'GET',
|
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',
|
dataType: 'json',
|
||||||
success: function (response) {
|
success: function (response) {
|
||||||
var data = [];
|
var data = [];
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
function SyncService(loginService, folderService, userService, apiService, settingsService) {
|
function SyncService(loginService, folderService, userService, apiService, settingsService, cryptoService) {
|
||||||
this.loginService = loginService;
|
this.loginService = loginService;
|
||||||
this.folderService = folderService;
|
this.folderService = folderService;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
this.apiService = apiService;
|
this.apiService = apiService;
|
||||||
this.settingsService = settingsService;
|
this.settingsService = settingsService;
|
||||||
|
this.cryptoService = settingsService;
|
||||||
this.syncInProgress = false;
|
this.syncInProgress = false;
|
||||||
|
|
||||||
initSyncService();
|
initSyncService();
|
||||||
@ -36,7 +37,11 @@ function initSyncService() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
syncVault(userId).then(function () {
|
syncProfile().then(function () {
|
||||||
|
return syncFolders(userId);
|
||||||
|
}).then(function () {
|
||||||
|
return syncCiphers(userId);
|
||||||
|
}).then(function () {
|
||||||
return syncSettings(userId);
|
return syncSettings(userId);
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
self.setLastSync(now, 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 deferred = Q.defer();
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
self.apiService.getCiphers(function (response) {
|
self.apiService.getCiphers(function (response) {
|
||||||
var logins = {};
|
var logins = {};
|
||||||
var folders = {};
|
|
||||||
|
|
||||||
for (var i = 0; i < response.data.length; i++) {
|
for (var i = 0; i < response.data.length; i++) {
|
||||||
var data = response.data[i];
|
var data = response.data[i];
|
||||||
if (data.type === 1) {
|
if (data.type === 1) {
|
||||||
logins[data.id] = new LoginData(data, userId);
|
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 () {
|
||||||
self.loginService.replace(logins, function () {
|
deferred.resolve();
|
||||||
deferred.resolve();
|
|
||||||
return;
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}, function () {
|
}, function () {
|
||||||
deferred.reject();
|
deferred.reject();
|
||||||
return;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return deferred.promise
|
return deferred.promise
|
||||||
@ -126,11 +159,9 @@ function initSyncService() {
|
|||||||
|
|
||||||
self.settingsService.setEquivalentDomains(eqDomains, function () {
|
self.settingsService.setEquivalentDomains(eqDomains, function () {
|
||||||
deferred.resolve();
|
deferred.resolve();
|
||||||
return;
|
|
||||||
});
|
});
|
||||||
}, function () {
|
}, function () {
|
||||||
deferred.reject();
|
deferred.reject();
|
||||||
return;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
|
Loading…
Reference in New Issue
Block a user