mirror of
https://github.com/bitwarden/web
synced 2025-12-28 22:23:52 +00:00
add subvault
This commit is contained in:
@@ -29,15 +29,6 @@
|
||||
del: { url: _apiUri + '/ciphers/:id/delete', method: 'POST', params: { id: '@id' } }
|
||||
});
|
||||
|
||||
_service.subvaults = $resource(_apiUri + '/subvaults/:id', {}, {
|
||||
get: { method: 'GET', params: { id: '@id' } },
|
||||
list: { method: 'GET', params: {} },
|
||||
listOrganization: { url: _apiUri + '/subvaults/organization/:orgId', method: 'GET', params: { orgId: '@orgId' } },
|
||||
post: { method: 'POST', params: {} },
|
||||
put: { method: 'POST', params: { id: '@id' } },
|
||||
del: { url: _apiUri + '/subvaults/:id/delete', method: 'POST', params: { id: '@id' } }
|
||||
});
|
||||
|
||||
_service.organizations = $resource(_apiUri + '/organizations/:id', {}, {
|
||||
get: { method: 'GET', params: { id: '@id' } },
|
||||
getExtended: { url: _apiUri + '/organizations/:id/extended', method: 'GET', params: { id: '@id' } },
|
||||
@@ -56,6 +47,15 @@
|
||||
del: { url: _apiUri + '/organizations/:orgId/users/:id/delete', method: 'POST', params: { id: '@id', orgId: '@orgId' } }
|
||||
});
|
||||
|
||||
_service.subvaults = $resource(_apiUri + '/organizations/:orgId/subvaults/:id', {}, {
|
||||
get: { method: 'GET', params: { id: '@id', orgId: '@orgId' } },
|
||||
listMe: { url: _apiUri + '/subvaults', method: 'GET', params: {} },
|
||||
listOrganization: { method: 'GET', params: { orgId: '@orgId' } },
|
||||
post: { method: 'POST', params: { orgId: '@orgId' } },
|
||||
put: { method: 'POST', params: { id: '@id', orgId: '@orgId' } },
|
||||
del: { url: _apiUri + '/organizations/:orgId/subvaults/:id/delete', method: 'POST', params: { id: '@id', orgId: '@orgId' } }
|
||||
});
|
||||
|
||||
_service.accounts = $resource(_apiUri + '/accounts', {}, {
|
||||
register: { url: _apiUri + '/accounts/register', method: 'POST', params: {} },
|
||||
emailToken: { url: _apiUri + '/accounts/email-token', method: 'POST', params: {} },
|
||||
|
||||
@@ -61,21 +61,6 @@ angular
|
||||
username: decryptProperty(encryptedCipher.Data.Username, key, true)
|
||||
};
|
||||
|
||||
try {
|
||||
login.name = cryptoService.decrypt(encryptedCipher.Data.Name, key);
|
||||
}
|
||||
catch (err) {
|
||||
login.name = '[error: cannot decrypt]';
|
||||
}
|
||||
|
||||
try {
|
||||
login.username = encryptedCipher.Data.Username && encryptedCipher.Data.Username !== '' ?
|
||||
cryptoService.decrypt(encryptedCipher.Data.Username, key) : null;
|
||||
}
|
||||
catch (err) {
|
||||
login.username = '[error: cannot decrypt]';
|
||||
}
|
||||
|
||||
return login;
|
||||
};
|
||||
|
||||
@@ -109,6 +94,31 @@ angular
|
||||
};
|
||||
};
|
||||
|
||||
_service.decryptSubvaults = function (encryptedSubvaults, orgId, catchError) {
|
||||
if (!encryptedSubvaults) throw "encryptedSubvaults is undefined or null";
|
||||
|
||||
var unencryptedSubvaults = [];
|
||||
for (var i = 0; i < encryptedSubvaults.length; i++) {
|
||||
unencryptedSubvaults.push(_service.decryptSubvault(encryptedSubvaults[i], orgId, catchError));
|
||||
}
|
||||
|
||||
return unencryptedSubvaults;
|
||||
};
|
||||
|
||||
_service.decryptSubvault = function (encryptedSubvault, orgId, catchError) {
|
||||
if (!encryptedSubvault) throw "encryptedSubvault is undefined or null";
|
||||
|
||||
catchError = catchError === true ? true : false;
|
||||
orgId = orgId || encryptedSubvault.OrganizationId;
|
||||
var key = cryptoService.getOrgKey(orgId);
|
||||
|
||||
return {
|
||||
id: encryptedSubvault.Id,
|
||||
name: catchError ? decryptProperty(encryptedSubvault.Name, key, false) :
|
||||
cryptoService.decrypt(encryptedSubvault.Name, key)
|
||||
};
|
||||
};
|
||||
|
||||
function decryptProperty(property, key, checkEmpty) {
|
||||
if (checkEmpty && (!property || property === '')) {
|
||||
return null;
|
||||
@@ -172,5 +182,25 @@ angular
|
||||
};
|
||||
};
|
||||
|
||||
_service.encryptSubvaults = function (unencryptedSubvaults, orgId) {
|
||||
if (!unencryptedSubvaults) throw "unencryptedSubvaults is undefined or null";
|
||||
|
||||
var encryptedSubvaults = [];
|
||||
for (var i = 0; i < unencryptedSubvaults.length; i++) {
|
||||
encryptedSubvaults.push(_service.encryptSubvault(unencryptedSubvaults[i], orgId));
|
||||
}
|
||||
|
||||
return encryptedSubvaults;
|
||||
};
|
||||
|
||||
_service.encryptSubvault = function (unencryptedSubvault, orgId) {
|
||||
if (!unencryptedSubvault) throw "unencryptedSubvault is undefined or null";
|
||||
|
||||
return {
|
||||
id: unencryptedSubvault.id,
|
||||
name: cryptoService.encrypt(unencryptedSubvault.name, cryptoService.getOrgKey(orgId))
|
||||
};
|
||||
};
|
||||
|
||||
return _service;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user