Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Update sharing tests and static translation strings (#2536)
Leendert de Borst50482d25f393
diff --git a/apps/web/tests/e2e/70-sharing.spec.ts b/apps/web/tests/e2e/70-sharing.spec.tsindex bfb0ef061..f992f8aaf 100644--- a/apps/web/tests/e2e/70-sharing.spec.ts+++ b/apps/web/tests/e2e/70-sharing.spec.ts@@ -2,20 +2,43 @@* Category 70: Vault sharing between two clients (requires API)*/import { test, expect } from '../fixtures';-import { createSharedGroup, createTestUser, enableCapability } from '../helpers/test-api';+import { createTestUser, enableCapability } from '../helpers/test-api';++import type { WebApp } from '../fixtures/WebApp';++/**+ * The viewer's own identity code, shown on the settings overview.+ */+async function ownIdentityCode(app: WebApp): Promise<string> {+ await app.openSettings();+ const code = (await app.page.locator('#own-identity-code').innerText()).trim();+ expect(code).toMatch(/^\d{4}-\d{4}-\d{4}-\d{4}-\d{4}$/);+ return code;+}++/**+ * Create a top-level personal folder in the vault and open it.+ */+async function createFolder(app: WebApp, name: string): Promise<void> {+ await app.openVault();+ await app.page.locator('#new-folder-button').click();+ await app.page.locator('#folder-name').fill(name);+ await app.page.locator('#folder-name').press('Enter');+ await app.openFolder(name);+}test.describe('70. Sharing', () => {- test('70.1 should show an item created in a shared vault to the invited member', async ({ app: owner, newApp, apiUrl }) => {+ test('70.1 should share an existing folder by inviting someone with their code, then share another folder without it', async ({ app: owner, newApp, apiUrl }) => {test.slow();- const vaultName = 'E2E shared vault';+ const folderName = 'Household';+ const renamedFolderName = 'Household shared';+ const secondFolderName = 'Streaming';const itemName = 'Shared item';+ const laterItemName = 'Later item';const ownerUser = await createTestUser(apiUrl);const memberUser = await createTestUser(apiUrl);- let groupId = '';- let manifestId = '';- await test.step('set up the group and its sharing capability on the server', async () => {- groupId = await createSharedGroup(apiUrl, 'E2E family', ownerUser.username, [memberUser.username]);+ await test.step('enable the sharing capability on the server', async () => {await enableCapability(apiUrl, ownerUser.username, 'vault-sharing');await enableCapability(apiUrl, memberUser.username, 'vault-sharing');});@@ -26,52 +49,149 @@ test.describe('70. Sharing', () => {await member.login(memberUser.username, memberUser.password);});- await test.step('the owner creates a shared vault', async () => {- await owner.openFamilySharing();- await owner.page.locator(`#new-vault-name-${groupId}`).fill(vaultName);- await owner.page.getByRole('button', { name: 'Create', exact: true }).click();- await expect(owner.page.getByRole('link', { name: vaultName })).toBeVisible();+ await test.step('the owner has a personal folder with an item in it', async () => {+ await createFolder(owner, folderName);+ await owner.createItem(itemName);+ await owner.openFolder(folderName);+ await expect(owner.page.getByText(itemName, { exact: true })).toBeVisible();+ });++ let memberCode = '';+ await test.step('inviting from the folder\'s people dialog shares it first; a wrong code and the own code are refused', async () => {+ memberCode = await ownIdentityCode(member);+ const ownerCode = await ownIdentityCode(owner);+ await owner.openFolder(folderName);+ await owner.page.locator('#folder-people').click();+ await expect(owner.page.getByText('Invite people to share this folder with them.', { exact: false })).toBeVisible();+ // The folder stays personal until the first invitation goes out; the wizard asks for the code first.+ await owner.page.locator('#invite-someone-new').click();+ const wrongCode = `${memberCode.slice(0, -1)}${memberCode.endsWith('0') ? '1' : '0'}`;+ await owner.page.locator('#invite-wizard-code').fill(wrongCode);+ await owner.page.locator('#invite-wizard-next').click();+ await expect(owner.page.getByText('No account has this code.', { exact: false })).toBeVisible();+ await owner.page.locator('#invite-wizard-code').fill(ownerCode);+ await owner.page.locator('#invite-wizard-next').click();+ await expect(owner.page.getByText('This is your own code.', { exact: false })).toBeVisible();await owner.pause();});- await test.step('the owner invites the member', async () => {- await owner.page.getByRole('listitem').filter({ hasText: memberUser.username }).getByRole('button', { name: 'Invite' }).click();- await expect(owner.page.getByText(`Invitation sent to ${memberUser.username}.`)).toBeVisible();+ await test.step('the owner invites the member with their identity code', async () => {+ await owner.page.locator('#invite-wizard-code').fill(memberCode);+ await owner.page.locator('#invite-wizard-next').click();+ await expect(owner.page.getByText(`You are about to share “${folderName}” with ${memberUser.username}.`, { exact: false })).toBeVisible();+ await owner.page.locator('#invite-wizard-confirm').click();+ await expect(owner.page.getByText('Next step: share your code')).toBeVisible();+ await expect(owner.page.locator('#invite-wizard-close')).toBeEnabled({ timeout: 5000 });+ await owner.page.locator('#invite-wizard-close').click();+ await expect(owner.page.locator(`[data-person="${memberUser.username}"]`)).toContainText('Invited');+ await owner.page.getByRole('button', { name: 'Close' }).click();+ await expect(owner.page.getByText(itemName, { exact: true })).toBeVisible();await owner.pause();});- await test.step('the member accepts the invitation', async () => {- await member.openFamilySharing();- await expect(member.page.getByText(vaultName, { exact: true })).toBeVisible();- await member.page.getByRole('button', { name: 'Accept' }).click();- await expect(member.page.getByRole('link', { name: vaultName })).toBeVisible();+ await test.step('the member sees the invitation in their folder list and accepts it with the owner\'s code', async () => {+ const ownerCode = await ownIdentityCode(owner);+ await member.openVault();+ await expect(async () => {+ await member.page.getByRole('button', { name: 'Refresh' }).click();+ await expect(member.page.locator('[data-invitation]')).toBeVisible({ timeout: 2000 });+ }).toPass({ timeout: 30000 });+ await member.page.locator('[data-invitation]').click();+ await expect(member.page.getByText(`${ownerUser.username} shared “${folderName}” with you`)).toBeVisible();+ await member.page.locator('#accept-invitation').click();+ await expect(member.page.getByText(`Confirm the invitation from ${ownerUser.username}`)).toBeVisible();+ const wrongCode = `${ownerCode.slice(0, -1)}${ownerCode.endsWith('0') ? '1' : '0'}`;+ await member.page.locator('#inviter-code').fill(wrongCode);+ await member.page.locator('#accept-invitation').click();+ await expect(member.page.getByText('This code is not correct.', { exact: false })).toBeVisible();+ await member.page.locator('#inviter-code').fill(ownerCode);+ await member.page.locator('#accept-invitation').click();+ await expect(member.page).toHaveURL(/\/items\/folder\//);+ await expect(member.page.getByText(itemName, { exact: true })).toBeVisible();await member.pause();});- await test.step('the owner creates an item in the shared vault', async () => {- await owner.page.getByRole('link', { name: vaultName }).click();- await expect(owner.page).toHaveURL(/\/items\/folder\/[0-9a-f-]{36}\/[0-9a-f-]{36}$/);- manifestId = owner.page.url().split('/').at(-2) ?? '';- await owner.createItem(itemName);- expect(owner.page.url()).toContain(`/items/${manifestId}/`);- await owner.pause();+ await test.step('the owner renames the shared folder and adds an item, which the member sees', async () => {+ await owner.openFolder(folderName);+ await owner.page.getByTitle('Edit Folder').click();+ await owner.page.locator('#folder-name').fill(renamedFolderName);+ await owner.page.locator('#folder-name').press('Enter');+ await owner.createItem(laterItemName);++ await expect(async () => {+ await member.openVault();+ await member.page.getByRole('button', { name: 'Refresh' }).click();+ await expect(member.page.getByRole('button', { name: renamedFolderName })).toBeVisible({ timeout: 2000 });+ }).toPass({ timeout: 30000 });+ await member.openFolder(renamedFolderName);+ await expect(member.page.getByText(laterItemName, { exact: true })).toBeVisible();+ await member.pause();});- await test.step('the member sees the item after pulling', async () => {- await member.page.getByRole('link', { name: vaultName }).click();- await expect(member.page).toHaveURL(new RegExp(`/items/folder/${manifestId}/`));+ await test.step('a second folder goes to the verified member without a code', async () => {+ await createFolder(owner, secondFolderName);+ await owner.page.locator('#folder-people').click();+ // Somebody verified before is picked in the wizard instead of entering their code.+ await owner.page.locator('#invite-someone-new').click();+ await owner.page.locator(`[data-person-option="${memberUser.username}"]`).click();+ await owner.page.locator('#invite-wizard-next').click();+ await expect(owner.page.getByText(`You are about to share “${secondFolderName}” with ${memberUser.username}.`, { exact: false })).toBeVisible();+ await owner.page.locator('#invite-wizard-confirm').click();+ await expect(owner.page.locator('#invite-wizard-close')).toBeEnabled({ timeout: 5000 });+ await owner.page.locator('#invite-wizard-close').click();+ await expect(owner.page.getByText(`Invitation sent to ${memberUser.username}.`)).toBeVisible();+ await expect(owner.page.locator(`[data-person="${memberUser.username}"]`)).toContainText('Invited');+ await owner.page.getByRole('button', { name: 'Close' }).click();+await expect(async () => {+ await member.openVault();await member.page.getByRole('button', { name: 'Refresh' }).click();- await expect(member.page.getByText(itemName, { exact: true })).toBeVisible({ timeout: 2000 });+ await expect(member.page.locator('[data-invitation]')).toBeVisible({ timeout: 2000 });}).toPass({ timeout: 30000 });+ await member.page.locator('[data-invitation]').click();+ await expect(member.page.getByText(`Invited by ${ownerUser.username} (verified)`)).toBeVisible();+ await member.page.locator('#accept-invitation').click();+ await expect(member.page).toHaveURL(/\/items\/folder\//);+ await expect(member.page.locator('#inviter-code')).toHaveCount(0);await member.pause();});- await test.step('the item opens in the shared vault for the member', async () => {- await member.page.getByText(itemName, { exact: true }).click();- await member.expectItemView(itemName);- expect(member.page.url()).toContain(`/items/${manifestId}/`);+ await test.step('the member leaves the first folder with their master password and loses it', async () => {+ await member.openFolder(renamedFolderName);+ await member.page.locator('#folder-people').click();+ await member.page.getByRole('button', { name: 'Leave folder' }).click();+ await member.page.locator('#confirmButton').click();+ await member.page.locator('#password-confirm').fill(memberUser.password);+ await member.page.getByRole('button', { name: 'Confirm' }).click();+ await member.openVault();+ await expect(member.page.getByRole('button', { name: renamedFolderName })).toHaveCount(0);+ await expect(member.page.getByRole('button', { name: secondFolderName })).toBeVisible();await member.pause();});++ await test.step('with nobody else left, the first folder is personal again by itself and keeps its items', async () => {+ await owner.openFolder(renamedFolderName);+ await owner.page.locator('#folder-people').click();+ // The page moves from the shared folder (manifest id twice) to the personal folder it turned back into.+ await expect(owner.page).not.toHaveURL(/\/items\/folder\/([0-9a-f-]{36})\/\1$/, { timeout: 15000 });+ await expect(owner.page.getByText('Invite people to share this folder with them.', { exact: false })).toBeVisible();+ await owner.page.getByRole('button', { name: 'Close' }).click();+ await expect(owner.page.getByText(itemName, { exact: true })).toBeVisible();+ await expect(owner.page.getByText(laterItemName, { exact: true })).toBeVisible();+ await owner.pause();+ });++ await test.step('removing the last other person from the second folder makes it personal again', async () => {+ await owner.openFolder(secondFolderName);+ await owner.page.locator('#folder-people').click();+ await owner.page.getByRole('listitem').filter({ hasText: memberUser.username }).getByRole('button', { name: 'Remove access' }).click();+ await owner.page.locator('#confirmButton').click();+ await owner.page.locator('#password-confirm').fill(ownerUser.password);+ await owner.page.getByRole('button', { name: 'Confirm' }).click();+ await expect(owner.page).not.toHaveURL(/\/items\/folder\/([0-9a-f-]{36})\/\1$/, { timeout: 15000 });+ await expect(owner.page.getByText('Invite people to share this folder with them.', { exact: false })).toBeVisible();+ await owner.page.getByRole('button', { name: 'Close' }).click();+ await owner.pause();+ });});});diff --git a/core/client/src/sharing/FamilySharingView.ts b/core/client/src/sharing/FamilySharingView.tsindex 60c44866a..004d7e9d8 100644--- a/core/client/src/sharing/FamilySharingView.ts+++ b/core/client/src/sharing/FamilySharingView.ts@@ -1,65 +1,92 @@-import type { GroupInfo, GroupMemberInfo, SentManifestInvitation, SharedManifestInfo } from '@aliasvault/models/webapi';+import type { GroupInfo, GroupMemberInfo, GroupOverviewResponse, ReceivedManifestInvitation, SentManifestInvitation, SharedManifestInfo } from '@aliasvault/models/webapi';/**- * What the family sharing screen shows and offers, generic and used by multiple clients.+ * What the shared folders screen shows and offers, generic and used by multiple clients.*//**- * Maximum length of a shared vault name in UTF-16 code units. Invitations carry the name RSA-OAEP encrypted, which fits at+ * Maximum length of a shared manifest name in UTF-16 code units. Invitations carry the name RSA-OAEP encrypted, which fits at* most 190 UTF-8 bytes; one code unit takes at most 3 bytes, so 60 fits in any script.*/export const MAX_SHARED_VAULT_NAME_LENGTH = 60;/**- * The family sharing screen's text strings, in English only on purpose (temporary) as the UI is pending changes+ * The shared folders screen's text strings, in English only on purpose (temporary) as the UI is pending changes* so we don't let the translation platform see this yet until its finalized. TODO: move these strings to locale files.*/export const familySharingText = {- title: 'Family Sharing',- beta: 'Beta',- description: 'Share vaults with the people in your family.',- notAvailable: 'Family sharing is not enabled for this account yet. Once a family has been set up for you, it appears here.',- invitations: 'Invitations',+ /** Title of the people dialog of a folder. */+ peopleTitle: 'People with access',+ /** Shown in the people dialog of a folder that is not shared yet. */+ shareFolderHint: 'Invite people to share this folder with them. Everyone you invite can see, change and delete its items.',+ /** A pending invitation shown in the folder list. */+ invitationPending: 'Invitation',+ /** Title of the dialog of an invitation to a shared folder. */+ sharedWithYou: (username: string, folder: string): string => `${username} shared “${folder}” with you`,+ sharedWithYouHint: 'Accept to see this folder and everything in it in your vault.',+ yourCodeSettingsHint: 'Someone who shares a folder with you needs this code to invite you. It is not secret.',+ /** Title of the step that asks for the inviter's code before accepting. */+ inviterCodeTitle: (username: string): string => `Confirm the invitation from ${username}`,+ /** Explains why the inviter's code is asked for. */+ inviterCodeExplanation: (username: string): string => `For your security, enter the code of ${username}. It confirms that this invitation really comes from them. ${username} finds it in Settings on their device.`,+ /** Who sent an invitation, whose key this account verified before. */+ invitedByVerified: (username: string): string => `Invited by ${username} (verified)`,/** Who sent an invitation. */invitedBy: (username: string): string => `Invited by ${username}`,+ invitePeople: 'Invite someone',+ /** Shown with this account's code while an invitation waits for an answer. */+ pendingCodeTip: 'Tip: looking for your code to send to the people you invited? Here it is:',+ notSharedYet: 'This folder is not shared with anyone yet. Invite someone to start sharing it.',+ inviteWizardChooseTitle: 'Who do you want to invite?',+ inviteWizardNewCodeTitle: 'Or invite someone new with their code',+ inviteWizardCodeTitle: 'Enter the code of the person you invite',+ inviteWizardCodeHint: 'Ask the person to copy their code from Settings and send it to you. The code creates a secure link between your accounts. You only need to do this once per person.',+ inviteWizardConfirmTitle: 'Confirm the invitation',+ /** Asks to confirm who a personal folder is shared with, which makes it a shared folder. */+ inviteWizardConfirmShare: (username: string, folder: string): string => `You are about to share “${folder}” with ${username}. They can see, change and delete everything in it.`,+ /** Asks to confirm who is invited to a shared folder. */+ inviteWizardConfirmFolder: (username: string, folder: string): string => `You are about to invite ${username} to “${folder}”.`,+ /** Confirms the invitation went out. */+ inviteWizardInvited: (username: string): string => `${username} has been invited`,+ inviteWizardNextStep: 'Next step: share your code',+ /** Asks to send this account's own code to the person invited. */+ inviteWizardShareHint: (username: string): string => `Send this code to ${username}. They need to enter it to accept your invitation.`,+ inviteWizardShareNotSecret: 'This code is not secret. It only confirms that the invitation comes from you, so you can send it by email or in a chat app, or type it in by hand.',+ /** A close button that is enabled after a short countdown. */+ closeCountdown: (seconds: number): string => `Close (${seconds})`,+ codePlaceholder: '1234-5678-9012-3456-7890',+ yourCode: 'Your code',accept: 'Accept',decline: 'Decline',- members: 'Family members',owner: 'Owner',admin: 'Admin',member: 'Member',you: 'You',- noSharedVaultAdmin: 'This family has no shared vault yet. Once created, it shows up as a folder for every member you invite.',- noSharedVaultMember: 'Nobody has created a shared vault for this family yet.',- createSharedVault: 'Create a new shared vault',- sharedVault: 'Shared vault',- sharedVaults: 'Shared vaults',- sharedVaultsHint: 'Each shared vault you have access to shows up as a folder in your vault. Everything you put in that folder is shared with its members.',- hasAccess: 'Has access',+ /** Progress line of the create shared folder wizard. */+ wizardStep: (step: number, total: number): string => `Step ${step} of ${total}`,+ wizardCreating: 'Creating the shared folder and sending the invitations...',+ sharedVault: 'Shared folder',invited: 'Invited',- noAccess: 'No access',- revoke: 'Revoke',+ revoke: 'Remove access',withdraw: 'Withdraw',invite: 'Invite',- create: 'Create',- leaveVault: 'Leave vault',- /** Confirmation for leaving a shared vault. */- leaveVaultConfirm: (vault: string): string => `Leave “${vault}”? You lose access to it, but stay in the family.`,- cannotInviteWithoutAccess: 'You do not have access to this vault, so you cannot invite anyone to it. Ask a member who has access to invite you first.',- vaultName: 'Vault name',- vaultNamePlaceholder: 'Vault name, for example Streaming',- renameVault: 'Rename vault',+ leaveVault: 'Leave folder',+ /** Confirmation for leaving a shared folder. */+ leaveVaultConfirm: (vault: string): string => `Leave “${vault}”? You lose access to it right away.`,/** Notice after an invitation was sent. */invitationSent: (username: string): string => `Invitation sent to ${username}.`,/** Confirmation for taking a member's access away. */- revokeAccessConfirm: (username: string, vault: string): string => `Take ${username} out of “${vault}”? They lose access to it right away, but stay in the family.`,- revokeAccessWarning: 'They may have already seen or copied the passwords in it. Change any you do not want them to keep using.',- deleteVault: 'Delete vault',- /** Confirmation for deleting a shared vault. */- deleteVaultConfirm: (vault: string): string => `Permanently delete “${vault}”? Every member of the family loses this vault and everything in it. This cannot be undone.`,- /** Password prompt for deleting a shared vault. */- deleteVaultPasswordPrompt: (vault: string): string => `Enter your master password to confirm deleting “${vault}” for the whole family.`,- vaultDeleted: 'The shared vault has been deleted.',+ revokeAccessConfirm: (username: string, vault: string): string => `Take ${username} out of “${vault}”? They lose access to it right away.`,+ deleteVault: 'Delete folder',+ /** Confirmation for deleting a shared folder. */+ deleteVaultConfirm: (vault: string): string => `Permanently delete “${vault}”? Everyone with access loses this folder and everything in it. This cannot be undone.`,+ /** Password prompt for taking a member's access to a shared folder away. */+ revokeAccessPasswordPrompt: (username: string, vault: string): string => `Enter your master password to confirm taking ${username} out of “${vault}”.`,+ /** Password prompt for leaving a shared folder. */+ leaveVaultPasswordPrompt: (vault: string): string => `Enter your master password to confirm leaving “${vault}”.`,+ /** Password prompt for deleting a shared folder. */+ deleteVaultPasswordPrompt: (vault: string): string => `Enter your master password to confirm deleting “${vault}” for everyone.`,+ vaultDeleted: 'The shared folder has been deleted.',/** An item's email alias that receives its emails in another place than the item's own vault or shared folder. */aliasOwner: {inPersonalVault: 'This email alias receives its emails in your personal vault.',@@ -72,37 +99,34 @@ export const familySharingText = {moveToPersonalVaultConfirm: (email: string): string => `From now on, new emails for ${email} go to your personal vault, where only you can read them. Emails received before stay where they are.`,},errors: {- loadFailed: 'Family sharing could not be loaded.',- createVaultFailed: 'The shared vault could not be created. Please try again.',- vaultUpgradeRequired: 'Your vault has to finish upgrading before it can be shared.',+ createVaultFailed: 'The shared folder could not be created. Please try again.',+ vaultUpgradeRequired: 'Your vault has to finish upgrading before you can share folders.',revokeAccessFailed: 'The access could not be changed. Please try again.',inviteFailed: 'The invitation could not be sent. Please try again.',- userNotReady: 'That account has to finish upgrading AliasVault before a vault can be shared with it.',+ userNotReady: 'That account has to finish upgrading AliasVault before a folder can be shared with it.',alreadyInvited: 'That person has already been invited.',invitationGone: 'That invitation is no longer available.',- invitationKeyOutdated: "This invitation is no longer valid because the shared vault's key has changed. Ask for a new invitation.",- notFamilyMember: 'That person is not in this family.',- alreadyHasAccess: 'That person already has access to this vault.',- lastMemberWithAccess: 'Somebody has to be able to open the shared vault. Give another member access to it first.',- vaultLimitReached: 'Max amount of shared vaults reached.',- deleteVaultFailed: 'The shared vault could not be deleted. Please try again.',- aliasOwnedByOtherFolder: 'This email alias receives its emails in a shared folder you cannot open, or in the personal vault of another family member. Ask them to move it here.',+ invitationKeyOutdated: "This invitation is no longer valid because the shared folder's key has changed. Ask for a new invitation.",+ alreadyHasAccess: 'That person already has access to this folder.',+ lastMemberWithAccess: 'Somebody has to be able to open the shared folder. Give someone else access to it first.',+ deleteVaultFailed: 'The shared folder could not be deleted. Please try again.',+ codeNotFound: 'No account has this code. Check the code and try again.',+ codeRateLimited: 'Too many codes were looked up. Please try again later.',+ codeIsOwn: 'This is your own code. Enter the code of the other person instead.',+ codeMismatch: 'This code is not correct. Ask the other person for their correct code.',+ inviterNotVerified: 'First enter the code of the person who invited you.',+ memberNotVerified: 'First invite this person with their code under Invite someone new.',+ aliasOwnedByOtherFolder: 'This email alias receives its emails in a shared folder you cannot open, or in the personal vault of someone else. Ask them to move it here.',},};/**- * One member's access status and current user's available actions on it.+ * What the viewer can do about one member of a shared folder.*/export type MemberAccess = {isSelf: boolean;- hasAccess: boolean;- invitation: SentManifestInvitation | null;- statusText: string;canLeave: boolean;canRevoke: boolean;- canWithdraw: boolean;- canInvite: boolean;- isReadyForInvite: boolean;};/**@@ -114,40 +138,49 @@ export function canAdministerGroup(group: Pick<GroupInfo, 'role'>): boolean {}/**- * Whether this account can delete the group, which only its owner may do.- * @param group - the group as served by the API.+ * `text` split around the first occurrence of `value`, so a screen can render `value` emphasized; `value` is empty when absent.+ * @param text - the full text.+ * @param value - the part to emphasize, such as a username.*/-export function canDeleteGroup(group: Pick<GroupInfo, 'role'>): boolean {- return group.role === 'owner';+export function splitAround(text: string, value: string): [before: string, value: string, after: string] {+ const index = value ? text.indexOf(value) : -1;+ return index < 0 ? [text, '', ''] : [text.slice(0, index), value, text.slice(index + value.length)];}/**- * Whether this account can leave the group. The owner cannot: they delete it once it is empty instead.- * @param group - the group as served by the API.+ * One shared folder: a shared manifest with the group of people it is shared with.*/-export function canLeaveGroup(group: Pick<GroupInfo, 'role'>): boolean {- return !canDeleteGroup(group);-}+export type SharedFolder = { group: GroupInfo; manifest: SharedManifestInfo };/**- * What the family sharing screen shows of an overview: the viewer's user id, the one family they are in (the one they- * own, else the one they joined; a user is in one family at a time for now), the invitations to join a family (only- * shown outside one, as joining a second family is not offered) and the invitations to shared manifests of families- * the overview does not list.+ * What the sharing screen shows of an overview: the viewer's user id, the shared folders (each with its own group,+ * members sorted), the invitations waiting for an answer, and the people verified before.* @param overview - the overview as served by the API.*/-export function familyView(overview: GroupOverviewResponse | null): { myUserId: string; group: GroupInfo | null; joinInvitations: ReceivedGroupInvitation[]; orphanInvitations: ReceivedManifestInvitation[] } {- const allGroups = overview?.groups ?? [];- const group = allGroups.find(candidate => candidate.role === 'owner') ?? allGroups[0] ?? null;- const receivedInvitations = overview?.receivedInvitations ?? [];+export function sharingView(overview: GroupOverviewResponse | null): { myUserId: string; folders: SharedFolder[]; invitations: ReceivedManifestInvitation[]; verifiedPeople: GroupMemberInfo[] } {+ const folders = (overview?.groups ?? []).flatMap(group => {+ const sorted = { ...group, members: sortMembers(group.members) };+ return group.manifests.map(manifest => ({ group: sorted, manifest }));+ });return {myUserId: overview?.userId ?? '',- group,- joinInvitations: group ? [] : overview?.receivedGroupInvitations ?? [],- orphanInvitations: receivedInvitations.filter(invitation => !allGroups.some(candidate => candidate.groupId.toLowerCase() === invitation.groupId.toLowerCase())),+ folders,+ invitations: overview?.receivedInvitations ?? [],+ verifiedPeople: [...(overview?.verifiedPeople ?? [])].sort((a, b) => a.username.localeCompare(b.username, undefined, { sensitivity: 'base' })),};}+/** The order roles are listed in: the owner first, then admins, then members. */+const ROLE_ORDER: Record<GroupMemberInfo['role'], number> = { owner: 0, admin: 1, member: 2 };++/**+ * Members sorted by role (owner, admins, members), then alphabetically by username within each role.+ * @param members - the members as served by the API.+ */+function sortMembers<T extends Pick<GroupMemberInfo, 'role' | 'username'>>(members: T[]): T[] {+ return [...members].sort((a, b) => (ROLE_ORDER[a.role] ?? 3) - (ROLE_ORDER[b.role] ?? 3) || a.username.localeCompare(b.username, undefined, { sensitivity: 'base' }));+}+/*** Whether this account certified the inviter's key before, so the invitation takes no code.* @param invitation - the invitation as served by the API.@@ -157,9 +190,9 @@ export function isInviterVerified(invitation: Pick<ReceivedManifestInvitation, '}/**- * Why a member cannot be handed a manifest key yet, or null when they can: the admin has not certified their key with- * their family code, or their account has no keys yet.- * @param member - the member as served by the API to an admin.+ * Why a person cannot be handed a manifest key yet, or null when they can: their key is not certified, or their account+ * has no keys yet.+ * @param member - the person as served by the API.*/export function memberKeyProblem(member: Pick<GroupMemberInfo, 'accountPublicKey' | 'signingPublicKey' | 'keyCertification'>): string | null {if (!member.accountPublicKey || !member.signingPublicKey) {@@ -169,65 +202,58 @@ export function memberKeyProblem(member: Pick<GroupMemberInfo, 'accountPublicKey}/**- * The notice after inviting by family code: the account was invited, or was a member already and is now verified.- * @param result - what the invite operation reported.+ * Whether the viewer holds a grant on the manifest. Inviting encrypts the manifest's key for somebody else, which+ * an administrator without a grant of their own cannot do.+ * @param manifest - the shared manifest.+ * @param ownUserId - the viewer's user id.*/-export function inviteByCodeNotice(result: { username?: string | null; alreadyMember?: boolean }): string {- const invitee = result.username ?? '';- return result.alreadyMember ? familySharingText.memberVerified(invitee) : familySharingText.familyInvitationSent(invitee);+export function holdsManifestKey(manifest: Pick<SharedManifestInfo, 'memberUserIds'>, ownUserId: string): boolean {+ return manifest.memberUserIds.includes(ownUserId);}/**- * Whether the group is empty enough to be deleted: no shared manifests left and no other members.- * @param group - the group as served by the API.+ * The people verified before who are not in the folder and have no open invitation to it, so they can be invited.+ * @param folder - the shared folder.+ * @param verifiedPeople - the people verified before.*/-export function isGroupDeletable(group: Pick<GroupInfo, 'manifests' | 'members'>): boolean {- return group.manifests.length === 0 && group.members.length === 1;+export function invitablePeople(folder: SharedFolder, verifiedPeople: GroupMemberInfo[]): GroupMemberInfo[] {+ return verifiedPeople.filter(person => !folder.group.members.some(member => member.userId === person.userId) && !folder.manifest.pendingInvitations.some(invitation => invitation.inviteeUserId === person.userId));}/**- * Whether the viewer may take a member out of the group: admins remove anyone but themselves and the owner.- * @param group - the group as served by the API.- * @param member - the member.+ * Whether anybody besides the viewer is in a shared folder or invited to it. A shared folder without anybody else is+ * personal again: its owner's client turns it back into a personal folder.+ * @param folder - the shared folder.* @param ownUserId - the viewer's user id.*/-export function canRemoveMember(group: Pick<GroupInfo, 'role'>, member: Pick<GroupMemberInfo, 'userId' | 'role'>, ownUserId: string): boolean {- return canAdministerGroup(group) && member.userId !== ownUserId && member.role !== 'owner';+export function hasOtherPeople(folder: SharedFolder, ownUserId: string): boolean {+ return folder.group.members.some(member => member.userId !== ownUserId) || folder.manifest.pendingInvitations.length > 0;}/**- * Whether the viewer holds a grant on the manifest. Inviting encrypts the manifest's key for somebody else, which- * an administrator without a grant of their own cannot do.- * @param manifest - the shared manifest.- * @param ownUserId - the viewer's user id.+ * The open invitations to a shared folder for people outside its group, who join it when they accept.+ * @param folder - the shared folder.*/-export function holdsManifestKey(manifest: Pick<SharedManifestInfo, 'memberUserIds'>, ownUserId: string): boolean {- return manifest.memberUserIds.includes(ownUserId);+export function pendingInvitees(folder: SharedFolder): SentManifestInvitation[] {+ return folder.manifest.pendingInvitations.filter(invitation => !folder.group.members.some(member => member.userId === invitation.inviteeUserId));}/**- * One member's access status and current user's available actions on it.+ * What the viewer can do about one member: a member leaves, an administrator takes another member's access away.* @param group - the group the manifest belongs to.* @param manifest - the shared manifest.* @param member - the member being described.* @param ownUserId - the viewer's user id.*/-export function describeMemberAccess(group: GroupInfo, manifest: SharedManifestInfo, member: GroupMemberInfo, ownUserId: string): MemberAccess {+export function describeMemberAccess(group: Pick<GroupInfo, 'role'>, manifest: Pick<SharedManifestInfo, 'memberUserIds'>, member: Pick<GroupMemberInfo, 'userId'>, ownUserId: string): MemberAccess {const isSelf = member.userId === ownUserId;const isAdmin = canAdministerGroup(group);const hasAccess = manifest.memberUserIds.includes(member.userId);- const invitation = manifest.pendingInvitations.find(candidate => candidate.inviteeUserId === member.userId) ?? null;return {isSelf,- hasAccess,- invitation,- statusText: hasAccess ? familySharingText.hasAccess : invitation ? familySharingText.invited : familySharingText.noAccess,canLeave: hasAccess && isSelf && !isAdmin,canRevoke: hasAccess && !isSelf && isAdmin,- canWithdraw: invitation !== null && !isSelf && isAdmin,- canInvite: !hasAccess && invitation === null && !isSelf && isAdmin && holdsManifestKey(manifest, ownUserId),- isReadyForInvite: memberKeyProblem(member) === null,};}@@ -251,13 +277,18 @@ export function roleLabel(member: Pick<GroupMemberInfo, 'role'>): string {export function sharingErrorMessage(apiErrorCode: string | null | undefined): string | null {switch (apiErrorCode) {case 'INVITE_RECIPIENT_NOT_READY': return familySharingText.errors.userNotReady;- case 'NOT_GROUP_MEMBER': return familySharingText.errors.notFamilyMember;case 'ACCESS_ALREADY_GRANTED': return familySharingText.errors.alreadyHasAccess;case 'INVITATION_ALREADY_EXISTS': return familySharingText.errors.alreadyInvited;case 'INVITATION_NOT_FOUND': return familySharingText.errors.invitationGone;case 'INVITATION_KEY_OUTDATED': return familySharingText.errors.invitationKeyOutdated;case 'LAST_MANIFEST_GRANT_HOLDER': return familySharingText.errors.lastMemberWithAccess;- case 'GROUP_MANIFEST_LIMIT_REACHED': return familySharingText.errors.vaultLimitReached;+ case 'SHARED_MANIFEST_IN_USE': return familySharingText.errors.revokeAccessFailed;+ case 'IDENTITY_CODE_NOT_FOUND': return familySharingText.errors.codeNotFound;+ case 'RATE_LIMIT_EXCEEDED': return familySharingText.errors.codeRateLimited;+ case 'MEMBER_NOT_VERIFIED': return familySharingText.errors.memberNotVerified;+ case 'INVITER_NOT_VERIFIED': return familySharingText.errors.inviterNotVerified;+ case 'IDENTITY_CODE_MISMATCH': return familySharingText.errors.codeMismatch;+ case 'IDENTITY_CODE_IS_OWN': return familySharingText.errors.codeIsOwn;default: return null;}}diff --git a/core/i18n/locales/en.json b/core/i18n/locales/en.jsonindex 5b8c7154b..8eb1ae60d 100644--- a/core/i18n/locales/en.json+++ b/core/i18n/locales/en.json@@ -328,6 +328,7 @@"saving": "Saving...","serviceName": "Service Name","settings": "Settings",+ "share": "Share","show": "Show","showDetails": "Show details","showPassword": "Show password",