mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-06 09:20:43 +01:00
org vault collections
This commit is contained in:
parent
1d60e881ee
commit
7d42c4eaa0
@ -35,6 +35,7 @@ import { TwoFactorComponent } from './accounts/two-factor.component';
|
||||
import { AddEditComponent as OrgAddEditComponent } from './organizations/add-edit.component';
|
||||
import { AttachmentsComponent as OrgAttachmentsComponent } from './organizations/attachments.component';
|
||||
import { CiphersComponent as OrgCiphersComponent } from './organizations/ciphers.component';
|
||||
import { CollectionsComponent as OrgCollectionsComponent } from './organizations/collections.component';
|
||||
import { GroupingsComponent as OrgGroupingsComponent } from './organizations/groupings.component';
|
||||
import { VaultComponent as OrgVaultComponent } from './organizations/vault.component';
|
||||
|
||||
@ -157,6 +158,7 @@ import { SearchCiphersPipe } from 'jslib/angular/pipes/search-ciphers.pipe';
|
||||
OrgAddEditComponent,
|
||||
OrgAttachmentsComponent,
|
||||
OrgCiphersComponent,
|
||||
OrgCollectionsComponent,
|
||||
OrgGroupingsComponent,
|
||||
OrganizationsComponent,
|
||||
OrganizationLayoutComponent,
|
||||
@ -203,6 +205,7 @@ import { SearchCiphersPipe } from 'jslib/angular/pipes/search-ciphers.pipe';
|
||||
ModalComponent,
|
||||
OrgAddEditComponent,
|
||||
OrgAttachmentsComponent,
|
||||
OrgCollectionsComponent,
|
||||
PasswordGeneratorHistoryComponent,
|
||||
PurgeVaultComponent,
|
||||
ShareComponent,
|
||||
|
57
src/app/organizations/collections.component.ts
Normal file
57
src/app/organizations/collections.component.ts
Normal 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);
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -29,26 +29,26 @@ export class CollectionsComponent implements OnInit, OnDestroy {
|
||||
|
||||
formPromise: Promise<any>;
|
||||
cipher: CipherView;
|
||||
collectionIds: string[];
|
||||
collections: CollectionView[] = [];
|
||||
|
||||
private cipherDomain: Cipher;
|
||||
protected cipherDomain: Cipher;
|
||||
|
||||
constructor(private collectionService: CollectionService, private analytics: Angulartics2,
|
||||
private toasterService: ToasterService, private i18nService: I18nService,
|
||||
private cipherService: CipherService) { }
|
||||
constructor(protected collectionService: CollectionService, protected analytics: Angulartics2,
|
||||
protected toasterService: ToasterService, protected i18nService: I18nService,
|
||||
protected cipherService: CipherService) { }
|
||||
|
||||
async ngOnInit() {
|
||||
this.cipherDomain = await this.cipherService.get(this.cipherId);
|
||||
this.cipherDomain = await this.loadCipher();
|
||||
this.collectionIds = this.loadCipherCollections();
|
||||
this.cipher = await this.cipherDomain.decrypt();
|
||||
const allCollections = await this.collectionService.getAllDecrypted();
|
||||
this.collections = allCollections.filter((c) =>
|
||||
!c.readOnly && c.organizationId === this.cipher.organizationId);
|
||||
this.collections = await this.loadCollections();
|
||||
|
||||
this.unselectAll();
|
||||
if (this.cipherDomain.collectionIds != null) {
|
||||
for (const collection of this.collections) {
|
||||
(collection as any).checked = this.cipherDomain.collectionIds.indexOf(collection.id) > -1;
|
||||
}
|
||||
if (this.collectionIds != null) {
|
||||
this.collections.forEach((c) => {
|
||||
(c as any).checked = this.collectionIds.indexOf(c.id) > -1;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,7 +60,7 @@ export class CollectionsComponent implements OnInit, OnDestroy {
|
||||
this.cipherDomain.collectionIds = this.collections
|
||||
.filter((c) => !!(c as any).checked)
|
||||
.map((c) => c.id);
|
||||
this.formPromise = this.cipherService.saveCollectionsWithServer(this.cipherDomain);
|
||||
this.formPromise = this.saveCollections();
|
||||
await this.formPromise;
|
||||
this.onSavedCollections.emit();
|
||||
this.analytics.eventTrack.next({ action: 'Edited Cipher Collections' });
|
||||
@ -82,4 +82,21 @@ export class CollectionsComponent implements OnInit, OnDestroy {
|
||||
(c as any).checked = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected loadCipher() {
|
||||
return this.cipherService.get(this.cipherId);
|
||||
}
|
||||
|
||||
protected loadCipherCollections() {
|
||||
return this.cipherDomain.collectionIds;
|
||||
}
|
||||
|
||||
protected async loadCollections() {
|
||||
const allCollections = await this.collectionService.getAllDecrypted();
|
||||
return allCollections.filter((c) => !c.readOnly && c.organizationId === this.cipher.organizationId);
|
||||
}
|
||||
|
||||
protected saveCollections() {
|
||||
return this.cipherService.saveCollectionsWithServer(this.cipherDomain);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user