2018-07-05 16:48:51 +02:00
|
|
|
import { Component } from '@angular/core';
|
|
|
|
|
|
|
|
import { ToasterService } from 'angular2-toaster';
|
|
|
|
import { Angulartics2 } from 'angulartics2';
|
|
|
|
|
|
|
|
import { ApiService } from 'jslib/abstractions/api.service';
|
|
|
|
import { CipherService } from 'jslib/abstractions/cipher.service';
|
|
|
|
import { CryptoService } from 'jslib/abstractions/crypto.service';
|
|
|
|
import { I18nService } from 'jslib/abstractions/i18n.service';
|
|
|
|
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
2018-08-29 15:31:20 +02:00
|
|
|
import { UserService } from 'jslib/abstractions/user.service';
|
2018-07-05 16:48:51 +02:00
|
|
|
|
|
|
|
import { CipherData } from 'jslib/models/data/cipherData';
|
|
|
|
import { Cipher } from 'jslib/models/domain/cipher';
|
|
|
|
import { Organization } from 'jslib/models/domain/organization';
|
|
|
|
|
2018-07-05 19:14:33 +02:00
|
|
|
import { AttachmentsComponent as BaseAttachmentsComponent } from '../../vault/attachments.component';
|
2018-07-05 16:48:51 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-org-vault-attachments',
|
2018-07-05 19:14:33 +02:00
|
|
|
templateUrl: '../../vault/attachments.component.html',
|
2018-07-05 16:48:51 +02:00
|
|
|
})
|
|
|
|
export class AttachmentsComponent extends BaseAttachmentsComponent {
|
|
|
|
organization: Organization;
|
|
|
|
|
|
|
|
constructor(cipherService: CipherService, analytics: Angulartics2,
|
|
|
|
toasterService: ToasterService, i18nService: I18nService,
|
2018-08-29 15:31:20 +02:00
|
|
|
cryptoService: CryptoService, userService: UserService,
|
2018-07-05 16:48:51 +02:00
|
|
|
platformUtilsService: PlatformUtilsService, private apiService: ApiService) {
|
2018-08-29 15:31:20 +02:00
|
|
|
super(cipherService, analytics, toasterService, i18nService, cryptoService, userService,
|
2018-07-05 16:48:51 +02:00
|
|
|
platformUtilsService);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected async loadCipher() {
|
|
|
|
if (!this.organization.isAdmin) {
|
|
|
|
return await super.loadCipher();
|
|
|
|
}
|
|
|
|
const response = await this.apiService.getCipherAdmin(this.cipherId);
|
|
|
|
return new Cipher(new CipherData(response));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected saveCipherAttachment(file: File) {
|
|
|
|
return this.cipherService.saveAttachmentWithServer(this.cipherDomain, file, this.organization.isAdmin);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected deleteCipherAttachment(attachmentId: string) {
|
|
|
|
if (!this.organization.isAdmin) {
|
|
|
|
return super.deleteCipherAttachment(attachmentId);
|
|
|
|
}
|
|
|
|
return this.apiService.deleteCipherAttachmentAdmin(this.cipherId, attachmentId);
|
|
|
|
}
|
|
|
|
}
|