Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Changed the consent screen to the shared permission grid

Damian Legawiecd8ffcb975e2e
diff --git a/packages/dashboard/src/components/spree/permission-picker.tsx b/packages/dashboard/src/components/spree/permission-picker.tsx
index 3592423fa7..4170c34c16 100644
--- a/packages/dashboard/src/components/spree/permission-picker.tsx
+++ b/packages/dashboard/src/components/spree/permission-picker.tsx
@@ -85,6 +85,8 @@ export function PermissionGrid({
onChange,
disabled = false,
disabledKeys,
+ className,
+ bare = false,
}: {
entries: Permission[]
value: string[]
@@ -93,6 +95,13 @@ export function PermissionGrid({
disabled?: boolean
/** Keys the caller may not grant (beyond their own) — rendered disabled. */
disabledKeys?: Set<string>
+ /** Extra classes for the grid's outer frame. */
+ className?: string
+ /**
+ * Drops the frame and the horizontal padding, for a caller that already
+ * draws both — a card section rather than a field inside a form.
+ */
+ bare?: boolean
}) {
const { t } = useTranslation()
const rows = buildPermissionRows(entries)
@@ -111,15 +120,28 @@ export function PermissionGrid({
}
return (
- <div className={cn('flex flex-col rounded-md border border-border', disabled && 'opacity-70')}>
- <div className="grid grid-cols-[1fr_auto_auto] items-center gap-x-6 gap-y-2 p-3 text-sm">
+ <div
+ className={cn(
+ 'flex flex-col',
+ !bare && 'rounded-md border border-border',
+ disabled && 'opacity-70',
+ className,
+ )}
+ >
+ <div
+ className={cn(
+ 'grid grid-cols-[1fr_auto_auto] items-center gap-x-6 gap-y-2 p-3 text-sm',
+ // A caller drawing its own frame pads the frame, not the grid.
+ bare && 'px-0',
+ )}
+ >
<span className="font-medium text-muted-foreground">
{t('admin.permissions.grid.resource_header')}
</span>
- <span className="w-12 text-center font-medium text-muted-foreground">
+ <span className="w-16 whitespace-nowrap text-center font-medium text-muted-foreground">
{t('admin.permissions.grid.read_header')}
</span>
- <span className="w-12 text-center font-medium text-muted-foreground">
+ <span className="w-16 whitespace-nowrap text-center font-medium text-muted-foreground">
{t('admin.permissions.grid.write_header')}
</span>
diff --git a/packages/dashboard/src/locales/ar.json b/packages/dashboard/src/locales/ar.json
index 515f67ba16..ce6990677b 100644
--- a/packages/dashboard/src/locales/ar.json
+++ b/packages/dashboard/src/locales/ar.json
@@ -4193,7 +4193,7 @@
"title": "ترخيص التطبيق",
"subtitle": "راجع ما يطلبه هذا التطبيق قبل السماح له.",
"intro": "يريد {{client}} الوصول إلى هذا المتجر بالنيابة عنك. ولن يتمكن إلا من تنفيذ ما تسمح به أدناه، ولن يتجاوز أبدًا ما تسمح به صلاحياتك.",
- "permissions_heading": "سيسمح له ذلك بما يلي",
+ "permissions_heading": "الأذونات",
"revoke_hint": "يمكنك إلغاء ذلك في أي وقت من الإعدادات ← التطبيقات المتصلة.",
"approve": "السماح بالوصول",
"deny": "إلغاء",
diff --git a/packages/dashboard/src/locales/de.json b/packages/dashboard/src/locales/de.json
index 4f16008732..f32b544578 100644
--- a/packages/dashboard/src/locales/de.json
+++ b/packages/dashboard/src/locales/de.json
@@ -4165,7 +4165,7 @@
"title": "Anwendung autorisieren",
"subtitle": "Prüfen Sie, was diese Anwendung anfordert, bevor Sie sie zulassen.",
"intro": "{{client}} möchte in Ihrem Namen auf diesen Shop zugreifen. Die Anwendung kann nur das tun, was Sie unten zulassen, und niemals mehr als Ihre eigenen Berechtigungen erlauben.",
- "permissions_heading": "Damit darf die Anwendung",
+ "permissions_heading": "Berechtigungen",
"revoke_hint": "Sie können dies jederzeit unter Einstellungen → Verbundene Apps widerrufen.",
"approve": "Zugriff erlauben",
"deny": "Abbrechen",
diff --git a/packages/dashboard/src/locales/en.json b/packages/dashboard/src/locales/en.json
index 9aebb01a0a..fb11cff903 100644
--- a/packages/dashboard/src/locales/en.json
+++ b/packages/dashboard/src/locales/en.json
@@ -4165,7 +4165,7 @@
"title": "Authorize application",
"subtitle": "Review what this application is asking for before you allow it.",
"intro": "{{client}} wants access to this store on your behalf. It will be able to do only what you allow below, and never more than your own permissions allow.",
- "permissions_heading": "This will allow it to",
+ "permissions_heading": "Permissions",
"revoke_hint": "You can revoke this at any time under Settings → Connected apps.",
"approve": "Allow access",
"deny": "Cancel",
diff --git a/packages/dashboard/src/locales/es.json b/packages/dashboard/src/locales/es.json
index 8061d86112..75d8cf8b3e 100644
--- a/packages/dashboard/src/locales/es.json
+++ b/packages/dashboard/src/locales/es.json
@@ -1057,7 +1057,7 @@
"title": "Autorizar aplicación",
"subtitle": "Revise lo que pide esta aplicación antes de permitirla.",
"intro": "{{client}} quiere acceder a esta tienda en su nombre. Solo podrá hacer lo que usted permita a continuación, y nunca más de lo que permitan sus propios permisos.",
- "permissions_heading": "Esto le permitirá",
+ "permissions_heading": "Permisos",
"revoke_hint": "Puede revocarlo en cualquier momento en Configuración → Aplicaciones conectadas.",
"approve": "Permitir acceso",
"deny": "Cancelar",
diff --git a/packages/dashboard/src/locales/fr.json b/packages/dashboard/src/locales/fr.json
index c0890afff3..2492e36e08 100644
--- a/packages/dashboard/src/locales/fr.json
+++ b/packages/dashboard/src/locales/fr.json
@@ -4165,7 +4165,7 @@
"title": "Autoriser l’application",
"subtitle": "Vérifiez ce que cette application demande avant de l’autoriser.",
"intro": "{{client}} souhaite accéder à cette boutique en votre nom. Elle ne pourra faire que ce que vous autorisez ci-dessous, et jamais plus que vos propres autorisations ne le permettent.",
- "permissions_heading": "Cela lui permettra de",
+ "permissions_heading": "Autorisations",
"revoke_hint": "Vous pouvez révoquer cet accès à tout moment dans Paramètres → Applications connectées.",
"approve": "Autoriser l’accès",
"deny": "Annuler",
diff --git a/packages/dashboard/src/locales/pl.json b/packages/dashboard/src/locales/pl.json
index d4027d15c2..0b13b8a0ae 100644
--- a/packages/dashboard/src/locales/pl.json
+++ b/packages/dashboard/src/locales/pl.json
@@ -4219,7 +4219,7 @@
"title": "Autoryzuj aplikację",
"subtitle": "Sprawdź, o co prosi ta aplikacja, przed udzieleniem zgody.",
"intro": "{{client}} chce uzyskać dostęp do tego sklepu w Twoim imieniu. Będzie mogła robić tylko to, na co zezwolisz poniżej, i nigdy więcej, niż pozwalają Twoje własne uprawnienia.",
- "permissions_heading": "Pozwoli jej to",
+ "permissions_heading": "Uprawnienia",
"revoke_hint": "Możesz odebrać dostęp w dowolnym momencie w Ustawienia → Połączone aplikacje.",
"approve": "Zezwól na dostęp",
"deny": "Anuluj",
diff --git a/packages/dashboard/src/locales/zh-CN.json b/packages/dashboard/src/locales/zh-CN.json
index b40dbcf2b9..2993f1c1f3 100644
--- a/packages/dashboard/src/locales/zh-CN.json
+++ b/packages/dashboard/src/locales/zh-CN.json
@@ -4155,7 +4155,7 @@
"title": "授权应用",
"subtitle": "在允许之前,请查看此应用请求的权限。",
"intro": "{{client}} 希望代表您访问此店铺。它只能执行您在下方允许的操作,且绝不会超出您自己的权限范围。",
- "permissions_heading": "这将允许它",
+ "permissions_heading": "权限",
"revoke_hint": "您可以随时在“设置 → 已连接的应用”中撤销。",
"approve": "允许访问",
"deny": "取消",
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/oauth/authorize.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/oauth/authorize.tsx
index 47b2896c47..93bf547725 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/oauth/authorize.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/oauth/authorize.tsx
@@ -5,15 +5,18 @@ import {
Button,
Card,
CardContent,
- Checkbox,
+ CardDescription,
+ CardFooter,
+ CardHeader,
+ CardTitle,
+ ScrollArea,
Skeleton,
} from '@spree/dashboard-ui'
-import { ShieldIcon } from '@spree/dashboard-ui/icons'
import { createFileRoute } from '@tanstack/react-router'
-import { useId, useState } from 'react'
+import { useMemo, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { z } from 'zod'
-import { permissionKeyLabel } from '../../../../components/spree/permission-picker'
+import { PermissionGrid, permissionKeyLabel } from '../../../../components/spree/permission-picker'
import {
useApproveOauthAuthorization,
useDenyOauthAuthorization,
@@ -50,19 +53,28 @@ function OauthAuthorizePage() {
// hand over — pre-ticked, because the client asked for them and declining
// one should be a deliberate act rather than the default.
const [granted, setGranted] = useState<string[] | null>(null)
- const scopeFieldId = useId()
const grantable = data?.grantable_scopes ?? []
const withheld = (data?.scopes ?? []).filter((key) => !grantable.includes(key))
const selected = granted ?? grantable
- const toggle = (key: string) =>
- setSelected(selected.includes(key) ? selected.filter((k) => k !== key) : [...selected, key])
-
function setSelected(next: string[]) {
setGranted(next)
}
const { data: catalog } = usePermissionCatalog()
+
+ // Only the resources this request touches. The grid builds its rows from
+ // whatever catalog entries it is handed, so narrowing the entries narrows
+ // the screen — the merchant sees what was asked for, not the whole catalog.
+ const requestedEntries = useMemo(() => {
+ const requested = new Set(data?.scopes ?? [])
+ return (catalog?.data ?? []).filter((entry) => requested.has(entry.key))
+ }, [catalog?.data, data?.scopes])
+
+ // Asked for but not this person's to give. Rendered disabled rather than
+ // hidden, so the merchant can see the client wanted it and that they could
+ // not hand it over.
+ const withheldKeys = useMemo(() => new Set(withheld), [withheld])
const approve = useApproveOauthAuthorization()
const deny = useDenyOauthAuthorization()
@@ -115,7 +127,15 @@ function OauthAuthorizePage() {
{error ? null : (
<Card>
- <CardContent className="flex flex-col gap-6 pt-6">
+ {isLoading || !data ? null : (
+ <CardHeader>
+ <CardTitle>{t('admin.pages.oauth.authorize.permissions_heading')}</CardTitle>
+ <CardDescription>
+ {t('admin.pages.oauth.authorize.intro', { client: data.client_name })}
+ </CardDescription>
+ </CardHeader>
+ )}
+ <CardContent className="flex flex-col gap-4">
{isLoading || !data ? (
<div className="flex flex-col gap-3">
<Skeleton className="h-5 w-48" />
@@ -124,39 +144,25 @@ function OauthAuthorizePage() {
</div>
) : (
<>
- <div className="flex items-start gap-3">
- <ShieldIcon className="mt-0.5 size-5 shrink-0 text-muted-foreground" />
- <p className="text-sm">
- {t('admin.pages.oauth.authorize.intro', { client: data.client_name })}
- </p>
- </div>
-
<div className="flex flex-col gap-3">
- <h2 className="font-medium text-sm">
- {t('admin.pages.oauth.authorize.permissions_heading')}
- </h2>
- {/* Each one is a choice, not a notice: a merchant can hand
- over less than the client asked for, and the grant is
- whatever they leave ticked. Labelled client-side so the
- one screen that says what is being granted follows the
- merchant's own language, not the server's. */}
- <ul className="flex flex-col gap-2">
- {grantable.map((key) => (
- <li key={key}>
- <label
- htmlFor={`${scopeFieldId}-${key}`}
- className="flex cursor-pointer items-start gap-2 text-sm"
- >
- <Checkbox
- id={`${scopeFieldId}-${key}`}
- checked={selected.includes(key)}
- onCheckedChange={() => toggle(key)}
- />
- <span>{permissionKeyLabel(t, catalog?.data, key)}</span>
- </label>
- </li>
- ))}
- </ul>
+ {/* The same grid the role editor and API-key picker use, so
+ a merchant reads one layout everywhere permissions are
+ granted. Narrowed to what the client asked for: showing
+ the whole catalog would invite ticking a permission the
+ client never requested, which the server would then cut
+ from the grant anyway.
+
+ Capped in height so the decision buttons stay in view
+ however much was asked for. */}
+ <ScrollArea className="-mx-6 max-h-96 border-border border-y px-6 [&_[data-slot=scroll-area-scrollbar]]:opacity-100">
+ <PermissionGrid
+ entries={requestedEntries}
+ value={selected}
+ onChange={setSelected}
+ disabledKeys={withheldKeys}
+ bare
+ />
+ </ScrollArea>
{/* Asked for but not this person's to give — saying so is
better than silently dropping it, because the agent will
behave as though it has them. */}
@@ -171,7 +177,7 @@ function OauthAuthorizePage() {
) : null}
</div>
- <Alert>
+ <Alert variant="info">
<AlertDescription>
{t('admin.pages.oauth.authorize.revoke_hint')}
</AlertDescription>
@@ -182,21 +188,19 @@ function OauthAuthorizePage() {
<AlertDescription>{decisionError}</AlertDescription>
</Alert>
) : null}
-
- <div className="flex gap-3">
- <Button
- disabled={pending || selected.length === 0}
- onClick={() => decide(approve)}
- >
- {t('admin.pages.oauth.authorize.approve')}
- </Button>
- <Button variant="outline" disabled={pending} onClick={() => decide(deny)}>
- {t('admin.pages.oauth.authorize.deny')}
- </Button>
- </div>
</>
)}
</CardContent>
+ {isLoading || !data ? null : (
+ <CardFooter className="gap-3">
+ <Button disabled={pending || selected.length === 0} onClick={() => decide(approve)}>
+ {t('admin.pages.oauth.authorize.approve')}
+ </Button>
+ <Button variant="outline" disabled={pending} onClick={() => decide(deny)}>
+ {t('admin.pages.oauth.authorize.deny')}
+ </Button>
+ </CardFooter>
+ )}
</Card>
)}
</div>