forked from bitwarden/clients
-
Notifications
You must be signed in to change notification settings - Fork 6
[VER-355] feat: Add Profile migration Alert and move all Profiles to trash after some delay #169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
98a3fe9
feat: Add `Profile` migration Alert
Ldoppea df03fb8
feat: Compute and store deadline for `Profile` migration
Ldoppea a678031
feat: Trash `Profiles` after deadline
Ldoppea c2671f0
feat: Remove `Profiles` sections
Ldoppea 93d31bd
feat: Open "more details" link on `Profile` migration alert
Ldoppea cd30543
feat: Prevent to restore `Profiles`
Ldoppea a7fa2b3
feat: Do not call profile-migration component if no Profile exists
Ldoppea b2b0839
fix: Restore ability to delete items
Ldoppea File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
apps/browser/src/cozy/components/profiles-migration/profiles-migration.component.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <div class="profileMigration" *ngIf="ready && profilesCount > 0"> | ||
| <div class="alert"> | ||
| <div class="alert-icon cozy-icon-info"></div> | ||
| <div class="alert-message"> | ||
| <div class="alert-title">{{ "profileMigrationTitle" | i18n }}</div> | ||
| <div>{{ "profileMigrationContent" | i18n: deadline:remaining:profilesCount }}</div> | ||
| </div> | ||
| <div class="alert-action"> | ||
| <button type="button" class="btn link" (click)="moreInfo()"> | ||
| {{ "profileMigrationAction" | i18n }} | ||
| </button> | ||
| </div> | ||
| </div> | ||
| </div> | ||
79 changes: 79 additions & 0 deletions
79
apps/browser/src/cozy/components/profiles-migration/profiles-migration.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| /* eslint-disable no-console */ | ||
| import { Component, Input, OnInit } from "@angular/core"; | ||
| /* eslint-disable import/no-duplicates */ | ||
| import addDays from "date-fns/addDays"; | ||
| import formatDistanceToNowStrict from "date-fns/formatDistanceToNowStrict"; | ||
| import isAfter from "date-fns/isAfter"; | ||
| import fr from "date-fns/locale/fr"; | ||
|
|
||
| import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; | ||
| import { StateService } from "@bitwarden/common/abstractions/state.service"; | ||
| import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service"; | ||
| import { CipherType } from "@bitwarden/common/vault/enums/cipher-type"; | ||
|
|
||
| const DELAY_IN_DAYS = 15; | ||
|
|
||
| @Component({ | ||
| selector: "app-profiles-migration", | ||
| templateUrl: "profiles-migration.component.html", | ||
| }) | ||
| export class ProfilesMigrationComponent implements OnInit { | ||
| @Input() profilesCount: number; | ||
| remaining: string; | ||
| deadline: string; | ||
| ready = false; | ||
| constructor( | ||
| protected cipherService: CipherService, | ||
| protected i18nService: I18nService, | ||
| protected stateService: StateService | ||
| ) {} | ||
|
|
||
| async ngOnInit() { | ||
| let cleanDeadline = await this.stateService.getProfilesCleanDeadline(); | ||
|
|
||
| if (!cleanDeadline) { | ||
| cleanDeadline = addDays(new Date(), DELAY_IN_DAYS); | ||
| this.stateService.setProfilesCleanDeadline(cleanDeadline); | ||
| } | ||
|
|
||
| this.deadline = cleanDeadline.toLocaleDateString(); | ||
| this.remaining = formatDistanceToNowStrict(cleanDeadline, { | ||
| // @ts-expect-error I did not succeed in getting i18nService.translationLocale so I fallback to a private property | ||
| locale: this.i18nService.systemLanguage === "fr" ? fr : undefined, | ||
| unit: "day", | ||
| }); | ||
|
|
||
| const didClean = await this.handleDeadline(cleanDeadline); | ||
|
|
||
| if (!didClean) { | ||
| this.ready = true; | ||
| } | ||
| } | ||
|
|
||
| protected async handleDeadline(deadline: Date) { | ||
| if (!isAfter(new Date(), deadline)) { | ||
| return false; | ||
| } | ||
|
|
||
| try { | ||
| const allCiphers = await this.cipherService.getAllDecrypted(); | ||
|
|
||
| for (const cipher of allCiphers) { | ||
| if (cipher.type === CipherType.Identity && !cipher.isDeleted) { | ||
| await this.cipherService.softDeleteWithServer(cipher.id); | ||
| } | ||
| } | ||
| } catch (err) { | ||
| console.log("Error while trying to delete Profiles", err); | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| moreInfo() { | ||
| const infoUrl = | ||
| "https://support.cozy.io/394-comment-puis-je-parametrer-mon-gestionnaire-de-mot-de-passe/"; | ||
| window.open(infoUrl); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| .profileMigration { | ||
| @include themify($themes) { | ||
| background-color: themed("backgroundColorAlt"); | ||
| } | ||
| padding: 16px; | ||
|
|
||
| .alert { | ||
| @include themify($themes) { | ||
| background-color: change-color(themed("warningColor"), $alpha: 0.12); | ||
| } | ||
| display: flex; | ||
| flex-wrap: wrap; | ||
|
|
||
| padding: 8px 16px; | ||
|
|
||
| border-radius: 8px; | ||
|
|
||
| .alert-icon { | ||
| display: flex; | ||
|
|
||
| height: 16px; | ||
| width: 16px; | ||
|
|
||
| margin-right: 12px; | ||
| margin-top: 9px; | ||
| padding: 7px 0; | ||
|
|
||
| font-size: 22px; | ||
|
|
||
| @include themify($themes) { | ||
| background-color: themed("warningColor"); | ||
| color: themed("warningColor"); | ||
| } | ||
| } | ||
|
|
||
| .alert-message { | ||
| display: flex; | ||
| flex-wrap: wrap; | ||
| flex: auto; | ||
| align-items: center; | ||
|
|
||
| max-width: calc(100% - 28px); | ||
|
|
||
| padding: 8px 0; | ||
|
|
||
| .alert-title { | ||
| width: 100%; | ||
|
|
||
| margin-bottom: 0.35em; | ||
| margin-top: -2px; | ||
|
|
||
| font-weight: bold; | ||
| } | ||
| } | ||
|
|
||
| .alert-action { | ||
| display: block; | ||
|
|
||
| width: 100%; | ||
|
|
||
| margin-left: auto; | ||
| margin-right: -6px; | ||
| padding-left: 0; | ||
|
|
||
| text-align: right; | ||
| text-transform: uppercase; | ||
|
|
||
| .btn.link { | ||
| @include themify($themes) { | ||
| color: themed("warningColor") !important; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.