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

add necessary apis for org directory imports

This commit is contained in:
Kyle Spearrin 2018-04-30 17:00:31 -04:00
parent 12533dd951
commit 66bdf442d6
5 changed files with 40 additions and 0 deletions

View File

@ -2,6 +2,7 @@ import { EnvironmentUrls } from '../models/domain/environmentUrls';
import { CipherRequest } from '../models/request/cipherRequest';
import { FolderRequest } from '../models/request/folderRequest';
import { ImportDirectoryRequest } from '../models/request/importDirectoryRequest';
import { PasswordHintRequest } from '../models/request/passwordHintRequest';
import { RegisterRequest } from '../models/request/registerRequest';
import { TokenRequest } from '../models/request/tokenRequest';
@ -36,4 +37,5 @@ export abstract class ApiService {
postCipherAttachment: (id: string, data: FormData) => Promise<CipherResponse>;
deleteCipherAttachment: (id: string, attachmentId: string) => Promise<any>;
getSync: () => Promise<SyncResponse>;
postImportDirectory: (organizationId: string, request: ImportDirectoryRequest) => Promise<any>;
}

View File

@ -0,0 +1,7 @@
import { ImportDirectoryRequestGroup } from './importDirectoryRequestGroup';
import { ImportDirectoryRequestUser } from './importDirectoryRequestUser';
export class ImportDirectoryRequest {
groups: ImportDirectoryRequestGroup[] = [];
users: ImportDirectoryRequestUser[] = [];
}

View File

@ -0,0 +1,5 @@
export class ImportDirectoryRequestGroup {
name: string;
externalId: string;
users: string[];
}

View File

@ -0,0 +1,5 @@
export class ImportDirectoryRequestUser {
externalId: string;
email: string;
deleted: boolean;
}

View File

@ -8,6 +8,7 @@ import { EnvironmentUrls } from '../models/domain/environmentUrls';
import { CipherRequest } from '../models/request/cipherRequest';
import { FolderRequest } from '../models/request/folderRequest';
import { ImportDirectoryRequest } from '../models/request/importDirectoryRequest';
import { PasswordHintRequest } from '../models/request/passwordHintRequest';
import { RegisterRequest } from '../models/request/registerRequest';
import { TokenRequest } from '../models/request/tokenRequest';
@ -379,6 +380,26 @@ export class ApiService implements ApiServiceAbstraction {
}
}
async postImportDirectory(organizationId: string, request: ImportDirectoryRequest): Promise<any> {
const authHeader = await this.handleTokenState();
const response = await fetch(new Request(this.baseUrl + '/organizations/' + organizationId + '/import', {
body: JSON.stringify(request),
cache: 'no-cache',
headers: new Headers({
'Accept': 'application/json',
'Authorization': authHeader,
'Content-Type': 'application/json; charset=utf-8',
'Device-Type': this.deviceType,
}),
method: 'POST',
}));
if (response.status !== 200) {
const error = await this.handleError(response, false);
return Promise.reject(error);
}
}
// Helpers
private async handleError(response: Response, tokenError: boolean): Promise<ErrorResponse> {