1
0
mirror of https://github.com/bitwarden/web synced 2026-01-20 01:13:32 +00:00

org vault collections

This commit is contained in:
Kyle Spearrin
2018-07-05 12:56:58 -04:00
parent 1d60e881ee
commit 7d42c4eaa0
4 changed files with 117 additions and 13 deletions

View File

@@ -0,0 +1,57 @@
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 { CollectionService } from 'jslib/abstractions/collection.service';
import { I18nService } from 'jslib/abstractions/i18n.service';
import { CipherData } from 'jslib/models/data/cipherData';
import { Cipher } from 'jslib/models/domain/cipher';
import { Organization } from 'jslib/models/domain/organization';
import { CipherCollectionsRequest } from 'jslib/models/request/cipherCollectionsRequest';
import { CollectionsComponent as BaseCollectionsComponent } from '../vault/collections.component';
@Component({
selector: 'app-org-vault-collections',
templateUrl: '../vault/collections.component.html',
})
export class CollectionsComponent extends BaseCollectionsComponent {
organization: Organization;
constructor(collectionService: CollectionService, analytics: Angulartics2,
toasterService: ToasterService, i18nService: I18nService,
cipherService: CipherService, private apiService: ApiService) {
super(collectionService, analytics, toasterService, i18nService, cipherService);
}
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 loadCipherCollections() {
if (!this.organization.isAdmin) {
return super.loadCipherCollections();
}
return this.collectionIds;
}
protected loadCollections() {
if (!this.organization.isAdmin) {
return super.loadCollections();
}
return Promise.resolve(this.collections);
}
protected saveCollections() {
const request = new CipherCollectionsRequest(this.cipherDomain.collectionIds);
return this.apiService.putCipherCollectionsAdmin(this.cipherId, request);
}
}

View File

@@ -25,6 +25,7 @@ import { ModalComponent } from '../modal.component';
import { AddEditComponent } from './add-edit.component';
import { AttachmentsComponent } from './attachments.component';
import { CiphersComponent } from './ciphers.component';
import { CollectionsComponent } from './collections.component';
import { GroupingsComponent } from './groupings.component';
@Component({
@@ -36,6 +37,7 @@ export class VaultComponent implements OnInit {
@ViewChild(CiphersComponent) ciphersComponent: CiphersComponent;
@ViewChild('attachments', { read: ViewContainerRef }) attachmentsModalRef: ViewContainerRef;
@ViewChild('cipherAddEdit', { read: ViewContainerRef }) cipherAddEditModalRef: ViewContainerRef;
@ViewChild('collections', { read: ViewContainerRef }) collectionsModalRef: ViewContainerRef;
organization: Organization;
collectionId: string;
@@ -151,6 +153,31 @@ export class VaultComponent implements OnInit {
});
}
editCipherCollections(cipher: CipherView) {
if (this.modal != null) {
this.modal.close();
}
const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent);
this.modal = this.collectionsModalRef.createComponent(factory).instance;
const childComponent = this.modal.show<CollectionsComponent>(CollectionsComponent, this.collectionsModalRef);
if (this.organization.isAdmin) {
childComponent.collectionIds = cipher.collectionIds;
childComponent.collections = this.groupingsComponent.collections.filter((c) => !c.readOnly);
}
childComponent.organization = this.organization;
childComponent.cipherId = cipher.id;
childComponent.onSavedCollections.subscribe(async () => {
this.modal.close();
await this.ciphersComponent.refresh();
});
this.modal.onClosed.subscribe(async () => {
this.modal = null;
});
}
addCipher() {
const component = this.editCipher(null);
component.type = this.type;