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.

Fix: the connected apps list called token issue time "last used"

Damian Legawiec8cba32e097c2
diff --git a/packages/admin-sdk/src/types/generated/OauthApplication.ts b/packages/admin-sdk/src/types/generated/OauthApplication.ts
index 98dc340931..7fc2f74285 100644
--- a/packages/admin-sdk/src/types/generated/OauthApplication.ts
+++ b/packages/admin-sdk/src/types/generated/OauthApplication.ts
@@ -1,4 +1,4 @@
-// Typelizer digest 563d9fb82d6fd499c593eb219262f5a3
+// Typelizer digest b23eb8b9833e0f3b8e67ee33fdfca25b
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
@@ -10,7 +10,7 @@ interface OauthApplication {
updated_at: string;
client_id: string;
scopes: Array<string>;
- last_used_at: string | null;
+ last_authorized_at: string | null;
authorized_at: string | null;
authorized_by: string | null;
}
diff --git a/packages/admin-sdk/src/zod/generated/OauthApplication.ts b/packages/admin-sdk/src/zod/generated/OauthApplication.ts
index e9c6813195..ce682c2d64 100644
--- a/packages/admin-sdk/src/zod/generated/OauthApplication.ts
+++ b/packages/admin-sdk/src/zod/generated/OauthApplication.ts
@@ -9,7 +9,7 @@ export const OauthApplicationSchema = z.object({
updated_at: z.string(),
client_id: z.string(),
scopes: z.array(z.string()),
- last_used_at: z.string().nullable(),
+ last_authorized_at: z.string().nullable(),
authorized_at: z.string().nullable(),
authorized_by: z.string().nullable(),
});
diff --git a/packages/dashboard/src/locales/ar.json b/packages/dashboard/src/locales/ar.json
index e053b8dd44..515f67ba16 100644
--- a/packages/dashboard/src/locales/ar.json
+++ b/packages/dashboard/src/locales/ar.json
@@ -4130,8 +4130,8 @@
"table": {
"name": "التطبيق",
"access": "الوصول",
- "last_used": "آخر استخدام",
- "authorized_by": "وافق عليه"
+ "authorized_by": "وافق عليه",
+ "last_authorized": "آخر تفويض"
},
"revoke_confirm": {
"title": "إلغاء الوصول؟",
diff --git a/packages/dashboard/src/locales/de.json b/packages/dashboard/src/locales/de.json
index a82933b1a2..4f16008732 100644
--- a/packages/dashboard/src/locales/de.json
+++ b/packages/dashboard/src/locales/de.json
@@ -4102,8 +4102,8 @@
"table": {
"name": "Anwendung",
"access": "Zugriff",
- "last_used": "Zuletzt verwendet",
- "authorized_by": "Genehmigt von"
+ "authorized_by": "Genehmigt von",
+ "last_authorized": "Letzte Autorisierung"
},
"revoke_confirm": {
"title": "Zugriff widerrufen?",
diff --git a/packages/dashboard/src/locales/en.json b/packages/dashboard/src/locales/en.json
index 2b94f8439b..9aebb01a0a 100644
--- a/packages/dashboard/src/locales/en.json
+++ b/packages/dashboard/src/locales/en.json
@@ -4102,8 +4102,8 @@
"table": {
"name": "Application",
"access": "Access",
- "last_used": "Last used",
- "authorized_by": "Approved by"
+ "authorized_by": "Approved by",
+ "last_authorized": "Last authorized"
},
"revoke_confirm": {
"title": "Revoke access?",
diff --git a/packages/dashboard/src/locales/es.json b/packages/dashboard/src/locales/es.json
index 04cdd731fb..8061d86112 100644
--- a/packages/dashboard/src/locales/es.json
+++ b/packages/dashboard/src/locales/es.json
@@ -728,8 +728,8 @@
"table": {
"name": "Aplicación",
"access": "Acceso",
- "last_used": "Último uso",
- "authorized_by": "Aprobado por"
+ "authorized_by": "Aprobado por",
+ "last_authorized": "Última autorización"
},
"revoke_confirm": {
"title": "¿Revocar el acceso?",
diff --git a/packages/dashboard/src/locales/fr.json b/packages/dashboard/src/locales/fr.json
index bf72ac8c96..c0890afff3 100644
--- a/packages/dashboard/src/locales/fr.json
+++ b/packages/dashboard/src/locales/fr.json
@@ -4102,8 +4102,8 @@
"table": {
"name": "Application",
"access": "Accès",
- "last_used": "Dernière utilisation",
- "authorized_by": "Autorisé par"
+ "authorized_by": "Autorisé par",
+ "last_authorized": "Dernière autorisation"
},
"revoke_confirm": {
"title": "Révoquer l’accès ?",
diff --git a/packages/dashboard/src/locales/pl.json b/packages/dashboard/src/locales/pl.json
index 5addaef24f..d4027d15c2 100644
--- a/packages/dashboard/src/locales/pl.json
+++ b/packages/dashboard/src/locales/pl.json
@@ -4156,8 +4156,8 @@
"table": {
"name": "Aplikacja",
"access": "Dostęp",
- "last_used": "Ostatnio użyta",
- "authorized_by": "Zatwierdzone przez"
+ "authorized_by": "Zatwierdzone przez",
+ "last_authorized": "Ostatnia autoryzacja"
},
"revoke_confirm": {
"title": "Odebrać dostęp?",
diff --git a/packages/dashboard/src/locales/zh-CN.json b/packages/dashboard/src/locales/zh-CN.json
index c7d148ebf4..b40dbcf2b9 100644
--- a/packages/dashboard/src/locales/zh-CN.json
+++ b/packages/dashboard/src/locales/zh-CN.json
@@ -4092,8 +4092,8 @@
"table": {
"name": "应用",
"access": "访问权限",
- "last_used": "上次使用",
- "authorized_by": "批准人"
+ "authorized_by": "批准人",
+ "last_authorized": "最后授权时间"
},
"revoke_confirm": {
"title": "撤销访问权限?",
diff --git a/packages/dashboard/src/tables/oauth-applications.tsx b/packages/dashboard/src/tables/oauth-applications.tsx
index 92366b463e..1f817c9da0 100644
--- a/packages/dashboard/src/tables/oauth-applications.tsx
+++ b/packages/dashboard/src/tables/oauth-applications.tsx
@@ -40,10 +40,10 @@ defineTable<OauthApplication>('oauth-applications', {
),
},
{
- key: 'last_used_at',
- label: i18n.t('admin.pages.settings.connected_apps.table.last_used'),
+ key: 'last_authorized_at',
+ label: i18n.t('admin.pages.settings.connected_apps.table.last_authorized'),
default: true,
- render: (application) => <RelativeTime iso={application.last_used_at} />,
+ render: (application) => <RelativeTime iso={application.last_authorized_at} />,
},
],
})
diff --git a/spree/api/app/serializers/spree/api/v3/admin/oauth_application_serializer.rb b/spree/api/app/serializers/spree/api/v3/admin/oauth_application_serializer.rb
index ef2ae5c53f..758b4803d9 100644
--- a/spree/api/app/serializers/spree/api/v3/admin/oauth_application_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/admin/oauth_application_serializer.rb
@@ -9,14 +9,14 @@ module Spree
# secret is null here anyway, because every MCP client is a public
# client that proves itself with PKCE instead.
#
- # `scopes` and `last_used_at` come from the live tokens rather than
+ # `scopes` and `last_authorized_at` come from the live tokens rather than
# the registration — a client is registered once and granted per
# consent, so what the merchant approved lives on the token.
class OauthApplicationSerializer < V3::BaseSerializer
typelize name: :string,
client_id: :string,
scopes: [:string, multi: true],
- last_used_at: [:string, nullable: true],
+ last_authorized_at: [:string, nullable: true],
authorized_at: [:string, nullable: true],
authorized_by: [:string, nullable: true],
redirect_uri: [:string, nullable: true]
@@ -29,8 +29,8 @@ module Spree
application.live_token_scopes
end
- attribute :last_used_at do |application|
- application.last_used_at&.iso8601
+ attribute :last_authorized_at do |application|
+ application.last_authorized_at&.iso8601
end
attribute :authorized_at do |application|
diff --git a/spree/core/app/models/spree/oauth_application.rb b/spree/core/app/models/spree/oauth_application.rb
index 74cffce822..9e0eb75054 100644
--- a/spree/core/app/models/spree/oauth_application.rb
+++ b/spree/core/app/models/spree/oauth_application.rb
@@ -46,10 +46,15 @@ module Spree
live_access_tokens.flat_map { |token| token.scopes.to_a }.uniq.sort
end
- # When this application was last granted a token that still works.
+ # When this application last obtained a token that still works.
+ #
+ # Not the last call it made: a token is minted once and then used for
+ # hours, and nothing records a call. Reporting this as "last used" would
+ # let a merchant read an actively running agent as idle, which is the
+ # opposite of what the connected-apps screen is for.
#
# @return [ActiveSupport::TimeWithZone, nil]
- def last_used_at
+ def last_authorized_at
live_access_tokens.map(&:created_at).max
end