mirror of
https://github.com/bitwarden/browser
synced 2026-02-19 10:54:00 +00:00
Updated delete attachment to conform with the server side changes (#19014)
This commit is contained in:
@@ -92,6 +92,7 @@ import { CipherRequest } from "../vault/models/request/cipher.request";
|
||||
import { AttachmentUploadDataResponse } from "../vault/models/response/attachment-upload-data.response";
|
||||
import { AttachmentResponse } from "../vault/models/response/attachment.response";
|
||||
import { CipherMiniResponse, CipherResponse } from "../vault/models/response/cipher.response";
|
||||
import { DeleteAttachmentResponse } from "../vault/models/response/delete-attachment.response";
|
||||
import { OptionalCipherResponse } from "../vault/models/response/optional-cipher.response";
|
||||
|
||||
/**
|
||||
@@ -243,8 +244,14 @@ export abstract class ApiService {
|
||||
id: string,
|
||||
request: AttachmentRequest,
|
||||
): Promise<AttachmentUploadDataResponse>;
|
||||
abstract deleteCipherAttachment(id: string, attachmentId: string): Promise<any>;
|
||||
abstract deleteCipherAttachmentAdmin(id: string, attachmentId: string): Promise<any>;
|
||||
abstract deleteCipherAttachment(
|
||||
id: string,
|
||||
attachmentId: string,
|
||||
): Promise<DeleteAttachmentResponse>;
|
||||
abstract deleteCipherAttachmentAdmin(
|
||||
id: string,
|
||||
attachmentId: string,
|
||||
): Promise<DeleteAttachmentResponse>;
|
||||
abstract postShareCipherAttachment(
|
||||
id: string,
|
||||
attachmentId: string,
|
||||
|
||||
@@ -115,6 +115,7 @@ import { CipherRequest } from "../vault/models/request/cipher.request";
|
||||
import { AttachmentUploadDataResponse } from "../vault/models/response/attachment-upload-data.response";
|
||||
import { AttachmentResponse } from "../vault/models/response/attachment.response";
|
||||
import { CipherResponse } from "../vault/models/response/cipher.response";
|
||||
import { DeleteAttachmentResponse } from "../vault/models/response/delete-attachment.response";
|
||||
import { OptionalCipherResponse } from "../vault/models/response/optional-cipher.response";
|
||||
|
||||
import { InsecureUrlNotAllowedError } from "./api-errors";
|
||||
@@ -590,18 +591,32 @@ export class ApiService implements ApiServiceAbstraction {
|
||||
return new AttachmentUploadDataResponse(r);
|
||||
}
|
||||
|
||||
deleteCipherAttachment(id: string, attachmentId: string): Promise<any> {
|
||||
return this.send("DELETE", "/ciphers/" + id + "/attachment/" + attachmentId, null, true, true);
|
||||
async deleteCipherAttachment(
|
||||
id: string,
|
||||
attachmentId: string,
|
||||
): Promise<DeleteAttachmentResponse> {
|
||||
const r = await this.send(
|
||||
"DELETE",
|
||||
"/ciphers/" + id + "/attachment/" + attachmentId,
|
||||
null,
|
||||
true,
|
||||
true,
|
||||
);
|
||||
return new DeleteAttachmentResponse(r);
|
||||
}
|
||||
|
||||
deleteCipherAttachmentAdmin(id: string, attachmentId: string): Promise<any> {
|
||||
return this.send(
|
||||
async deleteCipherAttachmentAdmin(
|
||||
id: string,
|
||||
attachmentId: string,
|
||||
): Promise<DeleteAttachmentResponse> {
|
||||
const r = await this.send(
|
||||
"DELETE",
|
||||
"/ciphers/" + id + "/attachment/" + attachmentId + "/admin",
|
||||
null,
|
||||
true,
|
||||
true,
|
||||
);
|
||||
return new DeleteAttachmentResponse(r);
|
||||
}
|
||||
|
||||
postShareCipherAttachment(
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { BaseResponse } from "../../../models/response/base.response";
|
||||
|
||||
import { CipherResponse } from "./cipher.response";
|
||||
|
||||
export class DeleteAttachmentResponse extends BaseResponse {
|
||||
cipher: CipherResponse;
|
||||
|
||||
constructor(response: any) {
|
||||
super(response);
|
||||
this.cipher = new CipherResponse(this.getResponseProperty("Cipher"));
|
||||
}
|
||||
}
|
||||
@@ -77,6 +77,7 @@ import { CipherShareRequest } from "../models/request/cipher-share.request";
|
||||
import { CipherWithIdRequest } from "../models/request/cipher-with-id.request";
|
||||
import { CipherRequest } from "../models/request/cipher.request";
|
||||
import { CipherResponse } from "../models/response/cipher.response";
|
||||
import { DeleteAttachmentResponse } from "../models/response/delete-attachment.response";
|
||||
import { AttachmentView } from "../models/view/attachment.view";
|
||||
import { CipherView } from "../models/view/cipher.view";
|
||||
import { FieldView } from "../models/view/field.view";
|
||||
@@ -1482,16 +1483,16 @@ export class CipherService implements CipherServiceAbstraction {
|
||||
userId: UserId,
|
||||
admin: boolean = false,
|
||||
): Promise<CipherData> {
|
||||
let cipherResponse = null;
|
||||
let response: DeleteAttachmentResponse;
|
||||
try {
|
||||
cipherResponse = admin
|
||||
response = admin
|
||||
? await this.apiService.deleteCipherAttachmentAdmin(id, attachmentId)
|
||||
: await this.apiService.deleteCipherAttachment(id, attachmentId);
|
||||
} catch (e) {
|
||||
return Promise.reject((e as ErrorResponse).getSingleMessage());
|
||||
}
|
||||
|
||||
const cipherData = CipherData.fromJSON(cipherResponse?.cipher);
|
||||
const cipherData = new CipherData(response.cipher);
|
||||
|
||||
return await this.deleteAttachment(id, cipherData.revisionDate, attachmentId, userId);
|
||||
}
|
||||
|
||||
@@ -93,12 +93,12 @@ export class CipherFileUploadService implements CipherFileUploadServiceAbstracti
|
||||
response: CipherResponse,
|
||||
uploadData: AttachmentUploadDataResponse,
|
||||
isAdmin: boolean,
|
||||
) {
|
||||
return () => {
|
||||
): () => Promise<void> {
|
||||
return async () => {
|
||||
if (isAdmin) {
|
||||
return this.apiService.deleteCipherAttachmentAdmin(response.id, uploadData.attachmentId);
|
||||
await this.apiService.deleteCipherAttachmentAdmin(response.id, uploadData.attachmentId);
|
||||
} else {
|
||||
return this.apiService.deleteCipherAttachment(response.id, uploadData.attachmentId);
|
||||
await this.apiService.deleteCipherAttachment(response.id, uploadData.attachmentId);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user