From db5855aa4b2699b06e85468087b30405b98b226b Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 23 Oct 2018 10:29:05 -0400 Subject: [PATCH] fixes and move to jslib share component --- jslib | 2 +- src/_locales/en/messages.json | 9 ++ src/popup/app-routing.animations.ts | 3 + src/popup/app-routing.module.ts | 6 +- src/popup/app.module.ts | 2 +- src/popup/vault/add-edit.component.html | 14 +-- src/popup/vault/add-edit.component.ts | 18 ++-- src/popup/vault/share.component.html | 45 ++++------ src/popup/vault/share.component.ts | 112 +++--------------------- 9 files changed, 60 insertions(+), 151 deletions(-) diff --git a/jslib b/jslib index 2f6426deb47..89c23522d56 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 2f6426deb470b71838b51c52587929ac64d428bf +Subproject commit 89c23522d5697c722dcbe7d074cd12ebb6dc8783 diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index 09bbde16986..77e1efadb54 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -554,6 +554,9 @@ "sharedItem": { "message": "Shared Item" }, + "shareDesc": { + "message": "Choose an organization that you wish to share this item with. Sharing transfers ownership of the item to the organization. You will no longer be the direct owner of this item once it has been shared." + }, "learnMore": { "message": "Learn more" }, @@ -1094,5 +1097,11 @@ }, "neverLockWarning": { "message": "Are you sure you want to use the \"Never\" option? Setting your lock options to \"Never\" stores your vault's encryption key on your device. If you use this option you should ensure that you keep your device properly protected." + }, + "noOrganizationsList": { + "message": "You do not belong to any organizations. Organizations allow you to securely share items with other users." + }, + "noCollectionsInList": { + "message": "There are no collections to list." } } diff --git a/src/popup/app-routing.animations.ts b/src/popup/app-routing.animations.ts index 07fa15d5c0f..a1baf4535e1 100644 --- a/src/popup/app-routing.animations.ts +++ b/src/popup/app-routing.animations.ts @@ -120,6 +120,9 @@ export const routerTransition = trigger('routerTransition', [ transition('add-cipher => generator, edit-cipher => generator', inSlideUp), transition('generator => add-cipher, generator => edit-cipher', outSlideDown), + transition('edit-cipher => share-cipher', inSlideUp), + transition('share-cipher => edit-cipher', outSlideDown), + transition('edit-cipher => attachments', inSlideLeft), transition('attachments => edit-cipher', outSlideRight), diff --git a/src/popup/app-routing.module.ts b/src/popup/app-routing.module.ts index ae44e51c580..83fa66939c2 100644 --- a/src/popup/app-routing.module.ts +++ b/src/popup/app-routing.module.ts @@ -29,11 +29,11 @@ import { SyncComponent } from './settings/sync.component'; import { TabsComponent } from './tabs.component'; import { AddEditComponent } from './vault/add-edit.component'; import { AttachmentsComponent } from './vault/attachments.component'; -import { ShareComponent } from './vault/share.component'; import { CiphersComponent } from './vault/ciphers.component'; import { CurrentTabComponent } from './vault/current-tab.component'; import { GroupingsComponent } from './vault/groupings.component'; import { PasswordHistoryComponent } from './vault/password-history.component'; +import { ShareComponent } from './vault/share.component'; import { ViewComponent } from './vault/view.component'; const routes: Routes = [ @@ -125,10 +125,10 @@ const routes: Routes = [ data: { state: 'edit-cipher' }, }, { - path: 'share', + path: 'share-cipher', component: ShareComponent, canActivate: [AuthGuardService], - data: { state: 'share' }, + data: { state: 'share-cipher' }, }, { path: 'attachments', diff --git a/src/popup/app.module.ts b/src/popup/app.module.ts index 77c30a0758e..b83b3c27f30 100644 --- a/src/popup/app.module.ts +++ b/src/popup/app.module.ts @@ -36,11 +36,11 @@ import { SyncComponent } from './settings/sync.component'; import { TabsComponent } from './tabs.component'; import { AddEditComponent } from './vault/add-edit.component'; import { AttachmentsComponent } from './vault/attachments.component'; -import { ShareComponent } from './vault/share.component'; import { CiphersComponent } from './vault/ciphers.component'; import { CurrentTabComponent } from './vault/current-tab.component'; import { GroupingsComponent } from './vault/groupings.component'; import { PasswordHistoryComponent } from './vault/password-history.component'; +import { ShareComponent } from './vault/share.component'; import { ViewComponent } from './vault/view.component'; import { ApiActionDirective } from 'jslib/angular/directives/api-action.directive'; diff --git a/src/popup/vault/add-edit.component.html b/src/popup/vault/add-edit.component.html index 026a242410e..35abd49bd32 100644 --- a/src/popup/vault/add-edit.component.html +++ b/src/popup/vault/add-edit.component.html @@ -318,20 +318,14 @@
- - -
-
diff --git a/src/popup/vault/add-edit.component.ts b/src/popup/vault/add-edit.component.ts index b399278caaf..f5c79ac5c94 100644 --- a/src/popup/vault/add-edit.component.ts +++ b/src/popup/vault/add-edit.component.ts @@ -1,8 +1,5 @@ import { Location } from '@angular/common'; -import { - Component, - OnInit, -} from '@angular/core'; +import { Component } from '@angular/core'; import { ActivatedRoute, Router, @@ -10,10 +7,12 @@ import { import { AuditService } from 'jslib/abstractions/audit.service'; import { CipherService } from 'jslib/abstractions/cipher.service'; +import { CollectionService } from 'jslib/abstractions/collection.service'; import { FolderService } from 'jslib/abstractions/folder.service'; import { I18nService } from 'jslib/abstractions/i18n.service'; import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; import { StateService } from 'jslib/abstractions/state.service'; +import { UserService } from 'jslib/abstractions/user.service'; import { AddEditComponent as BaseAddEditComponent } from 'jslib/angular/components/add-edit.component'; @@ -21,18 +20,21 @@ import { AddEditComponent as BaseAddEditComponent } from 'jslib/angular/componen selector: 'app-vault-add-edit', templateUrl: 'add-edit.component.html', }) -export class AddEditComponent extends BaseAddEditComponent implements OnInit { +export class AddEditComponent extends BaseAddEditComponent { showAttachments = true; constructor(cipherService: CipherService, folderService: FolderService, i18nService: I18nService, platformUtilsService: PlatformUtilsService, auditService: AuditService, stateService: StateService, + userService: UserService, collectionService: CollectionService, private route: ActivatedRoute, private router: Router, private location: Location) { - super(cipherService, folderService, i18nService, platformUtilsService, auditService, stateService); + super(cipherService, folderService, i18nService, platformUtilsService, auditService, stateService, + userService, collectionService); } - ngOnInit() { + async ngOnInit() { + await super.ngOnInit(); this.showAttachments = !this.platformUtilsService.isEdge(); this.route.queryParams.subscribe(async (params) => { if (params.cipherId) { @@ -84,7 +86,7 @@ export class AddEditComponent extends BaseAddEditComponent implements OnInit { } share() { - this.router.navigate(['/share'], { queryParams: { cipherId: this.cipher.id } }); + this.router.navigate(['/share-cipher'], { queryParams: { cipherId: this.cipher.id } }); } cancel() { diff --git a/src/popup/vault/share.component.html b/src/popup/vault/share.component.html index 526a4c63524..f2a667ccd36 100644 --- a/src/popup/vault/share.component.html +++ b/src/popup/vault/share.component.html @@ -4,46 +4,35 @@
- {{'share' | i18n}} + {{'shareItem' | i18n}}
-
- +
-
- {{'itemInformation' | i18n}} -
-
-
-
- - -
-
-
-
-
-
- {{'organization' | i18n}} -
{{'noOrganizationsList' | i18n}}
-

{{'shareDesc' | i18n}}

-
+
-
+
{{'collections' | i18n}}
@@ -51,13 +40,13 @@ {{'noCollectionsInList' | i18n}}
-
-
- - -
+
+ +
- \ No newline at end of file + diff --git a/src/popup/vault/share.component.ts b/src/popup/vault/share.component.ts index e6c177b8b4d..adb7af57327 100644 --- a/src/popup/vault/share.component.ts +++ b/src/popup/vault/share.component.ts @@ -1,123 +1,35 @@ import { Location } from '@angular/common'; -import { - Component, - EventEmitter, - Input, - OnDestroy, - OnInit, - Output, -} from '@angular/core'; -import { - ActivatedRoute, - Router, -} from '@angular/router'; - -import { ToasterService } from 'angular2-toaster'; -import { Angulartics2 } from 'angulartics2'; +import { Component } from '@angular/core'; +import { ActivatedRoute } from '@angular/router'; import { CipherService } from 'jslib/abstractions/cipher.service'; import { CollectionService } from 'jslib/abstractions/collection.service'; import { I18nService } from 'jslib/abstractions/i18n.service'; -import { UserService } from 'jslib/abstractions/user.service'; -import { AuditService } from 'jslib/abstractions/audit.service'; -import { FolderService } from 'jslib/abstractions/folder.service'; import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; -import { StateService } from 'jslib/abstractions/state.service'; +import { UserService } from 'jslib/abstractions/user.service'; -import { Organization } from 'jslib/models/domain/organization'; -import { CipherView } from 'jslib/models/view/cipherView'; -import { CollectionView } from 'jslib/models/view/collectionView'; +import { ShareComponent as BaseShareComponent } from 'jslib/angular/components/share.component'; @Component({ selector: 'app-vault-share', templateUrl: 'share.component.html', }) -export class ShareComponent implements OnInit, OnDestroy { - formPromise: Promise; - cipher: CipherView; - cipherId: string; - organizationId: string; - collections: CollectionView[] = []; - organizations: Organization[] = []; - - private writeableCollections: CollectionView[] = []; - - constructor(private cipherService: CipherService, private collectionService: CollectionService, - private userService: UserService, private i18nService: I18nService, - private route: ActivatedRoute, private location: Location, - private toasterService: ToasterService, private analytics: Angulartics2) { +export class ShareComponent extends BaseShareComponent { + constructor(collectionService: CollectionService, platformUtilsService: PlatformUtilsService, + i18nService: I18nService, userService: UserService, + cipherService: CipherService, private route: ActivatedRoute, + private location: Location) { + super(collectionService, platformUtilsService, i18nService, userService, cipherService); } async ngOnInit() { this.route.queryParams.subscribe(async (params) => { - if (params.cipherId) { - this.cipherId = params.cipherId; - } + this.cipherId = params.cipherId; + await super.ngOnInit(); }); - - - const cipherDomain = await this.cipherService.get(this.cipherId); - this.cipher = await cipherDomain.decrypt(); - const allCollections = await this.collectionService.getAllDecrypted(); - this.writeableCollections = allCollections.filter((c) => !c.readOnly); - this.organizations = await this.userService.getAllOrganizations(); - if (this.organizationId == null && this.organizations.length > 0) { - this.organizationId = this.organizations[0].id; - } - this.filterCollections(); - } - - ngOnDestroy() { - } - - filterCollections() { - if (this.organizationId == null || this.writeableCollections.length === 0) { - this.collections = []; - } else { - this.collections = this.writeableCollections.filter((c) => c.organizationId === this.organizationId); - } - } - - async submit() { - const cipherDomain = await this.cipherService.get(this.cipherId); - const cipherView = await cipherDomain.decrypt(); - - const attachmentPromises: Array> = []; - if (cipherView.attachments != null) { - for (const attachment of cipherView.attachments) { - const promise = this.cipherService.shareAttachmentWithServer(attachment, - cipherView.id, this.organizationId); - attachmentPromises.push(promise); - } - } - - const checkedCollectionIds = this.collections.filter((c) => (c as any).checked).map((c) => c.id); - try { - this.formPromise = Promise.all(attachmentPromises).then(async () => { - await this.cipherService.shareWithServer(cipherView, this.organizationId, checkedCollectionIds); - this.analytics.eventTrack.next({ action: 'Shared Cipher' }); - this.toasterService.popAsync('success', null, this.i18nService.t('sharedItem')); - }); - await this.formPromise; - } catch { } } cancel() { this.location.back(); } - - check(c: CollectionView, select?: boolean) { - (c as any).checked = select == null ? !(c as any).checked : select; - } - - get canSave() { - if (this.collections != null) { - for (let i = 0; i < this.collections.length; i++) { - if ((this.collections[i] as any).checked) { - return true; - } - } - } - return false; - } }