From 0adb7685f63924bf61ba67ea8d79a8c9498b9a35 Mon Sep 17 00:00:00 2001 From: Carter Date: Fri, 12 Jan 2024 12:55:51 -0800 Subject: [PATCH] Refactor scopes to use Intl for labels and descriptions (#1570) * Refactor scope labels for applications and pats * move scopes to composables * Refactor pages to use intl * Fix merge error * Extract messages --- composables/auth/scopes.ts | 675 ++++++++++++++++++++++++++++++ locales/en-US/index.json | 255 +++++++++++ pages/auth/authorize.vue | 6 +- pages/settings/applications.vue | 12 +- pages/settings/authorizations.vue | 15 +- pages/settings/pats.vue | 11 +- utils/auth/scopes.ts | 346 --------------- 7 files changed, 959 insertions(+), 361 deletions(-) create mode 100644 composables/auth/scopes.ts delete mode 100644 utils/auth/scopes.ts diff --git a/composables/auth/scopes.ts b/composables/auth/scopes.ts new file mode 100644 index 000000000..13b043ce5 --- /dev/null +++ b/composables/auth/scopes.ts @@ -0,0 +1,675 @@ +export const scopeMessages = defineMessages({ + userReadEmailLabel: { + id: 'scopes.userReadEmail.label', + defaultMessage: 'Read user email', + }, + userReadEmailDescription: { + id: 'scopes.userReadEmail.description', + defaultMessage: 'Read your email', + }, + userReadLabel: { + id: 'scopes.userRead.label', + defaultMessage: 'Read user data', + }, + userReadDescription: { + id: 'scopes.userRead.description', + defaultMessage: 'Access your public profile information', + }, + userWriteLabel: { + id: 'scopes.userWrite.label', + defaultMessage: 'Write user data', + }, + userWriteDescription: { + id: 'scopes.userWrite.description', + defaultMessage: 'Write to your profile', + }, + userDeleteLabel: { + id: 'scopes.userDelete.label', + defaultMessage: 'Delete your account', + }, + userDeleteDescription: { + id: 'scopes.userDelete.description', + defaultMessage: 'Delete your account', + }, + userAuthWriteLabel: { + id: 'scopes.userAuthWrite.label', + defaultMessage: 'Write auth data', + }, + userAuthWriteDescription: { + id: 'scopes.userAuthWrite.description', + defaultMessage: 'Modify your authentication data', + }, + notificationReadLabel: { + id: 'scopes.notificationRead.label', + defaultMessage: 'Read notifications', + }, + notificationReadDescription: { + id: 'scopes.notificationRead.description', + defaultMessage: 'Read your notifications', + }, + notificationWriteLabel: { + id: 'scopes.notificationWrite.label', + defaultMessage: 'Write notifications', + }, + notificationWriteDescription: { + id: 'scopes.notificationWrite.description', + defaultMessage: 'Delete/View your notifications', + }, + payoutsReadLabel: { + id: 'scopes.payoutsRead.label', + defaultMessage: 'Read payouts', + }, + payoutsReadDescription: { + id: 'scopes.payoutsRead.description', + defaultMessage: 'Read your payouts data', + }, + payoutsWriteLabel: { + id: 'scopes.payoutsWrite.label', + defaultMessage: 'Write payouts', + }, + payoutsWriteDescription: { + id: 'scopes.payoutsWrite.description', + defaultMessage: 'Withdraw money', + }, + analyticsLabel: { + id: 'scopes.analytics.label', + defaultMessage: 'Read analytics', + }, + analyticsDescription: { + id: 'scopes.analytics.description', + defaultMessage: 'Access your analytics data', + }, + projectCreateLabel: { + id: 'scopes.projectCreate.label', + defaultMessage: 'Create projects', + }, + projectCreateDescription: { + id: 'scopes.projectCreate.description', + defaultMessage: 'Create new projects', + }, + projectReadLabel: { + id: 'scopes.projectRead.label', + defaultMessage: 'Read projects', + }, + projectReadDescription: { + id: 'scopes.projectRead.description', + defaultMessage: 'Read all your projects', + }, + projectWriteLabel: { + id: 'scopes.projectWrite.label', + defaultMessage: 'Write projects', + }, + projectWriteDescription: { + id: 'scopes.projectWrite.description', + defaultMessage: 'Write to project data', + }, + projectDeleteLabel: { + id: 'scopes.projectDelete.label', + defaultMessage: 'Delete projects', + }, + projectDeleteDescription: { + id: 'scopes.projectDelete.description', + defaultMessage: 'Delete your projects', + }, + versionCreateLabel: { + id: 'scopes.versionCreate.label', + defaultMessage: 'Create versions', + }, + versionCreateDescription: { + id: 'scopes.versionCreate.description', + defaultMessage: 'Create new versions', + }, + versionReadLabel: { + id: 'scopes.versionRead.label', + defaultMessage: 'Read versions', + }, + versionReadDescription: { + id: 'scopes.versionRead.description', + defaultMessage: 'Read all versions', + }, + versionWriteLabel: { + id: 'scopes.versionWrite.label', + defaultMessage: 'Write versions', + }, + versionWriteDescription: { + id: 'scopes.versionWrite.description', + defaultMessage: 'Write to version data', + }, + versionDeleteLabel: { + id: 'scopes.versionDelete.label', + defaultMessage: 'Delete versions', + }, + versionDeleteDescription: { + id: 'scopes.versionDelete.description', + defaultMessage: 'Delete a version', + }, + reportCreateLabel: { + id: 'scopes.reportCreate.label', + defaultMessage: 'Create reports', + }, + reportCreateDescription: { + id: 'scopes.reportCreate.description', + defaultMessage: 'Create reports', + }, + reportReadLabel: { + id: 'scopes.reportRead.label', + defaultMessage: 'Read reports', + }, + reportReadDescription: { + id: 'scopes.reportRead.description', + defaultMessage: 'Read reports', + }, + reportWriteLabel: { + id: 'scopes.reportWrite.label', + defaultMessage: 'Write reports', + }, + reportWriteDescription: { + id: 'scopes.reportWrite.description', + defaultMessage: 'Edit reports', + }, + reportDeleteLabel: { + id: 'scopes.reportDelete.label', + defaultMessage: 'Delete reports', + }, + reportDeleteDescription: { + id: 'scopes.reportDelete.description', + defaultMessage: 'Delete reports', + }, + threadReadLabel: { + id: 'scopes.threadRead.label', + defaultMessage: 'Read threads', + }, + threadReadDescription: { + id: 'scopes.threadRead.description', + defaultMessage: 'Read threads', + }, + threadWriteLabel: { + id: 'scopes.threadWrite.label', + defaultMessage: 'Write threads', + }, + threadWriteDescription: { + id: 'scopes.threadWrite.description', + defaultMessage: 'Write to threads', + }, + patCreateLabel: { + id: 'scopes.patCreate.label', + defaultMessage: 'Create PATs', + }, + patCreateDescription: { + id: 'scopes.patCreate.description', + defaultMessage: 'Create personal API tokens', + }, + patReadLabel: { + id: 'scopes.patRead.label', + defaultMessage: 'Read PATs', + }, + patReadDescription: { + id: 'scopes.patRead.description', + defaultMessage: 'View created API tokens', + }, + patWriteLabel: { + id: 'scopes.patWrite.label', + defaultMessage: 'Write PATs', + }, + patWriteDescription: { + id: 'scopes.patWrite.description', + defaultMessage: 'Edit personal API tokens', + }, + patDeleteLabel: { + id: 'scopes.patDelete.label', + defaultMessage: 'Delete PATs', + }, + patDeleteDescription: { + id: 'scopes.patDelete.description', + defaultMessage: 'Delete your personal API tokens', + }, + sessionReadLabel: { + id: 'scopes.sessionRead.label', + defaultMessage: 'Read sessions', + }, + sessionReadDescription: { + id: 'scopes.sessionRead.description', + defaultMessage: 'Read active sessions', + }, + sessionDeleteLabel: { + id: 'scopes.sessionDelete.label', + defaultMessage: 'Delete sessions', + }, + sessionDeleteDescription: { + id: 'scopes.sessionDelete.description', + defaultMessage: 'Delete sessions', + }, + performAnalyticsLabel: { + id: 'scopes.performAnalytics.label', + defaultMessage: 'Perform analytics', + }, + performAnalyticsDescription: { + id: 'scopes.performAnalytics.description', + defaultMessage: 'Perform analytics actions', + }, + collectionCreateLabel: { + id: 'scopes.collectionCreate.label', + defaultMessage: 'Create collections', + }, + collectionCreateDescription: { + id: 'scopes.collectionCreate.description', + defaultMessage: 'Create collections', + }, + collectionReadLabel: { + id: 'scopes.collectionRead.label', + defaultMessage: 'Read collections', + }, + collectionReadDescription: { + id: 'scopes.collectionRead.description', + defaultMessage: 'Read collections', + }, + collectionWriteLabel: { + id: 'scopes.collectionWrite.label', + defaultMessage: 'Write collections', + }, + collectionWriteDescription: { + id: 'scopes.collectionWrite.description', + defaultMessage: 'Write to collections', + }, + collectionDeleteLabel: { + id: 'scopes.collectionDelete.label', + defaultMessage: 'Delete collections', + }, + collectionDeleteDescription: { + id: 'scopes.collectionDelete.description', + defaultMessage: 'Delete collections', + }, + organizationCreateLabel: { + id: 'scopes.organizationCreate.label', + defaultMessage: 'Create organizations', + }, + organizationCreateDescription: { + id: 'scopes.organizationCreate.description', + defaultMessage: 'Create organizations', + }, + organizationReadLabel: { + id: 'scopes.organizationRead.label', + defaultMessage: 'Read organizations', + }, + organizationReadDescription: { + id: 'scopes.organizationRead.description', + defaultMessage: 'Read organizations', + }, + organizationWriteLabel: { + id: 'scopes.organizationWrite.label', + defaultMessage: 'Write organizations', + }, + organizationWriteDescription: { + id: 'scopes.organizationWrite.description', + defaultMessage: 'Write to organizations', + }, + organizationDeleteLabel: { + id: 'scopes.organizationDelete.label', + defaultMessage: 'Delete organizations', + }, + organizationDeleteDescription: { + id: 'scopes.organizationDelete.description', + defaultMessage: 'Delete organizations', + }, + sessionAccessLabel: { + id: 'scopes.sessionAccess.label', + defaultMessage: 'Access sessions', + }, + sessionAccessDescription: { + id: 'scopes.sessionAccess.description', + defaultMessage: 'Access modrinth-issued sessions', + }, +}) + +const scopeDefinitions = [ + { + id: 'USER_READ_EMAIL', + value: BigInt(1) << BigInt(0), + label: scopeMessages.userReadEmailLabel, + desc: scopeMessages.userReadEmailDescription, + }, + { + id: 'USER_READ', + value: BigInt(1) << BigInt(1), + label: scopeMessages.userReadLabel, + desc: scopeMessages.userReadDescription, + }, + { + id: 'USER_WRITE', + value: BigInt(1) << BigInt(2), + label: scopeMessages.userWriteLabel, + desc: scopeMessages.userWriteDescription, + }, + { + id: 'USER_DELETE', + value: BigInt(1) << BigInt(3), + label: scopeMessages.userDeleteLabel, + desc: scopeMessages.userDeleteDescription, + }, + { + id: 'USER_AUTH_WRITE', + value: BigInt(1) << BigInt(4), + label: scopeMessages.userAuthWriteLabel, + desc: scopeMessages.userAuthWriteDescription, + }, + { + id: 'NOTIFICATION_READ', + value: BigInt(1) << BigInt(5), + label: scopeMessages.notificationReadLabel, + desc: scopeMessages.notificationReadDescription, + }, + { + id: 'NOTIFICATION_WRITE', + value: BigInt(1) << BigInt(6), + label: scopeMessages.notificationWriteLabel, + desc: scopeMessages.notificationWriteDescription, + }, + { + id: 'PAYOUTS_READ', + value: BigInt(1) << BigInt(7), + label: scopeMessages.payoutsReadLabel, + desc: scopeMessages.payoutsReadDescription, + }, + { + id: 'PAYOUTS_WRITE', + value: BigInt(1) << BigInt(8), + label: scopeMessages.payoutsWriteLabel, + desc: scopeMessages.payoutsWriteDescription, + }, + { + id: 'ANALYTICS', + value: BigInt(1) << BigInt(9), + label: scopeMessages.analyticsLabel, + desc: scopeMessages.analyticsDescription, + }, + { + id: 'PROJECT_CREATE', + value: BigInt(1) << BigInt(10), + label: scopeMessages.projectCreateLabel, + desc: scopeMessages.projectCreateDescription, + }, + { + id: 'PROJECT_READ', + value: BigInt(1) << BigInt(11), + label: scopeMessages.projectReadLabel, + desc: scopeMessages.projectReadDescription, + }, + { + id: 'PROJECT_WRITE', + value: BigInt(1) << BigInt(12), + label: scopeMessages.projectWriteLabel, + desc: scopeMessages.projectWriteDescription, + }, + { + id: 'PROJECT_DELETE', + value: BigInt(1) << BigInt(13), + label: scopeMessages.projectDeleteLabel, + desc: scopeMessages.projectDeleteDescription, + }, + { + id: 'VERSION_CREATE', + value: BigInt(1) << BigInt(14), + label: scopeMessages.versionCreateLabel, + desc: scopeMessages.versionCreateDescription, + }, + { + id: 'VERSION_READ', + value: BigInt(1) << BigInt(15), + label: scopeMessages.versionReadLabel, + desc: scopeMessages.versionReadDescription, + }, + { + id: 'VERSION_WRITE', + value: BigInt(1) << BigInt(16), + label: scopeMessages.versionWriteLabel, + desc: scopeMessages.versionWriteDescription, + }, + { + id: 'VERSION_DELETE', + value: BigInt(1) << BigInt(17), + label: scopeMessages.versionDeleteLabel, + desc: scopeMessages.versionDeleteDescription, + }, + { + id: 'REPORT_CREATE', + value: BigInt(1) << BigInt(18), + label: scopeMessages.reportCreateLabel, + desc: scopeMessages.reportCreateDescription, + }, + { + id: 'REPORT_READ', + value: BigInt(1) << BigInt(19), + label: scopeMessages.reportReadLabel, + desc: scopeMessages.reportReadDescription, + }, + { + id: 'REPORT_WRITE', + value: BigInt(1) << BigInt(20), + label: scopeMessages.reportWriteLabel, + desc: scopeMessages.reportWriteDescription, + }, + { + id: 'REPORT_DELETE', + value: BigInt(1) << BigInt(21), + label: scopeMessages.reportDeleteLabel, + desc: scopeMessages.reportDeleteDescription, + }, + { + id: 'THREAD_READ', + value: BigInt(1) << BigInt(22), + label: scopeMessages.threadReadLabel, + desc: scopeMessages.threadReadDescription, + }, + { + id: 'THREAD_WRITE', + value: BigInt(1) << BigInt(23), + label: scopeMessages.threadWriteLabel, + desc: scopeMessages.threadWriteDescription, + }, + { + id: 'PAT_CREATE', + value: BigInt(1) << BigInt(24), + label: scopeMessages.patCreateLabel, + desc: scopeMessages.patCreateDescription, + }, + { + id: 'PAT_READ', + value: BigInt(1) << BigInt(25), + label: scopeMessages.patReadLabel, + desc: scopeMessages.patReadDescription, + }, + { + id: 'PAT_WRITE', + value: BigInt(1) << BigInt(26), + label: scopeMessages.patWriteLabel, + desc: scopeMessages.patWriteDescription, + }, + { + id: 'PAT_DELETE', + value: BigInt(1) << BigInt(27), + label: scopeMessages.patDeleteLabel, + desc: scopeMessages.patDeleteDescription, + }, + { + id: 'SESSION_READ', + value: BigInt(1) << BigInt(28), + label: scopeMessages.sessionReadLabel, + desc: scopeMessages.sessionReadDescription, + }, + { + id: 'SESSION_DELETE', + value: BigInt(1) << BigInt(29), + label: scopeMessages.sessionDeleteLabel, + desc: scopeMessages.sessionDeleteDescription, + }, + { + id: 'PERFORM_ANALYTICS', + value: BigInt(1) << BigInt(30), + label: scopeMessages.performAnalyticsLabel, + desc: scopeMessages.performAnalyticsDescription, + }, + { + id: 'COLLECTION_CREATE', + value: BigInt(1) << BigInt(31), + label: scopeMessages.collectionCreateLabel, + desc: scopeMessages.collectionCreateDescription, + }, + { + id: 'COLLECTION_READ', + value: BigInt(1) << BigInt(32), + label: scopeMessages.collectionReadLabel, + desc: scopeMessages.collectionReadDescription, + }, + { + id: 'COLLECTION_WRITE', + value: BigInt(1) << BigInt(33), + label: scopeMessages.collectionWriteLabel, + desc: scopeMessages.collectionWriteDescription, + }, + { + id: 'COLLECTION_DELETE', + value: BigInt(1) << BigInt(34), + label: scopeMessages.collectionDeleteLabel, + desc: scopeMessages.collectionDeleteDescription, + }, + { + id: 'ORGANIZATION_CREATE', + value: BigInt(1) << BigInt(35), + label: scopeMessages.organizationCreateLabel, + desc: scopeMessages.organizationCreateDescription, + }, + { + id: 'ORGANIZATION_READ', + value: BigInt(1) << BigInt(36), + label: scopeMessages.organizationReadLabel, + desc: scopeMessages.organizationReadDescription, + }, + { + id: 'ORGANIZATION_WRITE', + value: BigInt(1) << BigInt(37), + label: scopeMessages.organizationWriteLabel, + desc: scopeMessages.organizationWriteDescription, + }, + { + id: 'ORGANIZATION_DELETE', + value: BigInt(1) << BigInt(38), + label: scopeMessages.organizationDeleteLabel, + desc: scopeMessages.organizationDeleteDescription, + }, + { + id: 'SESSION_ACCESS', + value: BigInt(1) << BigInt(39), + label: scopeMessages.sessionAccessLabel, + desc: scopeMessages.sessionAccessDescription, + }, +] + +const Scopes = scopeDefinitions.reduce((acc, scope) => { + acc[scope.id] = scope.value + return acc +}, {} as Record) + +export const restrictedScopes = [ + Scopes.PAT_READ, + Scopes.PAT_CREATE, + Scopes.PAT_WRITE, + Scopes.PAT_DELETE, + Scopes.SESSION_READ, + Scopes.SESSION_DELETE, + Scopes.SESSION_ACCESS, + Scopes.USER_AUTH_WRITE, + Scopes.USER_DELETE, + Scopes.PERFORM_ANALYTICS, +] + +export const scopeList = Object.entries(Scopes) + .filter(([_, value]) => !restrictedScopes.includes(value)) + .map(([key, _]) => key) + +export const getScopeValue = (scope: string) => { + return Scopes[scope] +} + +export const encodeScopes = (scopes: string[]) => { + let scopeFlag = BigInt(0) + + // We iterate over the provided scopes + for (const scope of scopes) { + // We iterate over the entries of the Scopes object + for (const [scopeName, scopeFlagValue] of Object.entries(Scopes)) { + // If the scope name is the same as the provided scope, add the scope flag to the scopeFlag variable + if (scopeName === scope) { + scopeFlag = scopeFlag | scopeFlagValue + } + } + } + + return scopeFlag +} + +export const decodeScopes = (scopes: bigint | number) => { + if (typeof scopes === 'number') { + scopes = BigInt(scopes) + } + + const authorizedScopes = [] + + // We iterate over the entries of the Scopes object + for (const [scopeName, scopeFlag] of Object.entries(Scopes)) { + // If the scope flag is present in the provided number, add the scope name to the list + if ((scopes & scopeFlag) === scopeFlag) { + authorizedScopes.push(scopeName) + } + } + + return authorizedScopes +} + +export const hasScope = (scopes: bigint, scope: string) => { + const authorizedScopes = decodeScopes(scopes) + return authorizedScopes.includes(scope) +} + +export const toggleScope = (scopes: bigint, scope: string) => { + const authorizedScopes = decodeScopes(scopes) + if (authorizedScopes.includes(scope)) { + return encodeScopes(authorizedScopes.filter((authorizedScope) => authorizedScope !== scope)) + } else { + return encodeScopes([...authorizedScopes, scope]) + } +} + +export const useScopes = () => { + const { formatMessage } = useVIntl() + + const scopesToDefinitions = (scopes: bigint) => { + const authorizedScopes = decodeScopes(scopes) + return authorizedScopes.map((scope) => { + const scopeDefinition = scopeDefinitions.find( + (scopeDefinition) => scopeDefinition.id === scope + ) + if (!scopeDefinition) { + throw new Error(`Scope ${scope} not found`) + } + return formatMessage(scopeDefinition.desc) + }) + } + + const scopesToLabels = (scopes: bigint) => { + const authorizedScopes = decodeScopes(scopes) + return authorizedScopes.map((scope) => { + const scopeDefinition = scopeDefinitions.find( + (scopeDefinition) => scopeDefinition.id === scope + ) + if (!scopeDefinition) { + throw new Error(`Scope ${scope} not found`) + } + return formatMessage(scopeDefinition.label) + }) + } + + return { + scopesToDefinitions, + scopesToLabels, + } +} diff --git a/locales/en-US/index.json b/locales/en-US/index.json index 095f4d275..805adae29 100644 --- a/locales/en-US/index.json +++ b/locales/en-US/index.json @@ -68,6 +68,9 @@ "profile.label.no-projects-auth": { "message": "You don't have any projects.\nWould you like to create one?" }, + "profile.label.organizations": { + "message": "Organizations" + }, "profile.meta.description": { "message": "Download {username}'s projects on Modrinth" }, @@ -134,6 +137,258 @@ "project-type.shader.singular": { "message": "Shader" }, + "revenue.transfers.total": { + "message": "You have withdrawn {amount} in total." + }, + "revenue.transfers.total.method": { + "message": "You have withdrawn {amount} through {method}." + }, + "revenue.transfers.total.year": { + "message": "You have withdrawn {amount} in {year}." + }, + "revenue.transfers.total.year_method": { + "message": "You have withdrawn {amount} in {year} through {method}." + }, + "scopes.analytics.description": { + "message": "Access your analytics data" + }, + "scopes.analytics.label": { + "message": "Read analytics" + }, + "scopes.collectionCreate.description": { + "message": "Create collections" + }, + "scopes.collectionCreate.label": { + "message": "Create collections" + }, + "scopes.collectionDelete.description": { + "message": "Delete collections" + }, + "scopes.collectionDelete.label": { + "message": "Delete collections" + }, + "scopes.collectionRead.description": { + "message": "Read collections" + }, + "scopes.collectionRead.label": { + "message": "Read collections" + }, + "scopes.collectionWrite.description": { + "message": "Write to collections" + }, + "scopes.collectionWrite.label": { + "message": "Write collections" + }, + "scopes.notificationRead.description": { + "message": "Read your notifications" + }, + "scopes.notificationRead.label": { + "message": "Read notifications" + }, + "scopes.notificationWrite.description": { + "message": "Delete/View your notifications" + }, + "scopes.notificationWrite.label": { + "message": "Write notifications" + }, + "scopes.organizationCreate.description": { + "message": "Create organizations" + }, + "scopes.organizationCreate.label": { + "message": "Create organizations" + }, + "scopes.organizationDelete.description": { + "message": "Delete organizations" + }, + "scopes.organizationDelete.label": { + "message": "Delete organizations" + }, + "scopes.organizationRead.description": { + "message": "Read organizations" + }, + "scopes.organizationRead.label": { + "message": "Read organizations" + }, + "scopes.organizationWrite.description": { + "message": "Write to organizations" + }, + "scopes.organizationWrite.label": { + "message": "Write organizations" + }, + "scopes.patCreate.description": { + "message": "Create personal API tokens" + }, + "scopes.patCreate.label": { + "message": "Create PATs" + }, + "scopes.patDelete.description": { + "message": "Delete your personal API tokens" + }, + "scopes.patDelete.label": { + "message": "Delete PATs" + }, + "scopes.patRead.description": { + "message": "View created API tokens" + }, + "scopes.patRead.label": { + "message": "Read PATs" + }, + "scopes.patWrite.description": { + "message": "Edit personal API tokens" + }, + "scopes.patWrite.label": { + "message": "Write PATs" + }, + "scopes.payoutsRead.description": { + "message": "Read your payouts data" + }, + "scopes.payoutsRead.label": { + "message": "Read payouts" + }, + "scopes.payoutsWrite.description": { + "message": "Withdraw money" + }, + "scopes.payoutsWrite.label": { + "message": "Write payouts" + }, + "scopes.performAnalytics.description": { + "message": "Perform analytics actions" + }, + "scopes.performAnalytics.label": { + "message": "Perform analytics" + }, + "scopes.projectCreate.description": { + "message": "Create new projects" + }, + "scopes.projectCreate.label": { + "message": "Create projects" + }, + "scopes.projectDelete.description": { + "message": "Delete your projects" + }, + "scopes.projectDelete.label": { + "message": "Delete projects" + }, + "scopes.projectRead.description": { + "message": "Read all your projects" + }, + "scopes.projectRead.label": { + "message": "Read projects" + }, + "scopes.projectWrite.description": { + "message": "Write to project data" + }, + "scopes.projectWrite.label": { + "message": "Write projects" + }, + "scopes.reportCreate.description": { + "message": "Create reports" + }, + "scopes.reportCreate.label": { + "message": "Create reports" + }, + "scopes.reportDelete.description": { + "message": "Delete reports" + }, + "scopes.reportDelete.label": { + "message": "Delete reports" + }, + "scopes.reportRead.description": { + "message": "Read reports" + }, + "scopes.reportRead.label": { + "message": "Read reports" + }, + "scopes.reportWrite.description": { + "message": "Edit reports" + }, + "scopes.reportWrite.label": { + "message": "Write reports" + }, + "scopes.sessionAccess.description": { + "message": "Access modrinth-issued sessions" + }, + "scopes.sessionAccess.label": { + "message": "Access sessions" + }, + "scopes.sessionDelete.description": { + "message": "Delete sessions" + }, + "scopes.sessionDelete.label": { + "message": "Delete sessions" + }, + "scopes.sessionRead.description": { + "message": "Read active sessions" + }, + "scopes.sessionRead.label": { + "message": "Read sessions" + }, + "scopes.threadRead.description": { + "message": "Read threads" + }, + "scopes.threadRead.label": { + "message": "Read threads" + }, + "scopes.threadWrite.description": { + "message": "Write to threads" + }, + "scopes.threadWrite.label": { + "message": "Write threads" + }, + "scopes.userAuthWrite.description": { + "message": "Modify your authentication data" + }, + "scopes.userAuthWrite.label": { + "message": "Write auth data" + }, + "scopes.userDelete.description": { + "message": "Delete your account" + }, + "scopes.userDelete.label": { + "message": "Delete your account" + }, + "scopes.userRead.description": { + "message": "Access your public profile information" + }, + "scopes.userRead.label": { + "message": "Read user data" + }, + "scopes.userReadEmail.description": { + "message": "Read your email" + }, + "scopes.userReadEmail.label": { + "message": "Read user email" + }, + "scopes.userWrite.description": { + "message": "Write to your profile" + }, + "scopes.userWrite.label": { + "message": "Write user data" + }, + "scopes.versionCreate.description": { + "message": "Create new versions" + }, + "scopes.versionCreate.label": { + "message": "Create versions" + }, + "scopes.versionDelete.description": { + "message": "Delete a version" + }, + "scopes.versionDelete.label": { + "message": "Delete versions" + }, + "scopes.versionRead.description": { + "message": "Read all versions" + }, + "scopes.versionRead.label": { + "message": "Read versions" + }, + "scopes.versionWrite.description": { + "message": "Write to version data" + }, + "scopes.versionWrite.label": { + "message": "Write versions" + }, "settings.language.categories.auto": { "message": "Automatic" }, diff --git a/pages/auth/authorize.vue b/pages/auth/authorize.vue index 42325f351..e0f30aea0 100644 --- a/pages/auth/authorize.vue +++ b/pages/auth/authorize.vue @@ -65,12 +65,14 @@ import { Button, XIcon, CheckIcon, Avatar } from 'omorphia' import { useBaseFetch } from '@/composables/fetch.js' import { useAuth } from '@/composables/auth.js' -import { getScopeDefinitions } from '@/utils/auth/scopes.ts' + +import { useScopes } from '@/composables/auth/scopes.ts' const data = useNuxtApp() const router = useRoute() const auth = await useAuth() +const { scopesToDefinitions } = useScopes() const clientId = router.query?.client_id || false const redirectUri = router.query?.redirect_uri || false @@ -115,7 +117,7 @@ const { data: app } = await useAsyncData('oauth/app/' + clientId, () => }) ) -const scopeDefinitions = getScopeDefinitions(BigInt(authorizationData.value?.requested_scopes || 0)) +const scopeDefinitions = scopesToDefinitions(BigInt(authorizationData.value?.requested_scopes || 0)) const { data: createdBy } = await useAsyncData('user/' + app.value.created_by, () => useBaseFetch('user/' + app.value.created_by, { diff --git a/pages/settings/applications.vue b/pages/settings/applications.vue index a9df727ee..2ffe42194 100644 --- a/pages/settings/applications.vue +++ b/pages/settings/applications.vue @@ -61,7 +61,7 @@ @@ -230,7 +230,14 @@ import { ConfirmModal, } from 'omorphia' import Modal from '~/components/ui/Modal.vue' -import { scopeList, hasScope, toggleScope, getScopeLabel } from '~/utils/auth/scopes.ts' + +import { + scopeList, + hasScope, + toggleScope, + useScopes, + getScopeValue, +} from '~/composables/auth/scopes.ts' definePageMeta({ middleware: 'auth', @@ -241,6 +248,7 @@ useHead({ }) const data = useNuxtApp() +const { scopesToLabels } = useScopes() const appModal = ref() diff --git a/pages/settings/authorizations.vue b/pages/settings/authorizations.vue index c1c76e7a8..a77c1f5e5 100644 --- a/pages/settings/authorizations.vue +++ b/pages/settings/authorizations.vue @@ -56,14 +56,14 @@
- {{ constCaseToTitleCase(scope) }} + {{ scope }}
@@ -89,7 +89,10 @@