2018-04-05 21:35:56 +02:00
|
|
|
import { Component, EventEmitter, Input, Output } from "@angular/core";
|
|
|
|
|
2021-06-07 19:25:37 +02:00
|
|
|
import { CipherRepromptType } from "jslib-common/enums/cipherRepromptType";
|
|
|
|
import { CipherType } from "jslib-common/enums/cipherType";
|
|
|
|
import { EventType } from "jslib-common/enums/eventType";
|
2018-04-05 21:35:56 +02:00
|
|
|
|
2021-06-07 19:25:37 +02:00
|
|
|
import { CipherView } from "jslib-common/models/view/cipherView";
|
2018-04-05 21:35:56 +02:00
|
|
|
|
2021-06-07 19:25:37 +02:00
|
|
|
import { EventService } from "jslib-common/abstractions/event.service";
|
|
|
|
import { I18nService } from "jslib-common/abstractions/i18n.service";
|
|
|
|
import { PasswordRepromptService } from "jslib-common/abstractions/passwordReprompt.service";
|
|
|
|
import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service";
|
2022-01-27 22:22:51 +01:00
|
|
|
import { StateService } from "jslib-common/abstractions/state.service";
|
2021-06-07 19:25:37 +02:00
|
|
|
import { TotpService } from "jslib-common/abstractions/totp.service";
|
2018-04-05 21:35:56 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: "app-action-buttons",
|
2018-04-06 17:48:45 +02:00
|
|
|
templateUrl: "action-buttons.component.html",
|
2018-04-05 21:35:56 +02:00
|
|
|
})
|
|
|
|
export class ActionButtonsComponent {
|
|
|
|
@Output() onView = new EventEmitter<CipherView>();
|
2021-01-27 22:45:54 +01:00
|
|
|
@Output() launchEvent = new EventEmitter<CipherView>();
|
2018-04-05 21:35:56 +02:00
|
|
|
@Input() cipher: CipherView;
|
2018-04-06 20:03:35 +02:00
|
|
|
@Input() showView = false;
|
2018-04-05 21:35:56 +02:00
|
|
|
|
|
|
|
cipherType = CipherType;
|
2020-12-15 17:26:01 +01:00
|
|
|
userHasPremiumAccess = false;
|
2018-04-05 21:35:56 +02:00
|
|
|
|
2021-12-07 20:42:18 +01:00
|
|
|
constructor(
|
|
|
|
private i18nService: I18nService,
|
2021-04-14 23:43:09 +02:00
|
|
|
private platformUtilsService: PlatformUtilsService,
|
|
|
|
private eventService: EventService,
|
2021-05-03 20:56:38 +02:00
|
|
|
private totpService: TotpService,
|
2022-01-27 22:22:51 +01:00
|
|
|
private stateService: StateService,
|
2021-05-03 20:56:38 +02:00
|
|
|
private passwordRepromptService: PasswordRepromptService
|
|
|
|
) {}
|
2018-04-05 21:35:56 +02:00
|
|
|
|
2020-12-15 17:26:01 +01:00
|
|
|
async ngOnInit() {
|
2022-01-27 22:22:51 +01:00
|
|
|
this.userHasPremiumAccess = await this.stateService.getCanAccessPremium();
|
2020-12-15 17:26:01 +01:00
|
|
|
}
|
2020-12-17 18:06:31 +01:00
|
|
|
|
2021-01-27 22:45:54 +01:00
|
|
|
launchCipher() {
|
|
|
|
this.launchEvent.emit(this.cipher);
|
2018-04-05 21:35:56 +02:00
|
|
|
}
|
|
|
|
|
2020-12-15 17:26:01 +01:00
|
|
|
async copy(cipher: CipherView, value: string, typeI18nKey: string, aType: string) {
|
2021-05-04 19:04:18 +02:00
|
|
|
if (
|
|
|
|
this.cipher.reprompt !== CipherRepromptType.None &&
|
|
|
|
this.passwordRepromptService.protectedFields().includes(aType) &&
|
|
|
|
!(await this.passwordRepromptService.showPasswordPrompt())
|
|
|
|
) {
|
2021-05-03 20:56:38 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-01-08 15:48:48 +01:00
|
|
|
if (value == null || (aType === "TOTP" && !this.displayTotpCopyButton(cipher))) {
|
2018-04-05 21:35:56 +02:00
|
|
|
return;
|
2020-12-15 17:26:01 +01:00
|
|
|
} else if (value === cipher.login.totp) {
|
|
|
|
value = await this.totpService.getCode(value);
|
2018-04-05 21:35:56 +02:00
|
|
|
}
|
|
|
|
|
2020-05-24 19:59:49 +02:00
|
|
|
if (!cipher.viewPassword) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-13 15:44:59 +02:00
|
|
|
this.platformUtilsService.copyToClipboard(value, { window: window });
|
2021-12-07 20:42:18 +01:00
|
|
|
this.platformUtilsService.showToast(
|
|
|
|
"info",
|
|
|
|
null,
|
2018-04-05 21:35:56 +02:00
|
|
|
this.i18nService.t("valueCopied", this.i18nService.t(typeI18nKey))
|
|
|
|
);
|
2019-07-12 21:00:20 +02:00
|
|
|
|
2020-12-15 17:26:01 +01:00
|
|
|
if (typeI18nKey === "password" || typeI18nKey === "verificationCodeTotp") {
|
2019-07-12 21:00:20 +02:00
|
|
|
this.eventService.collect(EventType.Cipher_ClientToggledHiddenFieldVisible, cipher.id);
|
|
|
|
} else if (typeI18nKey === "securityCode") {
|
|
|
|
this.eventService.collect(EventType.Cipher_ClientCopiedCardCode, cipher.id);
|
2018-04-05 21:35:56 +02:00
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
2018-04-05 21:35:56 +02:00
|
|
|
|
2020-12-15 17:26:01 +01:00
|
|
|
displayTotpCopyButton(cipher: CipherView) {
|
|
|
|
return (
|
|
|
|
(cipher?.login?.hasTotp ?? false) && (cipher.organizationUseTotp || this.userHasPremiumAccess)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-04-05 21:35:56 +02:00
|
|
|
view() {
|
|
|
|
this.onView.emit(this.cipher);
|
|
|
|
}
|
|
|
|
}
|