diff --git a/jslib b/jslib index 278b4402da..9b008ff382 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 278b4402da94ab36b4def76f520599a23308f7f1 +Subproject commit 9b008ff382d1dd6682185cf092afbf02a83ce951 diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 37eed3ad49..17d57eb354 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -32,6 +32,7 @@ import { RegisterComponent } from './accounts/register.component'; import { TwoFactorOptionsComponent } from './accounts/two-factor-options.component'; import { TwoFactorComponent } from './accounts/two-factor.component'; +import { AddEditComponent as OrgAddEditComponent } from './organizations/add-edit.component'; import { CiphersComponent as OrgCiphersComponent } from './organizations/ciphers.component'; import { GroupingsComponent as OrgGroupingsComponent } from './organizations/groupings.component'; import { VaultComponent as OrgVaultComponent } from './organizations/vault.component'; @@ -152,6 +153,7 @@ import { SearchCiphersPipe } from 'jslib/angular/pipes/search-ciphers.pipe'; ModalComponent, NavbarComponent, OptionsComponent, + OrgAddEditComponent, OrgCiphersComponent, OrgGroupingsComponent, OrganizationsComponent, @@ -197,6 +199,7 @@ import { SearchCiphersPipe } from 'jslib/angular/pipes/search-ciphers.pipe'; DeleteAccountComponent, FolderAddEditComponent, ModalComponent, + OrgAddEditComponent, PasswordGeneratorHistoryComponent, PurgeVaultComponent, ShareComponent, diff --git a/src/app/organizations/add-edit.component.ts b/src/app/organizations/add-edit.component.ts new file mode 100644 index 0000000000..b277ff9138 --- /dev/null +++ b/src/app/organizations/add-edit.component.ts @@ -0,0 +1,73 @@ +import { + Component, + OnInit, +} from '@angular/core'; + +import { ToasterService } from 'angular2-toaster'; +import { Angulartics2 } from 'angulartics2'; + +import { ApiService } from 'jslib/abstractions/api.service'; +import { AuditService } from 'jslib/abstractions/audit.service'; +import { CipherService } from 'jslib/abstractions/cipher.service'; +import { FolderService } from 'jslib/abstractions/folder.service'; +import { I18nService } from 'jslib/abstractions/i18n.service'; +import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service'; +import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; +import { StateService } from 'jslib/abstractions/state.service'; +import { TokenService } from 'jslib/abstractions/token.service'; +import { TotpService } from 'jslib/abstractions/totp.service'; + +import { CipherData } from 'jslib/models/data/cipherData'; +import { Cipher } from 'jslib/models/domain/cipher'; +import { Organization } from 'jslib/models/domain/organization'; +import { CipherRequest } from 'jslib/models/request/cipherRequest'; + +import { AddEditComponent as BaseAddEditComponent } from '../vault/add-edit.component'; + +@Component({ + selector: 'app-org-vault-add-edit', + templateUrl: '../vault/add-edit.component.html', +}) +export class AddEditComponent extends BaseAddEditComponent implements OnInit { + organization: Organization; + + constructor(cipherService: CipherService, folderService: FolderService, + i18nService: I18nService, platformUtilsService: PlatformUtilsService, + analytics: Angulartics2, toasterService: ToasterService, + auditService: AuditService, stateService: StateService, + tokenService: TokenService, totpService: TotpService, + passwordGenerationService: PasswordGenerationService, private apiService: ApiService) { + super(cipherService, folderService, i18nService, platformUtilsService, analytics, + toasterService, auditService, stateService, tokenService, totpService, passwordGenerationService); + } + + protected async loadCipher() { + if (this.organization.isAdmin) { + const response = await this.apiService.getCipherAdmin(this.cipherId); + return new Cipher(new CipherData(response)); + } else { + return await super.loadCipher(); + } + } + + protected async saveCipher(cipher: Cipher) { + if (this.organization.isAdmin) { + const request = new CipherRequest(cipher); + if (this.editMode) { + return this.apiService.putCipherAdmin(this.cipherId, request); + } else { + return this.apiService.postCipherAdmin(request); + } + } else { + return super.saveCipher(cipher); + } + } + + protected async deleteCipher() { + if (this.organization.isAdmin) { + return this.apiService.deleteCipherAdmin(this.cipherId); + } else { + return super.deleteCipher(); + } + } +} diff --git a/src/app/organizations/vault.component.ts b/src/app/organizations/vault.component.ts index 522b6e5f6c..6efafb8081 100644 --- a/src/app/organizations/vault.component.ts +++ b/src/app/organizations/vault.component.ts @@ -1,8 +1,10 @@ import { Location } from '@angular/common'; import { Component, + ComponentFactoryResolver, OnInit, ViewChild, + ViewContainerRef, } from '@angular/core'; import { ActivatedRoute, @@ -18,6 +20,9 @@ import { CipherView } from 'jslib/models/view/cipherView'; import { CipherType } from 'jslib/enums/cipherType'; +import { ModalComponent } from '../modal.component'; + +import { AddEditComponent } from './add-edit.component'; import { CiphersComponent } from './ciphers.component'; import { GroupingsComponent } from './groupings.component'; @@ -28,14 +33,18 @@ import { GroupingsComponent } from './groupings.component'; export class VaultComponent implements OnInit { @ViewChild(GroupingsComponent) groupingsComponent: GroupingsComponent; @ViewChild(CiphersComponent) ciphersComponent: CiphersComponent; + @ViewChild('cipherAddEdit', { read: ViewContainerRef }) cipherAddEditModalRef: ViewContainerRef; organization: Organization; collectionId: string; type: CipherType; + private modal: ModalComponent = null; + constructor(private route: ActivatedRoute, private userService: UserService, private location: Location, private router: Router, - private syncService: SyncService, private i18nService: I18nService) { } + private syncService: SyncService, private i18nService: I18nService, + private componentFactoryResolver: ComponentFactoryResolver) { } ngOnInit() { this.route.parent.params.subscribe(async (params) => { @@ -116,6 +125,38 @@ export class VaultComponent implements OnInit { this.ciphersComponent.searchText = searchText; } + addCipher() { + const component = this.editCipher(null); + component.type = this.type; + } + + editCipher(cipher: CipherView) { + if (this.modal != null) { + this.modal.close(); + } + + const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent); + this.modal = this.cipherAddEditModalRef.createComponent(factory).instance; + const childComponent = this.modal.show(AddEditComponent, this.cipherAddEditModalRef); + + childComponent.organization = this.organization; + childComponent.cipherId = cipher == null ? null : cipher.id; + childComponent.onSavedCipher.subscribe(async (c: CipherView) => { + this.modal.close(); + await this.ciphersComponent.refresh(); + }); + childComponent.onDeletedCipher.subscribe(async (c: CipherView) => { + this.modal.close(); + await this.ciphersComponent.refresh(); + }); + + this.modal.onClosed.subscribe(() => { + this.modal = null; + }); + + return childComponent; + } + private clearFilters() { this.collectionId = null; this.type = null; diff --git a/src/app/vault/add-edit.component.html b/src/app/vault/add-edit.component.html index 51b54158f4..3e22420ae8 100644 --- a/src/app/vault/add-edit.component.html +++ b/src/app/vault/add-edit.component.html @@ -21,7 +21,7 @@ -
+