diff --git a/packages/nc-gui/components/admin/License.vue b/packages/nc-gui/components/admin/License.vue index a2e0b49319..ed536f6b8b 100644 --- a/packages/nc-gui/components/admin/License.vue +++ b/packages/nc-gui/components/admin/License.vue @@ -29,12 +29,12 @@ loadLicense() diff --git a/packages/nc-gui/components/admin/ResetPassword.vue b/packages/nc-gui/components/admin/ResetPassword.vue index 3925422458..277f1c6900 100644 --- a/packages/nc-gui/components/admin/ResetPassword.vue +++ b/packages/nc-gui/components/admin/ResetPassword.vue @@ -67,18 +67,9 @@ const resetError = () => { diff --git a/packages/nocodb/src/lib/meta/api/ee/index.ts b/packages/nocodb/src/lib/meta/api/ee/index.ts deleted file mode 100644 index 9ceea1f3fd..0000000000 --- a/packages/nocodb/src/lib/meta/api/ee/index.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Router } from 'express'; -import { LICENSE_KEY } from '../../../constants'; -import Store from '../../../models/Store'; - -export const validateEE = async (_req, res, next) => { - const key = await Store.get(LICENSE_KEY); - if (!key?.value) { - return res.status(403).json({ msg: 'Not available' }); - } - next(); -}; - -const router = Router({ mergeParams: true }); - -// verify key -// router.use((_req, _res, next) => {}); - -export default router; diff --git a/packages/nocodb/src/lib/meta/api/ee/orgTokenApis.ts b/packages/nocodb/src/lib/meta/api/ee/orgTokenApis.ts new file mode 100644 index 0000000000..3a1526f563 --- /dev/null +++ b/packages/nocodb/src/lib/meta/api/ee/orgTokenApis.ts @@ -0,0 +1,22 @@ +import { OrgUserRoles } from '../../../../enums/OrgUserRoles'; +import ApiToken from '../../../models/ApiToken'; +import { PagedResponseImpl } from '../../helpers/PagedResponse'; + +export async function apiTokenListEE(req, res) { + let fk_user_id = req.user.id; + + // if super admin get all tokens + if (req.user.roles.includes(OrgUserRoles.SUPER)) { + fk_user_id = undefined; + } + + res.json( + new PagedResponseImpl( + await ApiToken.listWithCreatedBy({ ...req.query, fk_user_id }), + { + ...req.query, + count: await ApiToken.count(), + } + ) + ); +} diff --git a/packages/nocodb/src/lib/meta/api/orgTokenApis.ts b/packages/nocodb/src/lib/meta/api/orgTokenApis.ts index 99035eb1f5..c2f6c94e05 100644 --- a/packages/nocodb/src/lib/meta/api/orgTokenApis.ts +++ b/packages/nocodb/src/lib/meta/api/orgTokenApis.ts @@ -4,17 +4,14 @@ import ApiToken from '../../models/ApiToken'; import { Tele } from '../../utils/Tele'; import { metaApiMetrics } from '../helpers/apiMetrics'; import { NcError } from '../helpers/catchError'; +import getHandler from '../helpers/getHandler'; import ncMetaAclMw from '../helpers/ncMetaAclMw'; import { PagedResponseImpl } from '../helpers/PagedResponse'; +import { apiTokenListEE } from './ee/orgTokenApis'; async function apiTokenList(req, res) { let fk_user_id = req.user.id; - // if super admin get all tokens - if (req.user.roles.includes(OrgUserRoles.SUPER)) { - fk_user_id = undefined; - } - res.json( new PagedResponseImpl( await ApiToken.listWithCreatedBy({ ...req.query, fk_user_id }), @@ -49,7 +46,7 @@ const router = Router({ mergeParams: true }); router.get( '/api/v1/tokens', metaApiMetrics, - ncMetaAclMw(apiTokenList, 'apiTokenList', { + ncMetaAclMw(getHandler(apiTokenList, apiTokenListEE), 'apiTokenList', { // allowedRoles: [OrgUserRoles.SUPER], blockApiTokenAccess: true, }) diff --git a/packages/nocodb/src/lib/meta/helpers/getHandler.ts b/packages/nocodb/src/lib/meta/helpers/getHandler.ts new file mode 100644 index 0000000000..2d224de923 --- /dev/null +++ b/packages/nocodb/src/lib/meta/helpers/getHandler.ts @@ -0,0 +1,16 @@ +import express from 'express'; +import { LICENSE_KEY } from '../../constants'; +import Store from '../../models/Store'; + +export default function getHandler( + defaultHandler: express.Handler, + eeHandler: express.Handler +): express.Handler { + return async (...args) => { + const key = await Store.get(LICENSE_KEY); + if (!key?.value) { + return defaultHandler(...args); + } + return eeHandler(...args); + }; +}