[SM-520] add secret copy actions (#4887)

This commit is contained in:
Will Martin 2023-02-28 09:29:04 -05:00 committed by GitHub
parent 6adcb35dd7
commit 4e112573f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 79 additions and 4 deletions

View File

@ -57,6 +57,8 @@
(deleteSecretsEvent)="openDeleteSecret($event)"
(newSecretEvent)="openNewSecretDialog()"
(editSecretEvent)="openEditSecret($event)"
(copySecretNameEvent)="copySecretName($event)"
(copySecretValueEvent)="copySecretValue($event)"
[secrets]="view.latestSecrets"
></sm-secrets-list>
<div *ngIf="view.allSecrets.length > 0" class="tw-ml-auto tw-mt-4 tw-max-w-max">

View File

@ -11,7 +11,9 @@ import {
distinct,
} from "rxjs";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { OrganizationService } from "@bitwarden/common/abstractions/organization/organization.service.abstraction";
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
import { DialogService } from "@bitwarden/components";
import { ProjectListView } from "../models/view/project-list.view";
@ -75,7 +77,9 @@ export class OverviewComponent implements OnInit, OnDestroy {
private secretService: SecretService,
private serviceAccountService: ServiceAccountService,
private dialogService: DialogService,
private organizationService: OrganizationService
private organizationService: OrganizationService,
private platformUtilsService: PlatformUtilsService,
private i18nService: I18nService
) {
/**
* We want to remount the `sm-onboarding` component on route change.
@ -222,4 +226,23 @@ export class OverviewComponent implements OnInit, OnDestroy {
},
});
}
copySecretName(name: string) {
this.platformUtilsService.copyToClipboard(name);
this.platformUtilsService.showToast(
"success",
null,
this.i18nService.t("valueCopied", this.i18nService.t("name"))
);
}
async copySecretValue(id: string) {
const secret = await this.secretService.getBySecretId(id);
this.platformUtilsService.copyToClipboard(secret.value);
this.platformUtilsService.showToast(
"success",
null,
this.i18nService.t("valueCopied", this.i18nService.t("value"))
);
}
}

View File

@ -9,6 +9,8 @@
(deleteSecretsEvent)="openDeleteSecret($event)"
(newSecretEvent)="openNewSecretDialog()"
(editSecretEvent)="openEditSecret($event)"
(copySecretNameEvent)="copySecretName($event)"
(copySecretValueEvent)="copySecretValue($event)"
[secrets]="secrets"
></sm-secrets-list>
</ng-container>

View File

@ -2,6 +2,8 @@ import { Component } from "@angular/core";
import { ActivatedRoute } from "@angular/router";
import { combineLatestWith, Observable, startWith, switchMap } from "rxjs";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
import { DialogService } from "@bitwarden/components";
import { SecretListView } from "../../models/view/secret-list.view";
@ -29,7 +31,9 @@ export class ProjectSecretsComponent {
constructor(
private route: ActivatedRoute,
private secretService: SecretService,
private dialogService: DialogService
private dialogService: DialogService,
private platformUtilsService: PlatformUtilsService,
private i18nService: I18nService
) {}
ngOnInit() {
@ -75,4 +79,23 @@ export class ProjectSecretsComponent {
},
});
}
copySecretName(name: string) {
this.platformUtilsService.copyToClipboard(name);
this.platformUtilsService.showToast(
"success",
null,
this.i18nService.t("valueCopied", this.i18nService.t("name"))
);
}
async copySecretValue(id: string) {
const secret = await this.secretService.getBySecretId(id);
this.platformUtilsService.copyToClipboard(secret.value);
this.platformUtilsService.showToast(
"success",
null,
this.i18nService.t("valueCopied", this.i18nService.t("value"))
);
}
}

View File

@ -6,6 +6,8 @@
(deleteSecretsEvent)="openDeleteSecret($event)"
(newSecretEvent)="openNewSecretDialog()"
(editSecretEvent)="openEditSecret($event)"
(copySecretNameEvent)="copySecretName($event)"
(copySecretValueEvent)="copySecretValue($event)"
[secrets]="secrets$ | async"
[search]="search"
></sm-secrets-list>

View File

@ -2,6 +2,8 @@ import { Component, OnInit } from "@angular/core";
import { ActivatedRoute } from "@angular/router";
import { combineLatestWith, Observable, startWith, switchMap } from "rxjs";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
import { DialogService } from "@bitwarden/components";
import { SecretListView } from "../models/view/secret-list.view";
@ -30,7 +32,9 @@ export class SecretsComponent implements OnInit {
constructor(
private route: ActivatedRoute,
private secretService: SecretService,
private dialogService: DialogService
private dialogService: DialogService,
private platformUtilsService: PlatformUtilsService,
private i18nService: I18nService
) {}
ngOnInit() {
@ -78,4 +82,23 @@ export class SecretsComponent implements OnInit {
},
});
}
copySecretName(name: string) {
this.platformUtilsService.copyToClipboard(name);
this.platformUtilsService.showToast(
"success",
null,
this.i18nService.t("valueCopied", this.i18nService.t("name"))
);
}
async copySecretValue(id: string) {
const secret = await this.secretService.getBySecretId(id);
this.platformUtilsService.copyToClipboard(secret.value);
this.platformUtilsService.showToast(
"success",
null,
this.i18nService.t("valueCopied", this.i18nService.t("value"))
);
}
}

View File

@ -97,7 +97,7 @@
<i class="bwi bwi-fw bwi-pencil" aria-hidden="true"></i>
{{ "editSecret" | i18n }}
</button>
<button type="button" bitMenuItem (click)="copySecretNameEvent.emit(secret.id)">
<button type="button" bitMenuItem (click)="copySecretNameEvent.emit(secret.name)">
<i class="bwi bwi-fw bwi-clone" aria-hidden="true"></i>
{{ "copySecretName" | i18n }}
</button>