From 19952f108f2160f39a147c4a84c9d3a258f4f599 Mon Sep 17 00:00:00 2001 From: "Ronald A. Richardson" Date: Thu, 11 Apr 2024 18:12:34 +0800 Subject: [PATCH] refactoring solid client on server side, added UI in admin for managing solid server config, started UI for managing solid pods and synced data from fleetbase --- .eslintignore | 10 + .eslintrc.js | 2 +- .stylelintrc.js | 2 +- .template-lintrc.js | 2 +- .../components/admin/solid-server-config.hbs | 19 + addon/components/admin/solid-server-config.js | 52 + addon/components/solid-brand-icon.hbs | 9 + addon/components/solid-brand-icon.js | 13 + addon/controllers/application.js | 27 + addon/engine.js | 22 +- addon/routes.js | 2 +- addon/routes/application.js | 14 + addon/styles/solid-engine.css | 29 + addon/templates/application.hbs | 15 + app/components/admin/solid-server-config.js | 1 + app/components/solid-brand-icon.js | 1 + app/controllers/application.js | 1 + app/routes/application.js | 1 + composer.json | 22 +- package.json | 261 +- pnpm-lock.yaml | 3142 ++++++++++++----- ...9_064616_create_solid_identities_table.php | 33 + server/src/Client/OIDCClient.php | 168 - server/src/Client/OpenIDConnectClient.php | 217 ++ server/src/Client/SolidClient.php | 174 +- .../src/Http/Controllers/OIDCController.php | 25 +- .../src/Http/Controllers/SolidController.php | 101 +- .../Identity/IdentityProvider.php | 108 +- .../Identity/Profile.php | 5 +- server/src/LegacyClient/OIDCClient.php | 350 ++ .../Profile/WebID.php | 2 +- server/src/LegacyClient/SolidClient.php | 270 ++ server/src/Models/SolidIdentity.php | 131 + server/src/routes.php | 7 +- tests/dummy/config/ember-try.js | 94 +- .../admin/solid-server-config-test.js | 26 + .../components/solid-brand-icon-test.js | 26 + tests/unit/controllers/application-test.js | 12 + tests/unit/routes/application-test.js | 11 + 39 files changed, 3983 insertions(+), 1424 deletions(-) create mode 100644 addon/components/admin/solid-server-config.hbs create mode 100644 addon/components/admin/solid-server-config.js create mode 100644 addon/components/solid-brand-icon.hbs create mode 100644 addon/components/solid-brand-icon.js create mode 100644 addon/controllers/application.js create mode 100644 addon/routes/application.js create mode 100644 addon/styles/solid-engine.css create mode 100644 addon/templates/application.hbs create mode 100644 app/components/admin/solid-server-config.js create mode 100644 app/components/solid-brand-icon.js create mode 100644 app/controllers/application.js create mode 100644 app/routes/application.js create mode 100644 server/migrations/2024_04_09_064616_create_solid_identities_table.php delete mode 100644 server/src/Client/OIDCClient.php create mode 100644 server/src/Client/OpenIDConnectClient.php rename server/src/{Client => LegacyClient}/Identity/IdentityProvider.php (56%) rename server/src/{Client => LegacyClient}/Identity/Profile.php (82%) create mode 100644 server/src/LegacyClient/OIDCClient.php rename server/src/{Client => LegacyClient}/Profile/WebID.php (90%) create mode 100644 server/src/LegacyClient/SolidClient.php create mode 100644 server/src/Models/SolidIdentity.php create mode 100644 tests/integration/components/admin/solid-server-config-test.js create mode 100644 tests/integration/components/solid-brand-icon-test.js create mode 100644 tests/unit/controllers/application-test.js create mode 100644 tests/unit/routes/application-test.js diff --git a/.eslintignore b/.eslintignore index 9385391..02adf1b 100644 --- a/.eslintignore +++ b/.eslintignore @@ -6,8 +6,18 @@ # misc /coverage/ +/scripts/ !.* .*/ # ember-try /.node_modules.ember-try/ +/bower.json.ember-try +/npm-shrinkwrap.json.ember-try +/package.json.ember-try +/package-lock.json.ember-try +/yarn.lock.ember-try + +#server +/server +/server_vendor diff --git a/.eslintrc.js b/.eslintrc.js index 2eba0f1..d483054 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -24,7 +24,7 @@ module.exports = { 'ember/no-get': 'off', 'ember/classic-decorator-no-classic-methods': 'off', 'no-prototype-builtins': 'off', - 'node/no-unpublished-require': [ + 'n/no-unpublished-require': [ 'error', { allowModules: ['resolve', 'broccoli-funnel'], diff --git a/.stylelintrc.js b/.stylelintrc.js index 021c539..62d4554 100644 --- a/.stylelintrc.js +++ b/.stylelintrc.js @@ -1,5 +1,5 @@ 'use strict'; module.exports = { - extends: ['stylelint-config-standard', 'stylelint-prettier/recommended'], + extends: ['stylelint-config-standard', 'stylelint-prettier/recommended'], }; diff --git a/.template-lintrc.js b/.template-lintrc.js index 07d5ad8..5b9387e 100644 --- a/.template-lintrc.js +++ b/.template-lintrc.js @@ -5,7 +5,7 @@ module.exports = { rules: { 'no-invalid-interactive': 'off', 'no-yield-only': 'off', - 'no-down-event-binding': 'off', + 'no-pointer-down-event-binding': 'off', 'table-groups': 'off', 'link-href-attributes': 'off', 'require-input-label': 'off', diff --git a/addon/components/admin/solid-server-config.hbs b/addon/components/admin/solid-server-config.hbs new file mode 100644 index 0000000..6657096 --- /dev/null +++ b/addon/components/admin/solid-server-config.hbs @@ -0,0 +1,19 @@ +{{#if this.configLoaded}} + + + + + + Secure Server + + + + +
+
+{{else}} +
+ +
+{{/if}} \ No newline at end of file diff --git a/addon/components/admin/solid-server-config.js b/addon/components/admin/solid-server-config.js new file mode 100644 index 0000000..bb9cfe5 --- /dev/null +++ b/addon/components/admin/solid-server-config.js @@ -0,0 +1,52 @@ +import Component from '@glimmer/component'; +import { tracked } from '@glimmer/tracking'; +import { inject as service } from '@ember/service'; +import { task } from 'ember-concurrency'; + +export default class AdminSolidServerConfigComponent extends Component { + @service fetch; + @service notifications; + @tracked configLoaded = false; + @tracked host; + @tracked port; + @tracked secure; + + constructor() { + super(...arguments); + this.loadServerConfig.perform(); + } + + getConfig() { + return { + host: this.host, + port: this.port, + secure: this.secure, + }; + } + + setConfig(config) { + this.host = config.host; + this.port = config.port; + this.secure = config.secure; + } + + @task *loadServerConfig() { + const config = yield this.fetch.get('server-config', {}, { namespace: 'solid/int/v1' }); + if (config) { + this.setConfig(config); + this.configLoaded = true; + } + } + + @task *saveServerConfig() { + try { + const config = yield this.fetch.post('server-config', { server: this.getConfig() }, { namespace: 'solid/int/v1' }); + if (config) { + this.setConfig(config); + this.notifications.success('Solid server config udpated successfully.'); + } + } catch (error) { + this.notifications.serverError(error); + } + } +} diff --git a/addon/components/solid-brand-icon.hbs b/addon/components/solid-brand-icon.hbs new file mode 100644 index 0000000..59356a8 --- /dev/null +++ b/addon/components/solid-brand-icon.hbs @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/addon/components/solid-brand-icon.js b/addon/components/solid-brand-icon.js new file mode 100644 index 0000000..68f8497 --- /dev/null +++ b/addon/components/solid-brand-icon.js @@ -0,0 +1,13 @@ +import Component from '@glimmer/component'; +import { tracked } from '@glimmer/tracking'; + +export default class SolidBrandIconComponent extends Component { + @tracked width = 19; + @tracked height = 19; + constructor(owner, { options }) { + super(...arguments); + const { width = 19, height = 19 } = options || {}; + this.width = width; + this.height = height; + } +} diff --git a/addon/controllers/application.js b/addon/controllers/application.js new file mode 100644 index 0000000..a87cc82 --- /dev/null +++ b/addon/controllers/application.js @@ -0,0 +1,27 @@ +import Controller from '@ember/controller'; +import { inject as service } from '@ember/service'; +import { task } from 'ember-concurrency'; + +export default class ApplicationController extends Controller { + @service universe; + @service fetch; + + constructor() { + super(...arguments); + this.universe.on('sidebarContext.available', (sidebarContext) => { + sidebarContext.hideNow(); + }); + } + + @task *authenticate() { + const { authenticationUrl, identifier } = yield this.fetch.get('request-authentication', {}, { namespace: 'solid/int/v1' }); + if (authenticationUrl) { + window.location.href = `${authenticationUrl}/${identifier}`; + } + } + + @task *getAccountIndex() { + const response = yield this.fetch.get('account', {}, { namespace: 'solid/int/v1' }); + console.log('[response]', response); + } +} diff --git a/addon/engine.js b/addon/engine.js index f92a014..4e91ba4 100644 --- a/addon/engine.js +++ b/addon/engine.js @@ -3,6 +3,8 @@ import loadInitializers from 'ember-load-initializers'; import Resolver from 'ember-resolver'; import config from './config/environment'; import services from '@fleetbase/ember-core/exports/services'; +import AdminSolidServerConfigComponent from './components/admin/solid-server-config'; +import SolidBrandIconComponent from './components/solid-brand-icon'; const { modulePrefix } = config; const externalRoutes = ['console', 'extensions']; @@ -14,7 +16,25 @@ export default class SolidEngine extends Engine { services, externalRoutes, }; - setupExtension = function (app, engine, universe) {}; + setupExtension = function (app, engine, universe) { + // register menu item in header + universe.registerHeaderMenuItem('Solid', 'console.solid-protocol', { iconComponent: SolidBrandIconComponent, iconComponentOptions: { width: 19, height: 19 }, priority: 5 }); + + // register admin settings -- create a solid server menu panel with it's own setting options + universe.registerAdminMenuPanel( + 'Solid Protocol', + [ + { + title: 'Solid Server Config', + icon: 'sliders', + component: AdminSolidServerConfigComponent, + }, + ], + { + slug: 'solid-server', + } + ); + }; } loadInitializers(SolidEngine, modulePrefix); diff --git a/addon/routes.js b/addon/routes.js index ad6ac01..fbe9f1b 100644 --- a/addon/routes.js +++ b/addon/routes.js @@ -1,3 +1,3 @@ import buildRoutes from 'ember-engines/routes'; -export default buildRoutes(); +export default buildRoutes(function () {}); diff --git a/addon/routes/application.js b/addon/routes/application.js new file mode 100644 index 0000000..0229bad --- /dev/null +++ b/addon/routes/application.js @@ -0,0 +1,14 @@ +import Route from '@ember/routing/route'; +import getWithDefault from '@fleetbase/ember-core/utils/get-with-default'; +import { inject as service } from '@ember/service'; + +export default class ApplicationRoute extends Route { + @service notifications; + + beforeModel(transition) { + const queryParams = getWithDefault(transition, 'router._lastQueryParams', {}); + if (queryParams.error) { + this.notifications.error(queryParams.error); + } + } +} diff --git a/addon/styles/solid-engine.css b/addon/styles/solid-engine.css new file mode 100644 index 0000000..9681a09 --- /dev/null +++ b/addon/styles/solid-engine.css @@ -0,0 +1,29 @@ +.solid-fleetbase-home-container { + margin: auto; + width: 1200px; + padding: 2rem; +} + +.solid-fleetbase-home-container h1 { + font-size: 1.5rem; + font-weight: 600; + margin-bottom: 0.75rem; +} + +.solid-fleetbase-home-container h2 { + font-size: 1.25rem; + font-weight: 500; + margin-bottom: 0.75rem; +} + +body[data-theme='light'] .solid-fleetbase-home-container a:not([class*='text-']), +body[data-theme='dark'] .solid-fleetbase-home-container a:not([class*='text-']), +.solid-fleetbase-home-container a { + color: #60a5fa; + text-decoration: underline; + text-decoration-line: underline; +} + +.solid-fleetbase-home-container a:hover { + opacity: 0.5; +} diff --git a/addon/templates/application.hbs b/addon/templates/application.hbs new file mode 100644 index 0000000..6b8d727 --- /dev/null +++ b/addon/templates/application.hbs @@ -0,0 +1,15 @@ + + + + +

Welcome to Solid for Fleetbase

+

Getting Started

+
+

+ Sign up for an account to get started with your own Pod and WebID. Once you are logged in you can begin to manage your pods and sync data directly from Fleetbase to your Pods. +

+
+ {{!--