Skip to content

Commit eddbb6a

Browse files
committed
svelte: Show authenticated owner's email on settings page
Match the Ember app by rendering the logged-in user's email in the owners list when they appear as a crate owner. In Ember this is an emergent side effect of Ember Data's identity map (the `/api/v1/me` response pre-populates the user record with an email, which is preserved when the same user shows up in the owners list). The Svelte app has no such store, so compare `session.currentUser.id` against each owner explicitly. Other owners' email columns remain empty, as the owners API does not expose their addresses. Also add `data-test-email` markers on both apps' email columns and an acceptance test covering the self-only behavior.
1 parent 1c66879 commit eddbb6a

3 files changed

Lines changed: 33 additions & 4 deletions

File tree

app/templates/crate/settings/index.gjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ import UserAvatar from 'crates-io/components/user-avatar';
6262
<LinkTo @route={{team.kind}} @model={{team.login}}>
6363
{{team.display_name}}
6464
</LinkTo>
65-
<div class='email-column'>
65+
<div class='email-column' data-test-email>
6666
{{team.email}}
6767
</div>
6868
<button
@@ -85,7 +85,7 @@ import UserAvatar from 'crates-io/components/user-avatar';
8585
{{user.login}}
8686
{{/if}}
8787
</LinkTo>
88-
<div class='email-column'>
88+
<div class='email-column' data-test-email>
8989
{{user.email}}
9090
</div>
9191
<button

e2e/routes/crate/settings.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,24 @@ test.describe('Route | crate.settings', { tag: '@routes' }, () => {
5858
await expect(page.locator('[data-test-delete-button]')).toBeVisible();
5959
});
6060

61+
test('only the authenticated owner has their email shown in the owners list', async ({ msw, page }) => {
62+
let user1 = await msw.db.user.create({ login: 'authenticated-owner' });
63+
let user2 = await msw.db.user.create({ login: 'other-owner' });
64+
65+
let crate = await msw.db.crate.create({ name: 'foo' });
66+
await msw.db.version.create({ crate });
67+
await msw.db.crateOwnership.create({ crate, user: user1 });
68+
await msw.db.crateOwnership.create({ crate, user: user2 });
69+
70+
await msw.authenticateAs(user1);
71+
72+
await page.goto('/crates/foo/settings');
73+
await expect(page).toHaveURL('/crates/foo/settings');
74+
75+
await expect(page.locator(`[data-test-owner-user="${user1.login}"] [data-test-email]`)).toHaveText(user1.email);
76+
await expect(page.locator(`[data-test-owner-user="${user2.login}"] [data-test-email]`)).toHaveText('');
77+
});
78+
6179
test.describe('Trusted Publishing', () => {
6280
test('mixed GitHub and GitLab configs', async ({ msw, page, percy }) => {
6381
const { crate } = await prepare(msw);

svelte/src/routes/crates/[crate_id]/settings/+page.svelte

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import Tooltip from '$lib/components/Tooltip.svelte';
1313
import UserAvatar from '$lib/components/UserAvatar.svelte';
1414
import { getNotifications } from '$lib/notifications.svelte';
15+
import { getSession } from '$lib/utils/session.svelte';
1516
1617
type Owner = components['schemas']['Owner'];
1718
type GitHubConfig = components['schemas']['GitHubConfig'];
@@ -20,6 +21,7 @@
2021
let { data } = $props();
2122
2223
let notifications = getNotifications();
24+
let session = getSession();
2325
let client = createClient({ fetch });
2426
2527
let addOwnerVisible = $state(false);
@@ -232,7 +234,7 @@
232234
<a {href}>
233235
{teamDisplayName(team)}
234236
</a>
235-
<div class="email-column"></div>
237+
<div class="email-column" data-test-email></div>
236238
<button
237239
type="button"
238240
class="button button--small"
@@ -254,7 +256,16 @@
254256
<a {href}>
255257
{user.name ?? user.login}
256258
</a>
257-
<div class="email-column"></div>
259+
<!--
260+
TODO: Showing only the authenticated user's own email here is a bit
261+
questionable. This matches the Ember.js app's behavior (an emergent
262+
consequence of Ember Data's identity map) and is reproduced here for
263+
parity during the migration. Revisit whether this column should exist
264+
at all once the Svelte app is the primary frontend.
265+
-->
266+
<div class="email-column" data-test-email>
267+
{session.currentUser?.id === user.id ? (session.currentUser?.email ?? '') : ''}
268+
</div>
258269
<button
259270
type="button"
260271
class="button button--small"

0 commit comments

Comments
 (0)