Formatting
This commit is contained in:
1 parent
1fcc425ca5
commit
4c06efc90d
18 files changed
+348
-177
No files matched your search
@@ -1,9 +1,11 @@
|
||||
# AGENTS.md
|
||||
|
||||
## Overview
|
||||
|
||||
**Dashtab** is a client-side new-tab dashboard built with Ember.js, Vite, and Tailwind CSS. It features widgets (clock, greeting), customizable wallpapers, and third-party integrations (e.g., Discourse).
|
||||
|
||||
## Tech Stack
|
||||
|
||||
- **Framework**: Ember.js (Octane) with Embroider & Vite (`@embroider/vite`)
|
||||
- **Components**: Glimmer Template Tag format (`.gjs`)
|
||||
- **Styling**: Tailwind CSS v4 (`@tailwindcss/vite`) & `@tailwindplus/elements`
|
||||
@@ -13,6 +15,7 @@
|
||||
- **Package Manager**: `pnpm`
|
||||
|
||||
## Code Layout
|
||||
|
||||
- `app/components/`: UI components using `.gjs` single-file template tags.
|
||||
- `app/services/`: Shared state and logic (e.g., `clock.js`, `storage.js`).
|
||||
- `app/routes/` & `app/templates/`: Route definitions and `.gjs` templates.
|
||||
@@ -21,12 +24,14 @@
|
||||
- `tests/`: QUnit tests (`tests/integration/` for `.gjs` components, `tests/unit/` for services).
|
||||
|
||||
## Commands
|
||||
|
||||
- `pnpm start`: Start local development server (`http://localhost:4200`).
|
||||
- `pnpm test`: Build and run the test suite via Testem.
|
||||
- `pnpm lint`: Run all linters (ESLint, Prettier, stylelint, template-lint).
|
||||
- `pnpm lint:fix`: Auto-fix linting and formatting issues.
|
||||
|
||||
## Key Conventions
|
||||
|
||||
- **Component Format**: Author all new components and templates in Glimmer Template Tag (`.gjs`) syntax.
|
||||
- **State & Services**: Use autotracking (`@tracked`) for state. Inject services with `@service`.
|
||||
- **Client Persistence**: Access client storage exclusively through `service:storage` (using namespaces: `preferences`, `integrations`, `settings`).
|
||||
@@ -34,5 +39,6 @@
|
||||
- **Testing**: Write component tests in `.gjs` with `<template>` and `render()`. Use `qunit-dom` assertions. Run `pnpm lint` and `pnpm test` to verify changes.
|
||||
|
||||
## Agent Restrictions
|
||||
|
||||
- **No Git Write Operations**: Do not run Git commands that mutate state or commit changes (e.g., `git commit`, `git add`, `git push`, etc.). All committing and staging is handled by the user.
|
||||
- **No Production Builds**: Do not run `pnpm build` or production build commands. Use `pnpm test` or `pnpm start` for testing and development.
|
||||
@@ -14,20 +14,20 @@ export default class GreetingComponent extends Component {
|
||||
}
|
||||
|
||||
async loadName() {
|
||||
this.name = await this.storage.get('preferences', 'name') ?? "Râu";
|
||||
this.name = (await this.storage.get('preferences', 'name')) ?? 'Râu';
|
||||
}
|
||||
|
||||
get greeting() {
|
||||
const hour = this.clock.time.getHours();
|
||||
if (hour < 12) return "Good morning";
|
||||
if (hour < 18) return "Good afternoon";
|
||||
return "Good evening";
|
||||
if (hour < 12) return 'Good morning';
|
||||
if (hour < 18) return 'Good afternoon';
|
||||
return 'Good evening';
|
||||
}
|
||||
|
||||
<template>
|
||||
<div class="text-[2rem]">
|
||||
{{this.greeting}}, <span class="name">{{this.name}}</span>.
|
||||
{{this.greeting}},
|
||||
<span class="name">{{this.name}}</span>.
|
||||
</div>
|
||||
</template>
|
||||
}
|
||||
|
||||
@@ -24,10 +24,10 @@ export default class ModalDialogComponent extends Component {
|
||||
|
||||
get maxWidthClass() {
|
||||
const widths = {
|
||||
'sm': 'sm:max-w-sm',
|
||||
'md': 'sm:max-w-md',
|
||||
'lg': 'sm:max-w-lg',
|
||||
'xl': 'sm:max-w-xl',
|
||||
sm: 'sm:max-w-sm',
|
||||
md: 'sm:max-w-md',
|
||||
lg: 'sm:max-w-lg',
|
||||
xl: 'sm:max-w-xl',
|
||||
'2xl': 'sm:max-w-2xl',
|
||||
'3xl': 'sm:max-w-3xl',
|
||||
'4xl': 'sm:max-w-4xl',
|
||||
@@ -54,10 +54,24 @@ export default class ModalDialogComponent extends Component {
|
||||
|
||||
<template>
|
||||
<el-dialog>
|
||||
<dialog id={{@id}} aria-labelledby="dialog-title" class="fixed inset-0 size-auto max-h-none max-w-none overflow-y-auto bg-transparent backdrop:bg-transparent" {{this.setupDialog}}>
|
||||
<el-dialog-backdrop class="fixed inset-0 bg-neutral-950/75 transition-opacity data-closed:opacity-0 data-enter:duration-300 data-enter:ease-out data-leave:duration-200 data-leave:ease-in"></el-dialog-backdrop>
|
||||
<div tabindex="0" class="flex min-h-full items-end justify-center p-4 text-center focus:outline-none sm:items-center sm:p-0">
|
||||
<el-dialog-panel class="relative transform overflow-hidden rounded-lg bg-white text-left shadow-xl transition-all data-closed:translate-y-4 data-closed:opacity-0 data-enter:duration-300 data-enter:ease-out data-leave:duration-200 data-leave:ease-in sm:my-8 sm:w-full {{this.maxWidthClass}} data-closed:sm:translate-y-0 data-closed:sm:scale-95">
|
||||
<dialog
|
||||
id={{@id}}
|
||||
aria-labelledby="dialog-title"
|
||||
class="fixed inset-0 size-auto max-h-none max-w-none overflow-y-auto bg-transparent backdrop:bg-transparent"
|
||||
{{this.setupDialog}}
|
||||
>
|
||||
<el-dialog-backdrop
|
||||
class="fixed inset-0 bg-neutral-950/75 transition-opacity data-closed:opacity-0 data-enter:duration-300 data-enter:ease-out data-leave:duration-200 data-leave:ease-in"
|
||||
></el-dialog-backdrop>
|
||||
<div
|
||||
tabindex="0"
|
||||
class="flex min-h-full items-end justify-center p-4 text-center focus:outline-none sm:items-center sm:p-0"
|
||||
>
|
||||
<el-dialog-panel
|
||||
class="relative transform overflow-hidden rounded-lg bg-white text-left shadow-xl transition-all data-closed:translate-y-4 data-closed:opacity-0 data-enter:duration-300 data-enter:ease-out data-leave:duration-200 data-leave:ease-in sm:my-8 sm:w-full
|
||||
{{this.maxWidthClass}}
|
||||
data-closed:sm:translate-y-0 data-closed:sm:scale-95"
|
||||
>
|
||||
{{#if this.currentComponent}}
|
||||
<this.currentComponent
|
||||
@switchComponent={{this.switchComponent}}
|
||||
@@ -65,7 +79,12 @@ export default class ModalDialogComponent extends Component {
|
||||
...attributes
|
||||
/>
|
||||
{{else}}
|
||||
{{yield (hash switchComponent=this.switchComponent closeDialog=this.closeDialog)}}
|
||||
{{yield
|
||||
(hash
|
||||
switchComponent=this.switchComponent
|
||||
closeDialog=this.closeDialog
|
||||
)
|
||||
}}
|
||||
{{/if}}
|
||||
</el-dialog-panel>
|
||||
</div>
|
||||
|
||||
@@ -6,7 +6,10 @@ import ModalStepTwo from './modal-step-two.gjs';
|
||||
export default class ModalStepOneComponent extends Component {
|
||||
<template>
|
||||
<div class="p-6">
|
||||
<h3 id="dialog-title" class="text-base font-semibold leading-6 text-gray-900">Step 1: Welcome</h3>
|
||||
<h3
|
||||
id="dialog-title"
|
||||
class="text-base font-semibold leading-6 text-gray-900"
|
||||
>Step 1: Welcome</h3>
|
||||
<div class="mt-2">
|
||||
<p class="text-sm text-gray-500">
|
||||
This is the first step of the workflow. Click next to continue.
|
||||
|
||||
@@ -6,7 +6,10 @@ import ModalStepOne from './modal-step-one.gjs';
|
||||
export default class ModalStepTwoComponent extends Component {
|
||||
<template>
|
||||
<div class="p-6">
|
||||
<h3 id="dialog-title" class="text-base font-semibold leading-6 text-gray-900">Step 2: Configuration</h3>
|
||||
<h3
|
||||
id="dialog-title"
|
||||
class="text-base font-semibold leading-6 text-gray-900"
|
||||
>Step 2: Configuration</h3>
|
||||
<div class="mt-2">
|
||||
<p class="text-sm text-gray-500">
|
||||
This is the second step. You can go back or finish.
|
||||
|
||||
@@ -36,20 +36,25 @@ export default class SettingsAddIntegrationDiscourse extends Component {
|
||||
const urlObj = new URL(url);
|
||||
|
||||
// Check if there's already a pending integration for this URL
|
||||
const existingIntegration = await this.findPendingIntegration(urlObj.origin);
|
||||
const existingIntegration = await this.findPendingIntegration(
|
||||
urlObj.origin
|
||||
);
|
||||
|
||||
let clientId, nonce, publicKeyPem;
|
||||
|
||||
if (existingIntegration) {
|
||||
// Re-use existing pending integration
|
||||
console.log('Re-using existing pending integration:', existingIntegration.data.clientId);
|
||||
console.log(
|
||||
'Re-using existing pending integration:',
|
||||
existingIntegration.data.clientId
|
||||
);
|
||||
clientId = existingIntegration.data.clientId;
|
||||
nonce = existingIntegration.data.nonce;
|
||||
|
||||
// Re-import the private key to get the public key
|
||||
const privateKeyData = Uint8Array.from(
|
||||
atob(existingIntegration.data.privateKey),
|
||||
c => c.charCodeAt(0)
|
||||
(c) => c.charCodeAt(0)
|
||||
);
|
||||
const privateKey = await window.crypto.subtle.importKey(
|
||||
'pkcs8',
|
||||
@@ -93,7 +98,13 @@ export default class SettingsAddIntegrationDiscourse extends Component {
|
||||
const redirectUrl = window.location.origin + '/auth/discourse/callback';
|
||||
|
||||
// Store the pending integration with private key and nonce
|
||||
await this.storePendingIntegration(clientId, urlObj.origin, privateKey, nonce, redirectUrl);
|
||||
await this.storePendingIntegration(
|
||||
clientId,
|
||||
urlObj.origin,
|
||||
privateKey,
|
||||
nonce,
|
||||
redirectUrl
|
||||
);
|
||||
|
||||
console.log('Created new pending integration:', clientId);
|
||||
}
|
||||
@@ -107,17 +118,19 @@ export default class SettingsAddIntegrationDiscourse extends Component {
|
||||
nonce: nonce,
|
||||
scopes: 'notifications,session_info',
|
||||
auth_redirect: redirectUrl,
|
||||
public_key: publicKeyPem
|
||||
public_key: publicKeyPem,
|
||||
});
|
||||
|
||||
authUrl.search = params.toString();
|
||||
|
||||
console.log('Authorization URL:', authUrl.toString());
|
||||
console.log('Redirect URL (must be whitelisted in Discourse):', redirectUrl);
|
||||
console.log(
|
||||
'Redirect URL (must be whitelisted in Discourse):',
|
||||
redirectUrl
|
||||
);
|
||||
|
||||
// Redirect to Discourse authorization
|
||||
window.location.href = authUrl.toString();
|
||||
|
||||
} catch (err) {
|
||||
console.error('Error setting up Discourse integration:', err);
|
||||
this.error = 'Invalid URL. Please enter a valid Discourse forum URL.';
|
||||
@@ -129,8 +142,8 @@ export default class SettingsAddIntegrationDiscourse extends Component {
|
||||
const integrationKeys = await this.storage.keys('integrations');
|
||||
const discourseIntegrations = await Promise.all(
|
||||
integrationKeys
|
||||
.filter(key => key.startsWith('discourse-'))
|
||||
.map(async key => {
|
||||
.filter((key) => key.startsWith('discourse-'))
|
||||
.map(async (key) => {
|
||||
const data = await this.storage.get('integrations', key);
|
||||
return { key, data };
|
||||
})
|
||||
@@ -138,7 +151,8 @@ export default class SettingsAddIntegrationDiscourse extends Component {
|
||||
|
||||
// Find a pending integration for this URL
|
||||
return discourseIntegrations.find(
|
||||
({ data }) => data && data.status === 'pending' && data.url === discourseUrl
|
||||
({ data }) =>
|
||||
data && data.status === 'pending' && data.url === discourseUrl
|
||||
);
|
||||
} catch (err) {
|
||||
console.error('Error finding pending integration:', err);
|
||||
@@ -162,15 +176,28 @@ export default class SettingsAddIntegrationDiscourse extends Component {
|
||||
|
||||
async exportPublicKeyToPem(publicKey) {
|
||||
const exported = await window.crypto.subtle.exportKey('spki', publicKey);
|
||||
const exportedAsBase64 = btoa(String.fromCharCode(...new Uint8Array(exported)));
|
||||
const exportedAsBase64 = btoa(
|
||||
String.fromCharCode(...new Uint8Array(exported))
|
||||
);
|
||||
const pem = `-----BEGIN PUBLIC KEY-----\n${exportedAsBase64.match(/.{1,64}/g).join('\n')}\n-----END PUBLIC KEY-----`;
|
||||
return pem;
|
||||
}
|
||||
|
||||
async storePendingIntegration(clientId, discourseOrigin, privateKey, nonce, redirectUrl) {
|
||||
async storePendingIntegration(
|
||||
clientId,
|
||||
discourseOrigin,
|
||||
privateKey,
|
||||
nonce,
|
||||
redirectUrl
|
||||
) {
|
||||
// Export private key for storage
|
||||
const exportedPrivateKey = await window.crypto.subtle.exportKey('pkcs8', privateKey);
|
||||
const privateKeyBase64 = btoa(String.fromCharCode(...new Uint8Array(exportedPrivateKey)));
|
||||
const exportedPrivateKey = await window.crypto.subtle.exportKey(
|
||||
'pkcs8',
|
||||
privateKey
|
||||
);
|
||||
const privateKeyBase64 = btoa(
|
||||
String.fromCharCode(...new Uint8Array(exportedPrivateKey))
|
||||
);
|
||||
|
||||
// Store pending integration state for when we return from auth
|
||||
const integrationKey = `discourse-${clientId}`;
|
||||
@@ -182,7 +209,7 @@ export default class SettingsAddIntegrationDiscourse extends Component {
|
||||
url: discourseOrigin,
|
||||
redirectUrl,
|
||||
privateKey: privateKeyBase64,
|
||||
createdAt: Date.now()
|
||||
createdAt: Date.now(),
|
||||
};
|
||||
|
||||
await this.storage.set('integrations', integrationKey, integrationData);
|
||||
@@ -190,7 +217,10 @@ export default class SettingsAddIntegrationDiscourse extends Component {
|
||||
|
||||
<template>
|
||||
<div class="p-6">
|
||||
<h3 id="dialog-title" class="text-base font-semibold leading-6 text-gray-900">Add Discourse Integration</h3>
|
||||
<h3
|
||||
id="dialog-title"
|
||||
class="text-base font-semibold leading-6 text-gray-900"
|
||||
>Add Discourse Integration</h3>
|
||||
<div class="mt-2">
|
||||
<p class="text-sm text-gray-500">
|
||||
Enter your Discourse forum URL to connect and receive notifications.
|
||||
@@ -199,7 +229,10 @@ export default class SettingsAddIntegrationDiscourse extends Component {
|
||||
|
||||
<form {{on "submit" this.handleSubmit}} class="mt-5">
|
||||
<div>
|
||||
<label for="discourse-url" class="block text-sm font-medium leading-6 text-gray-900">
|
||||
<label
|
||||
for="discourse-url"
|
||||
class="block text-sm font-medium leading-6 text-gray-900"
|
||||
>
|
||||
Discourse URL
|
||||
</label>
|
||||
<div class="mt-2">
|
||||
|
||||
@@ -7,16 +7,33 @@ export default class SettingsAddIntegrationList extends Component {
|
||||
<template>
|
||||
<div class="block max-h-96 p-4 transform-gpu scroll-py-3 overflow-y-auto">
|
||||
<button
|
||||
type="button"
|
||||
{{on "click" (fn @switchComponent Discourse)}}
|
||||
class="group flex w-full rounded-xl p-3 cursor-pointer select-none focus:outline-hidden hover:bg-gray-100 aria-selected:bg-gray-100">
|
||||
<div class="flex size-10 flex-none items-center justify-center rounded-lg bg-indigo-500">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" data-slot="icon" class="size-6 text-white">
|
||||
<path d="m16.862 4.487 1.687-1.688a1.875 1.875 0 1 1 2.652 2.652L10.582 16.07a4.5 4.5 0 0 1-1.897 1.13L6 18l.8-2.685a4.5 4.5 0 0 1 1.13-1.897l8.932-8.931Zm0 0L19.5 7.125M18 14v4.75A2.25 2.25 0 0 1 15.75 21H5.25A2.25 2.25 0 0 1 3 18.75V8.25A2.25 2.25 0 0 1 5.25 6H10" stroke-linecap="round" stroke-linejoin="round" />
|
||||
type="button"
|
||||
{{on "click" (fn @switchComponent Discourse)}}
|
||||
class="group flex w-full rounded-xl p-3 cursor-pointer select-none focus:outline-hidden hover:bg-gray-100 aria-selected:bg-gray-100"
|
||||
>
|
||||
<div
|
||||
class="flex size-10 flex-none items-center justify-center rounded-lg bg-indigo-500"
|
||||
>
|
||||
<svg
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.5"
|
||||
data-slot="icon"
|
||||
class="size-6 text-white"
|
||||
>
|
||||
<path
|
||||
d="m16.862 4.487 1.687-1.688a1.875 1.875 0 1 1 2.652 2.652L10.582 16.07a4.5 4.5 0 0 1-1.897 1.13L6 18l.8-2.685a4.5 4.5 0 0 1 1.13-1.897l8.932-8.931Zm0 0L19.5 7.125M18 14v4.75A2.25 2.25 0 0 1 15.75 21H5.25A2.25 2.25 0 0 1 3 18.75V8.25A2.25 2.25 0 0 1 5.25 6H10"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="ml-4 flex-auto text-left">
|
||||
<p id="item-1-label" class="text-sm font-medium text-gray-700 group-aria-selected:text-gray-900">
|
||||
<p
|
||||
id="item-1-label"
|
||||
class="text-sm font-medium text-gray-700 group-aria-selected:text-gray-900"
|
||||
>
|
||||
Discourse
|
||||
</p>
|
||||
<p class="text-sm text-gray-500 group-aria-selected:text-gray-700">
|
||||
@@ -24,10 +41,27 @@ export default class SettingsAddIntegrationList extends Component {
|
||||
</p>
|
||||
</div>
|
||||
</button>
|
||||
<button type="button" disabled class="group flex w-full cursor-default rounded-xl p-3 select-none focus:outline-hidden">
|
||||
<div class="flex size-10 flex-none items-center justify-center rounded-lg bg-gray-300">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" data-slot="icon" class="size-6 text-white">
|
||||
<path d="m16.862 4.487 1.687-1.688a1.875 1.875 0 1 1 2.652 2.652L10.582 16.07a4.5 4.5 0 0 1-1.897 1.13L6 18l.8-2.685a4.5 4.5 0 0 1 1.13-1.897l8.932-8.931Zm0 0L19.5 7.125M18 14v4.75A2.25 2.25 0 0 1 15.75 21H5.25A2.25 2.25 0 0 1 3 18.75V8.25A2.25 2.25 0 0 1 5.25 6H10" stroke-linecap="round" stroke-linejoin="round" />
|
||||
<button
|
||||
type="button"
|
||||
disabled
|
||||
class="group flex w-full cursor-default rounded-xl p-3 select-none focus:outline-hidden"
|
||||
>
|
||||
<div
|
||||
class="flex size-10 flex-none items-center justify-center rounded-lg bg-gray-300"
|
||||
>
|
||||
<svg
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.5"
|
||||
data-slot="icon"
|
||||
class="size-6 text-white"
|
||||
>
|
||||
<path
|
||||
d="m16.862 4.487 1.687-1.688a1.875 1.875 0 1 1 2.652 2.652L10.582 16.07a4.5 4.5 0 0 1-1.897 1.13L6 18l.8-2.685a4.5 4.5 0 0 1 1.13-1.897l8.932-8.931Zm0 0L19.5 7.125M18 14v4.75A2.25 2.25 0 0 1 15.75 21H5.25A2.25 2.25 0 0 1 3 18.75V8.25A2.25 2.25 0 0 1 5.25 6H10"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="ml-4 flex-auto text-left">
|
||||
|
||||
@@ -20,14 +20,41 @@ export default class IntegrationResultDialog extends Component {
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<div class="mx-auto flex size-12 items-center justify-center rounded-full {{if this.isSuccess 'bg-green-100' 'bg-red-100'}}">
|
||||
<div
|
||||
class="mx-auto flex size-12 items-center justify-center rounded-full
|
||||
{{if this.isSuccess 'bg-green-100' 'bg-red-100'}}"
|
||||
>
|
||||
{{#if this.isSuccess}}
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" data-slot="icon" aria-hidden="true" class="size-6 text-green-600">
|
||||
<path d="m4.5 12.75 6 6 9-13.5" stroke-linecap="round" stroke-linejoin="round" />
|
||||
<svg
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.5"
|
||||
data-slot="icon"
|
||||
aria-hidden="true"
|
||||
class="size-6 text-green-600"
|
||||
>
|
||||
<path
|
||||
d="m4.5 12.75 6 6 9-13.5"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
/>
|
||||
</svg>
|
||||
{{else}}
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" data-slot="icon" aria-hidden="true" class="size-6 text-red-600">
|
||||
<path d="M6 18L18 6M6 6l12 12" stroke-linecap="round" stroke-linejoin="round" />
|
||||
<svg
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.5"
|
||||
data-slot="icon"
|
||||
aria-hidden="true"
|
||||
class="size-6 text-red-600"
|
||||
>
|
||||
<path
|
||||
d="M6 18L18 6M6 6l12 12"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
/>
|
||||
</svg>
|
||||
{{/if}}
|
||||
</div>
|
||||
@@ -38,7 +65,8 @@ export default class IntegrationResultDialog extends Component {
|
||||
<div class="mt-2">
|
||||
<p class="text-sm text-gray-500">
|
||||
{{#if this.isSuccess}}
|
||||
Your Discourse forum has been connected successfully. You can now receive notifications from your forum.
|
||||
Your Discourse forum has been connected successfully. You can now
|
||||
receive notifications from your forum.
|
||||
{{else}}
|
||||
{{@result.error}}
|
||||
{{/if}}
|
||||
|
||||
+2
-2
@@ -7,8 +7,8 @@ export default class Router extends EmberRouter {
|
||||
}
|
||||
|
||||
Router.map(function () {
|
||||
this.route('auth', function() {
|
||||
this.route('discourse', function() {
|
||||
this.route('auth', function () {
|
||||
this.route('discourse', function () {
|
||||
this.route('callback');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -19,8 +19,8 @@ export default class AuthDiscourseCallbackRoute extends Route {
|
||||
const integrationKeys = await this.storage.keys('integrations');
|
||||
const pendingIntegrations = await Promise.all(
|
||||
integrationKeys
|
||||
.filter(key => key.startsWith('discourse-'))
|
||||
.map(async key => {
|
||||
.filter((key) => key.startsWith('discourse-'))
|
||||
.map(async (key) => {
|
||||
const data = await this.storage.get('integrations', key);
|
||||
return { key, data };
|
||||
})
|
||||
@@ -37,9 +37,9 @@ export default class AuthDiscourseCallbackRoute extends Route {
|
||||
// Import the stored private key using node-forge for PKCS#1 v1.5 support
|
||||
const privateKeyData = Uint8Array.from(
|
||||
atob(pendingIntegration.data.privateKey),
|
||||
c => c.charCodeAt(0)
|
||||
(c) => c.charCodeAt(0)
|
||||
);
|
||||
|
||||
|
||||
// Convert to PEM format for node-forge
|
||||
const privateKeyDer = forge.util.createBuffer(privateKeyData);
|
||||
const privateKeyAsn1 = forge.asn1.fromDer(privateKeyDer);
|
||||
@@ -50,23 +50,26 @@ export default class AuthDiscourseCallbackRoute extends Route {
|
||||
const cleanPayload = payload.replace(/\s/g, '');
|
||||
console.log('Original payload length:', payload.length);
|
||||
console.log('Cleaned payload length:', cleanPayload.length);
|
||||
|
||||
|
||||
// Convert base64url to base64
|
||||
let base64 = cleanPayload.replace(/-/g, '+').replace(/_/g, '/');
|
||||
// Pad with = if needed
|
||||
while (base64.length % 4) {
|
||||
base64 += '=';
|
||||
}
|
||||
|
||||
|
||||
let encryptedData;
|
||||
try {
|
||||
encryptedData = forge.util.decode64(base64);
|
||||
console.log('Successfully decoded, encrypted data length:', encryptedData.length);
|
||||
console.log(
|
||||
'Successfully decoded, encrypted data length:',
|
||||
encryptedData.length
|
||||
);
|
||||
} catch (err) {
|
||||
console.error('Failed to decode base64:', err);
|
||||
return { error: 'Invalid payload format from Discourse' };
|
||||
}
|
||||
|
||||
|
||||
// Decrypt with PKCS#1 v1.5 padding (Discourse default)
|
||||
let decryptedData;
|
||||
try {
|
||||
@@ -78,7 +81,10 @@ export default class AuthDiscourseCallbackRoute extends Route {
|
||||
console.error('PKCS#1 v1.5 decryption failed:', err);
|
||||
console.error('Payload length:', payload.length);
|
||||
console.error('Encrypted data length:', encryptedData.length);
|
||||
return { error: 'Failed to decrypt response from Discourse. The key or encryption format may be incompatible.' };
|
||||
return {
|
||||
error:
|
||||
'Failed to decrypt response from Discourse. The key or encryption format may be incompatible.',
|
||||
};
|
||||
}
|
||||
|
||||
// Parse the decrypted data
|
||||
@@ -91,15 +97,15 @@ export default class AuthDiscourseCallbackRoute extends Route {
|
||||
apiKey: apiData.key,
|
||||
oneTimePassword: apiData.one_time_password,
|
||||
activatedAt: Date.now(),
|
||||
privateKey: undefined // Remove private key after successful auth
|
||||
privateKey: undefined, // Remove private key after successful auth
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
integration: {
|
||||
...pendingIntegration.data,
|
||||
status: 'active'
|
||||
}
|
||||
status: 'active',
|
||||
},
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Error processing Discourse callback:', error);
|
||||
|
||||
@@ -26,8 +26,8 @@ export default class StorageService extends Service {
|
||||
driver: [
|
||||
localforage.INDEXEDDB,
|
||||
localforage.WEBSQL,
|
||||
localforage.LOCALSTORAGE
|
||||
]
|
||||
localforage.LOCALSTORAGE,
|
||||
],
|
||||
});
|
||||
this.databases.set(name, db);
|
||||
});
|
||||
@@ -35,7 +35,9 @@ export default class StorageService extends Service {
|
||||
|
||||
getDatabase(dbName = 'preferences') {
|
||||
if (!this.databases.has(dbName)) {
|
||||
throw new Error(`Database "${dbName}" not initialized. Available: ${Array.from(this.databases.keys()).join(', ')}`);
|
||||
throw new Error(
|
||||
`Database "${dbName}" not initialized. Available: ${Array.from(this.databases.keys()).join(', ')}`
|
||||
);
|
||||
}
|
||||
return this.databases.get(dbName);
|
||||
}
|
||||
@@ -76,7 +78,7 @@ export default class StorageService extends Service {
|
||||
const db = this.getDatabase(dbName);
|
||||
const keys = await db.keys();
|
||||
|
||||
keys.forEach(key => {
|
||||
keys.forEach((key) => {
|
||||
const cacheKey = this.getCacheKey(dbName, key);
|
||||
this.cache.delete(cacheKey);
|
||||
});
|
||||
@@ -99,4 +101,3 @@ export default class StorageService extends Service {
|
||||
return db.iterate(callback);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,10 @@ import { pageTitle } from 'ember-page-title';
|
||||
<template>
|
||||
{{pageTitle "Dashtab"}}
|
||||
|
||||
<div id="wrapper" class="bg-[url(/img/adelboden.jpg)] bg-cover bg-center min-h-screen w-full grid grid-cols-3 grid-rows-3">
|
||||
<div
|
||||
id="wrapper"
|
||||
class="bg-[url(/img/adelboden.jpg)] bg-cover bg-center min-h-screen w-full grid grid-cols-3 grid-rows-3"
|
||||
>
|
||||
{{outlet}}
|
||||
</div>
|
||||
</template>
|
||||
+30
-10
@@ -11,12 +11,19 @@ export default class IndexRoute extends Component {
|
||||
{{pageTitle "New Tab"}}
|
||||
|
||||
<div class="col-start-3 row-start-1 flex items-center justify-center gap-4">
|
||||
<button command="show-modal" commandfor="modal-settings-add-integration"
|
||||
class="rounded-md px-2.5 py-1.5 text-white border border-white hover:bg-gray-950/10" type="button">
|
||||
<button
|
||||
command="show-modal"
|
||||
commandfor="modal-settings-add-integration"
|
||||
class="rounded-md px-2.5 py-1.5 text-white border border-white hover:bg-gray-950/10"
|
||||
type="button"
|
||||
>
|
||||
Add Integration
|
||||
</button>
|
||||
|
||||
<ModalDialog @initialComponent={{SettingsAddIntegrationList}} @id="modal-settings-add-integration" />
|
||||
<ModalDialog
|
||||
@initialComponent={{SettingsAddIntegrationList}}
|
||||
@id="modal-settings-add-integration"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="col-start-2 row-start-2 flex items-center justify-center">
|
||||
@@ -24,24 +31,38 @@ export default class IndexRoute extends Component {
|
||||
</div>
|
||||
|
||||
<div class="col-start-2 row-start-3 flex items-center justify-center gap-4">
|
||||
<button command="show-modal" commandfor="modal-dialog-workflow"
|
||||
class="rounded-md px-2.5 py-1.5 text-white border border-white hover:bg-gray-950/10" type="button">
|
||||
<button
|
||||
command="show-modal"
|
||||
commandfor="modal-dialog-workflow"
|
||||
class="rounded-md px-2.5 py-1.5 text-white border border-white hover:bg-gray-950/10"
|
||||
type="button"
|
||||
>
|
||||
Open workflow dialog
|
||||
</button>
|
||||
|
||||
<button command="show-modal" commandfor="modal-dialog-yield"
|
||||
class="rounded-md px-2.5 py-1.5 text-white border border-white hover:bg-gray-950/10" type="button">
|
||||
<button
|
||||
command="show-modal"
|
||||
commandfor="modal-dialog-yield"
|
||||
class="rounded-md px-2.5 py-1.5 text-white border border-white hover:bg-gray-950/10"
|
||||
type="button"
|
||||
>
|
||||
Open yielded dialog
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{{! Workflow dialog with initial component }}
|
||||
<ModalDialog @initialComponent={{ModalStepOne}} @id="modal-dialog-workflow" />
|
||||
<ModalDialog
|
||||
@initialComponent={{ModalStepOne}}
|
||||
@id="modal-dialog-workflow"
|
||||
/>
|
||||
|
||||
{{! Yielded content dialog }}
|
||||
<ModalDialog @id="modal-dialog-yield" as |modal|>
|
||||
<div class="p-6">
|
||||
<h3 id="dialog-title" class="text-base font-semibold leading-6 text-gray-900">Simple Dialog</h3>
|
||||
<h3
|
||||
id="dialog-title"
|
||||
class="text-base font-semibold leading-6 text-gray-900"
|
||||
>Simple Dialog</h3>
|
||||
<div class="mt-2">
|
||||
<p class="text-sm text-gray-500">
|
||||
This dialog uses yielded content. You can put any content here.
|
||||
@@ -58,6 +79,5 @@ export default class IndexRoute extends Component {
|
||||
</div>
|
||||
</div>
|
||||
</ModalDialog>
|
||||
|
||||
</template>
|
||||
}
|
||||
+51
-50
@@ -1,6 +1,6 @@
|
||||
Discourse contains a system for generating API keys **per user** if a very
|
||||
specific protocol is followed. This feature facilitates "application" access to
|
||||
Discourse instances without needing to involve moderators.
|
||||
Discourse instances without needing to involve moderators.
|
||||
|
||||
### High level description
|
||||
|
||||
@@ -16,26 +16,26 @@ At a high level:
|
||||
4. Discourse generates a user api key
|
||||
|
||||
5. Discourse redirects back to return url with an encrypted payload using
|
||||
public api key containing the user api key
|
||||
public api key containing the user api key
|
||||
|
||||
### Details
|
||||
|
||||
Use cases:
|
||||
Use cases:
|
||||
|
||||
1. Desktop applications that poll Discourse sites on behalf of end users to get
|
||||
notification counts across multiple sites.
|
||||
notification counts across multiple sites.
|
||||
|
||||
2. Mobile applications that poll Discourse sites on behalf of end users and
|
||||
handles push notifications
|
||||
handles push notifications
|
||||
|
||||
3. Web applications that provide a dashboard for end users about various
|
||||
Discourse sites.
|
||||
Discourse sites.
|
||||
|
||||
4. Custom integrations with 3rd party apps that consume Discourse as part of
|
||||
a general company app. Eg: integrate Discourse community notifications into
|
||||
hopscotch app.
|
||||
a general company app. Eg: integrate Discourse community notifications into
|
||||
hopscotch app.
|
||||
|
||||
The design:
|
||||
The design:
|
||||
|
||||
### Site Settings
|
||||
|
||||
@@ -56,9 +56,9 @@ Use cases:
|
||||
### UX elements
|
||||
|
||||
If any user api keys have been granted, Discourse displays an **apps** tab in
|
||||
the user page.
|
||||
the user page.
|
||||
|
||||
The **apps** tab will list:
|
||||
The **apps** tab will list:
|
||||
|
||||
- The name of the application eg: ("Discourse Notifier") Last use date Approved
|
||||
- date List of access scopes granted A **revoke access** button so you can
|
||||
@@ -67,66 +67,67 @@ The **apps** tab will list:
|
||||
#### API Key authorization UI
|
||||
|
||||
Every key will have to be explicitly authorized by end users in a page that
|
||||
clearly explains what is going on, for example:
|
||||
clearly explains what is going on, for example:
|
||||
|
||||
> "Discourse Notifier" is requesting the following access to your account:
|
||||
> "Discourse Notifier" is requesting the following access to your account:
|
||||
>
|
||||
> - Read and clear notifications
|
||||
> - Read user session info
|
||||
> - Create a one-time login token
|
||||
>
|
||||
> [Authorize]
|
||||
|
||||
|
||||
### API key generation flow
|
||||
|
||||
API only requires a single GET request on the user's end.
|
||||
|
||||
``` https://sitename.com/user-api-key/new ```
|
||||
`https://sitename.com/user-api-key/new`
|
||||
|
||||
> :exclamation: As of Discourse 2.1 these user api keys now auto-expire if left
|
||||
> unused for long periods of time. The site setting: `revoke user api keys
|
||||
> unused days` is set to 180 out of the box
|
||||
unused days` is set to 180 out of the box
|
||||
|
||||
Params:
|
||||
Params:
|
||||
|
||||
* **auth_redirect**: url to redirect back to with the generated token
|
||||
* **application_name**: the name of the application making the request (will be
|
||||
* displayed in the user account's Apps tab) **client_id**: a unique identifier
|
||||
* for the client **scopes**: comma-separated list of access scopes allowed for
|
||||
* the key, see `allow user api key scopes` for the full list of available
|
||||
* scopes **push_url**: url to push notifications to (required and valid only if
|
||||
* `push` or `notifications` are included in the scopes) **public_key**: the
|
||||
* public part of the keypair generated by the client
|
||||
- **auth_redirect**: url to redirect back to with the generated token
|
||||
- **application_name**: the name of the application making the request (will be
|
||||
- displayed in the user account's Apps tab) **client_id**: a unique identifier
|
||||
- for the client **scopes**: comma-separated list of access scopes allowed for
|
||||
- the key, see `allow user api key scopes` for the full list of available
|
||||
- scopes **push_url**: url to push notifications to (required and valid only if
|
||||
- `push` or `notifications` are included in the scopes) **public_key**: the
|
||||
- public part of the keypair generated by the client
|
||||
|
||||
After `/user-api-key/new` is called with correct params 2 things may happen
|
||||
After `/user-api-key/new` is called with correct params 2 things may happen
|
||||
|
||||
1. If user is not logged on, we will redirect to login (after login we will
|
||||
resume authorization)
|
||||
2. Once a user is logged on they will be presented with the authorization
|
||||
UI
|
||||
1. If user is not logged on, we will redirect to login (after login we will
|
||||
resume authorization)
|
||||
2. Once a user is logged on they will be presented with the authorization
|
||||
UI
|
||||
|
||||
After authorization is allowed, system will redirect back to the URL
|
||||
defined in `auth_redirect` and include a single encrypted `payload`
|
||||
parameter containing the generated user API key and, if requested, a
|
||||
one-time login token. `client_id` is not echoed back for extra security.
|
||||
After authorization is allowed, system will redirect back to the URL
|
||||
defined in `auth_redirect` and include a single encrypted `payload`
|
||||
parameter containing the generated user API key and, if requested, a
|
||||
one-time login token. `client_id` is not echoed back for extra security.
|
||||
|
||||
### Checking API version
|
||||
|
||||
The use key API in Discourse is versioned. Clients can check a Discourse site's
|
||||
API version by making a HEAD request to
|
||||
`https://sitename.com/user-api-key/new`. The response will contain a header
|
||||
named Auth-Api-Version containing the version number of the site's API.
|
||||
named Auth-Api-Version containing the version number of the site's API.
|
||||
|
||||
### Consuming the API
|
||||
|
||||
Consuming the client API will be somewhat different that the current admin API.
|
||||
Consuming the client API will be somewhat different that the current admin API.
|
||||
|
||||
Client can specify 2 headers:
|
||||
Client can specify 2 headers:
|
||||
|
||||
`User-Api-Key` (required): the key that was generated
|
||||
|
||||
and
|
||||
and
|
||||
|
||||
`User-Api-Client-Id` (optional): supply this to update the 'client id' stored
|
||||
`User-Api-Client-Id` (optional): supply this to update the 'client id' stored
|
||||
for this api_key in the database.
|
||||
|
||||
Once those headers are specified client can perform requests against the API
|
||||
@@ -134,26 +135,26 @@ just as they would normally.
|
||||
|
||||
### Generating a one-time-login password
|
||||
|
||||
As of version 4, the API includes a special scope: the `one_time_password`
|
||||
As of version 4, the API includes a special scope: the `one_time_password`
|
||||
scope, which allows clients to use the user API key to generate a
|
||||
one-time-password. If the client includes this scope when generating the API
|
||||
key following the steps above, a `one_time_password` will be included in the
|
||||
encrypted `payload`.
|
||||
encrypted `payload`.
|
||||
|
||||
Alternately, the client can make a GET request to `/user-api-key/otp` with the
|
||||
following parameters:
|
||||
following parameters:
|
||||
|
||||
- auth_redirect application_name public_key
|
||||
|
||||
and with the `User-Api-Key` header.
|
||||
and with the `User-Api-Key` header.
|
||||
|
||||
This request will redirect to a screen in Discourse that will ask the user
|
||||
to allow the application access to the site. If the user approves, the site
|
||||
will redirect back to the URL defined in `auth_redirect` and include an
|
||||
encrypted `payload` with a one-time password which the client can use to
|
||||
login to the site by requesting
|
||||
`https://sitename.com/session/otp/ONE-TIME-PASSWORD`. (The
|
||||
one-time-password is only valid for 10 minutes.)
|
||||
This request will redirect to a screen in Discourse that will ask the user
|
||||
to allow the application access to the site. If the user approves, the site
|
||||
will redirect back to the URL defined in `auth_redirect` and include an
|
||||
encrypted `payload` with a one-time password which the client can use to
|
||||
login to the site by requesting
|
||||
`https://sitename.com/session/otp/ONE-TIME-PASSWORD`. (The
|
||||
one-time-password is only valid for 10 minutes.)
|
||||
|
||||
### Revoking API keys
|
||||
|
||||
|
||||
@@ -17,11 +17,13 @@ module('Integration | Component | greeting', function (hooks) {
|
||||
assert.dom().hasText('');
|
||||
|
||||
// Template block usage:
|
||||
await render(<template>
|
||||
<Greeting>
|
||||
template block text
|
||||
</Greeting>
|
||||
</template>);
|
||||
await render(
|
||||
<template>
|
||||
<Greeting>
|
||||
template block text
|
||||
</Greeting>
|
||||
</template>
|
||||
);
|
||||
|
||||
assert.dom().hasText('template block text');
|
||||
});
|
||||
|
||||
@@ -17,11 +17,13 @@ module('Integration | Component | modal-dialog', function (hooks) {
|
||||
assert.dom().hasText('');
|
||||
|
||||
// Template block usage:
|
||||
await render(<template>
|
||||
<ModalDialog>
|
||||
template block text
|
||||
</ModalDialog>
|
||||
</template>);
|
||||
await render(
|
||||
<template>
|
||||
<ModalDialog>
|
||||
template block text
|
||||
</ModalDialog>
|
||||
</template>
|
||||
);
|
||||
|
||||
assert.dom().hasText('template block text');
|
||||
});
|
||||
|
||||
@@ -3,26 +3,31 @@ import { setupRenderingTest } from 'dashtab/tests/helpers';
|
||||
import { render } from '@ember/test-helpers';
|
||||
import Discourse from 'dashtab/components/settings/add-integration/discourse';
|
||||
|
||||
module('Integration | Component | settings/add-integration/discourse', function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
module(
|
||||
'Integration | Component | settings/add-integration/discourse',
|
||||
function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test('it renders', async function (assert) {
|
||||
// Updating values is achieved using autotracking, just like in app code. For example:
|
||||
// class State { @tracked myProperty = 0; }; const state = new State();
|
||||
// and update using state.myProperty = 1; await rerender();
|
||||
// Handle any actions with function myAction(val) { ... };
|
||||
test('it renders', async function (assert) {
|
||||
// Updating values is achieved using autotracking, just like in app code. For example:
|
||||
// class State { @tracked myProperty = 0; }; const state = new State();
|
||||
// and update using state.myProperty = 1; await rerender();
|
||||
// Handle any actions with function myAction(val) { ... };
|
||||
|
||||
await render(<template><Discourse /></template>);
|
||||
await render(<template><Discourse /></template>);
|
||||
|
||||
assert.dom().hasText('');
|
||||
assert.dom().hasText('');
|
||||
|
||||
// Template block usage:
|
||||
await render(<template>
|
||||
<Discourse>
|
||||
template block text
|
||||
</Discourse>
|
||||
</template>);
|
||||
// Template block usage:
|
||||
await render(
|
||||
<template>
|
||||
<Discourse>
|
||||
template block text
|
||||
</Discourse>
|
||||
</template>
|
||||
);
|
||||
|
||||
assert.dom().hasText('template block text');
|
||||
});
|
||||
});
|
||||
assert.dom().hasText('template block text');
|
||||
});
|
||||
}
|
||||
);
|
||||
@@ -3,26 +3,31 @@ import { setupRenderingTest } from 'dashtab/tests/helpers';
|
||||
import { render } from '@ember/test-helpers';
|
||||
import List from 'dashtab/components/settings/add-integration/list';
|
||||
|
||||
module('Integration | Component | settings/add-integration/list', function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
module(
|
||||
'Integration | Component | settings/add-integration/list',
|
||||
function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test('it renders', async function (assert) {
|
||||
// Updating values is achieved using autotracking, just like in app code. For example:
|
||||
// class State { @tracked myProperty = 0; }; const state = new State();
|
||||
// and update using state.myProperty = 1; await rerender();
|
||||
// Handle any actions with function myAction(val) { ... };
|
||||
test('it renders', async function (assert) {
|
||||
// Updating values is achieved using autotracking, just like in app code. For example:
|
||||
// class State { @tracked myProperty = 0; }; const state = new State();
|
||||
// and update using state.myProperty = 1; await rerender();
|
||||
// Handle any actions with function myAction(val) { ... };
|
||||
|
||||
await render(<template><List /></template>);
|
||||
await render(<template><List /></template>);
|
||||
|
||||
assert.dom().hasText('');
|
||||
assert.dom().hasText('');
|
||||
|
||||
// Template block usage:
|
||||
await render(<template>
|
||||
<List>
|
||||
template block text
|
||||
</List>
|
||||
</template>);
|
||||
// Template block usage:
|
||||
await render(
|
||||
<template>
|
||||
<List>
|
||||
template block text
|
||||
</List>
|
||||
</template>
|
||||
);
|
||||
|
||||
assert.dom().hasText('template block text');
|
||||
});
|
||||
});
|
||||
assert.dom().hasText('template block text');
|
||||
});
|
||||
}
|
||||
);
|
||||
Reference in new issue
Block a user