diff --git a/packages/plugins/@hera/plugin-core/src/client/schema-initializer/SettingBlockInitializer.tsx b/packages/plugins/@hera/plugin-core/src/client/schema-initializer/SettingBlockInitializer.tsx index 2bdad6e82..a6193632b 100644 --- a/packages/plugins/@hera/plugin-core/src/client/schema-initializer/SettingBlockInitializer.tsx +++ b/packages/plugins/@hera/plugin-core/src/client/schema-initializer/SettingBlockInitializer.tsx @@ -1,7 +1,7 @@ import { FormOutlined } from '@ant-design/icons'; import { FormLayout } from '@formily/antd-v5'; import { SchemaOptionsContext } from '@formily/react'; -import { createFormBlockSchema, useAPIClient, useCollectionManager_deprecated } from '@nocobase/client'; +import { createFormBlockSchema, useAPIClient, useCollectionManager } from '@nocobase/client'; import { DataBlockInitializer, FormDialog, @@ -12,7 +12,7 @@ import { useSchemaInitializerItem, } from '@nocobase/client'; import React, { useContext } from 'react'; -import { useTranslation } from 'react-i18next'; +import { useTranslation } from '../locale'; export const SettingBlockInitializer = () => { const { insert } = useSchemaInitializer(); @@ -20,7 +20,7 @@ export const SettingBlockInitializer = () => { const options = useContext(SchemaOptionsContext); const { theme } = useGlobalTheme(); const itemConfig = useSchemaInitializerItem(); - const { getCollection } = useCollectionManager_deprecated(); + const cm = useCollectionManager(); const api = useAPIClient(); return ( { componentType={'FormItem'} icon={} onCreateBlockSchema={async ({ item }) => { - const collection = getCollection(item.name); - const titleField = collection.options.titleField; + const collection = cm.getCollection(item.name); + const titleField = collection.titleField; const result = await api.resource(collection.name).list(); const values = await FormDialog( - t('添加单条数据展示区块'), + t('Pick a data entry for viewing and editing'), () => { return ( @@ -41,7 +41,7 @@ export const SettingBlockInitializer = () => { schema={{ properties: { id: { - title: t('选择数据'), + title: t('Please select'), enum: result.data.data.map((item) => { return { label: item[titleField], diff --git a/packages/plugins/@hera/plugin-core/src/locale/en-US.json b/packages/plugins/@hera/plugin-core/src/locale/en-US.json index 167a4bf3e..2628fa9b5 100644 --- a/packages/plugins/@hera/plugin-core/src/locale/en-US.json +++ b/packages/plugins/@hera/plugin-core/src/locale/en-US.json @@ -15,5 +15,7 @@ "System setting": "System setting", "classical": "classical", "Signature input": "Signature input", + "Pick a data entry for viewing and editing": "Pick a data entry for viewing and editing", + "Please select": "Please select", "HomePage Config": "HomePage Config" } diff --git a/packages/plugins/@hera/plugin-core/src/locale/zh-CN.json b/packages/plugins/@hera/plugin-core/src/locale/zh-CN.json index 2afae2596..9d4bc4396 100644 --- a/packages/plugins/@hera/plugin-core/src/locale/zh-CN.json +++ b/packages/plugins/@hera/plugin-core/src/locale/zh-CN.json @@ -15,5 +15,7 @@ "System setting": "系统设置", "classical": "经典版", "Signature input": "手写签名", + "Pick a data entry for viewing and editing": "选择一条数据用于查看与编辑", + "Please select": "请选择", "HomePage Config": "主页配置" } diff --git a/packages/plugins/@hera/plugin-oidc/.npmignore b/packages/plugins/@hera/plugin-oidc/.npmignore new file mode 100644 index 000000000..65f5e8779 --- /dev/null +++ b/packages/plugins/@hera/plugin-oidc/.npmignore @@ -0,0 +1,2 @@ +/node_modules +/src diff --git a/packages/plugins/@hera/plugin-oidc/README.md b/packages/plugins/@hera/plugin-oidc/README.md new file mode 100644 index 000000000..7e7c909eb --- /dev/null +++ b/packages/plugins/@hera/plugin-oidc/README.md @@ -0,0 +1 @@ +# @hera/plugin-oidc diff --git a/packages/plugins/@hera/plugin-oidc/client.d.ts b/packages/plugins/@hera/plugin-oidc/client.d.ts new file mode 100644 index 000000000..6c459cbac --- /dev/null +++ b/packages/plugins/@hera/plugin-oidc/client.d.ts @@ -0,0 +1,2 @@ +export * from './dist/client'; +export { default } from './dist/client'; diff --git a/packages/plugins/@hera/plugin-oidc/client.js b/packages/plugins/@hera/plugin-oidc/client.js new file mode 100644 index 000000000..b6e3be70e --- /dev/null +++ b/packages/plugins/@hera/plugin-oidc/client.js @@ -0,0 +1 @@ +module.exports = require('./dist/client/index.js'); diff --git a/packages/plugins/@hera/plugin-oidc/package.json b/packages/plugins/@hera/plugin-oidc/package.json new file mode 100644 index 000000000..fedadcffc --- /dev/null +++ b/packages/plugins/@hera/plugin-oidc/package.json @@ -0,0 +1,14 @@ +{ + "name": "@hera/plugin-oidc", + "version": "0.20.0-alpha.7", + "main": "dist/server/index.js", + "devDependencies": { + "@koa/router": "^12.0.1", + "@types/koa__router": "^12.0.4" + }, + "peerDependencies": { + "@nocobase/client": "0.x", + "@nocobase/server": "0.x", + "@nocobase/test": "0.x" + } +} diff --git a/packages/plugins/@hera/plugin-oidc/server.d.ts b/packages/plugins/@hera/plugin-oidc/server.d.ts new file mode 100644 index 000000000..c41081ddc --- /dev/null +++ b/packages/plugins/@hera/plugin-oidc/server.d.ts @@ -0,0 +1,2 @@ +export * from './dist/server'; +export { default } from './dist/server'; diff --git a/packages/plugins/@hera/plugin-oidc/server.js b/packages/plugins/@hera/plugin-oidc/server.js new file mode 100644 index 000000000..972842039 --- /dev/null +++ b/packages/plugins/@hera/plugin-oidc/server.js @@ -0,0 +1 @@ +module.exports = require('./dist/server/index.js'); diff --git a/packages/plugins/@hera/plugin-oidc/src/client/index.tsx b/packages/plugins/@hera/plugin-oidc/src/client/index.tsx new file mode 100644 index 000000000..21ff0eddd --- /dev/null +++ b/packages/plugins/@hera/plugin-oidc/src/client/index.tsx @@ -0,0 +1,21 @@ +import { Plugin } from '@nocobase/client'; + +export class PluginOidcClient extends Plugin { + async afterAdd() { + // await this.app.pm.add() + } + + async beforeLoad() {} + + // You can get and modify the app instance here + async load() { + console.log(this.app); + // this.app.addComponents({}) + // this.app.addScopes({}) + // this.app.addProvider() + // this.app.addProviders() + // this.app.router.add() + } +} + +export default PluginOidcClient; diff --git a/packages/plugins/@hera/plugin-oidc/src/index.ts b/packages/plugins/@hera/plugin-oidc/src/index.ts new file mode 100644 index 000000000..7e74612df --- /dev/null +++ b/packages/plugins/@hera/plugin-oidc/src/index.ts @@ -0,0 +1,2 @@ +export * from './server'; +export { default } from './server'; diff --git a/packages/plugins/@hera/plugin-oidc/src/server/collections/.gitkeep b/packages/plugins/@hera/plugin-oidc/src/server/collections/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugins/@hera/plugin-oidc/src/server/index.ts b/packages/plugins/@hera/plugin-oidc/src/server/index.ts new file mode 100644 index 000000000..b68aea57f --- /dev/null +++ b/packages/plugins/@hera/plugin-oidc/src/server/index.ts @@ -0,0 +1 @@ +export { default } from './plugin'; diff --git a/packages/plugins/@hera/plugin-oidc/src/server/plugin.ts b/packages/plugins/@hera/plugin-oidc/src/server/plugin.ts new file mode 100644 index 000000000..222a40820 --- /dev/null +++ b/packages/plugins/@hera/plugin-oidc/src/server/plugin.ts @@ -0,0 +1,218 @@ +import { Plugin } from '@nocobase/server'; +import Router from '@koa/router'; + +export class PluginOidcServer extends Plugin { + async afterAdd() {} + + async beforeLoad() {} + + async load() { + const router = new Router(); + + router.get('/oidc/hello', async (ctx, next) => { + ctx.body = { + message: 'hello from koa router', + }; + }); + // this.app.use(router.routes()); + this.app.use(async (ctx, next) => { + console.log('------------------- - - - -'); + }); + + // router.use(async (ctx, next) => { + // ctx.set('cache-control', 'no-store'); + // try { + // await next(); + // } catch (err) { + // console.log('------------------') + // console.error(err) + // if (err instanceof SessionNotFound) { + // ctx.status = err.status; + // const { message: error, error_description } = err; + // await defaults.renderError(ctx, { error, error_description }, err); + // } else { + // throw err; + // } + // } + // }); + + // router.get('/interaction/:uid', async (ctx, next) => { + // const { + // uid, prompt, params, session, + // } = await provider.interactionDetails(ctx.req, ctx.res); + // const client = await provider.Client.find(params.client_id); + + // switch (prompt.name) { + // case 'login': { + // return ctx.render('login', { + // client, + // uid, + // details: prompt.details, + // params, + // title: 'Sign-in', + // google: ctx.google, + // session: session ? debug(session) : undefined, + // dbg: { + // params: debug(params), + // prompt: debug(prompt), + // }, + // }); + // } + // case 'consent': { + // return ctx.render('interaction', { + // client, + // uid, + // details: prompt.details, + // params, + // title: 'Authorize', + // session: session ? debug(session) : undefined, + // dbg: { + // params: debug(params), + // prompt: debug(prompt), + // }, + // }); + // } + // default: + // return next(); + // } + // }); + + // const body = bodyParser({ + // text: false, json: false, patchNode: true, patchKoa: true, + // }); + + // router.get('/interaction/callback/google', (ctx) => { + // const nonce = ctx.res.locals.cspNonce; + // return ctx.render('repost', { layout: false, upstream: 'google', nonce }); + // }); + + // router.post('/interaction/:uid/login', body, async (ctx) => { + // const { prompt: { name } } = await provider.interactionDetails(ctx.req, ctx.res); + // assert.equal(name, 'login'); + + // const account = await Account.findByLogin(ctx.request.body.login); + + // const result = { + // login: { + // accountId: account.accountId, + // }, + // }; + + // return provider.interactionFinished(ctx.req, ctx.res, result, { + // mergeWithLastSubmission: false, + // }); + // }); + + // router.post('/interaction/:uid/federated', body, async (ctx) => { + // const { prompt: { name } } = await provider.interactionDetails(ctx.req, ctx.res); + // assert.equal(name, 'login'); + + // const path = `/interaction/${ctx.params.uid}/federated`; + + // switch (ctx.request.body.upstream) { + // case 'google': { + // const callbackParams = ctx.google.callbackParams(ctx.req); + + // // init + // if (!Object.keys(callbackParams).length) { + // const state = ctx.params.uid; + // const nonce = crypto.randomBytes(32).toString('hex'); + + // ctx.cookies.set('google.nonce', nonce, { path, sameSite: 'strict' }); + + // ctx.status = 303; + // return ctx.redirect(ctx.google.authorizationUrl({ + // state, nonce, scope: 'openid email profile', + // })); + // } + + // // callback + // const nonce = ctx.cookies.get('google.nonce'); + // ctx.cookies.set('google.nonce', null, { path }); + + // const tokenset = await ctx.google.callback(undefined, callbackParams, { state: ctx.params.uid, nonce, response_type: 'id_token' }); + // const account = await Account.findByFederated('google', tokenset.claims()); + + // const result = { + // login: { + // accountId: account.accountId, + // }, + // }; + // return provider.interactionFinished(ctx.req, ctx.res, result, { + // mergeWithLastSubmission: false, + // }); + // } + // default: + // return undefined; + // } + // }); + + // router.post('/interaction/:uid/confirm', body, async (ctx) => { + // const interactionDetails = await provider.interactionDetails(ctx.req, ctx.res); + // const { prompt: { name, details }, params, session: { accountId } } = interactionDetails; + // assert.equal(name, 'consent'); + + // let { grantId } = interactionDetails; + // let grant; + + // if (grantId) { + // // we'll be modifying existing grant in existing session + // grant = await provider.Grant.find(grantId); + // } else { + // // we're establishing a new grant + // grant = new provider.Grant({ + // accountId, + // clientId: params.client_id, + // }); + // } + + // if (details.missingOIDCScope) { + // grant.addOIDCScope(details.missingOIDCScope.join(' ')); + // } + // if (details.missingOIDCClaims) { + // grant.addOIDCClaims(details.missingOIDCClaims); + // } + // if (details.missingResourceScopes) { + // for (const [indicator, scope] of Object.entries(details.missingResourceScopes)) { + // grant.addResourceScope(indicator, scope.join(' ')); + // } + // } + + // grantId = await grant.save(); + + // const consent = {}; + // if (!interactionDetails.grantId) { + // // we don't have to pass grantId to consent, we're just modifying existing one + // consent.grantId = grantId; + // } + + // const result = { consent }; + // return provider.interactionFinished(ctx.req, ctx.res, result, { + // mergeWithLastSubmission: true, + // }); + // }); + + // router.get('/interaction/:uid/abort', async (ctx) => { + // const result = { + // error: 'access_denied', + // error_description: 'End-User aborted interaction', + // }; + + // return provider.interactionFinished(ctx.req, ctx.res, result, { + // mergeWithLastSubmission: false, + // }); + // }); + + // return router; + } + + async install() {} + + async afterEnable() {} + + async afterDisable() {} + + async remove() {} +} + +export default PluginOidcServer;