Browse Source

feat: add license page

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/4716/head
Pranav C 2 years ago
parent
commit
eac47a0dbf
  1. 1
      packages/nc-gui/components.d.ts
  2. 4
      packages/nc-gui/components/account/License.vue
  3. 12
      packages/nc-gui/pages/account/index.vue
  4. 1
      packages/nc-gui/pages/account/index/[page].vue
  5. 7
      packages/nocodb/src/lib/Noco.ts
  6. 3
      packages/nocodb/src/lib/meta/api/orgLicenseApis.ts
  7. 4
      packages/nocodb/src/lib/meta/api/utilApis.ts
  8. 6
      packages/nocodb/src/lib/meta/helpers/getHandler.ts

1
packages/nc-gui/components.d.ts vendored

@ -190,6 +190,7 @@ declare module '@vue/runtime-core' {
MdiHook: typeof import('~icons/mdi/hook')['default']
MdiInformation: typeof import('~icons/mdi/information')['default']
MdiJson: typeof import('~icons/mdi/json')['default']
MdiKey: typeof import('~icons/mdi/key')['default']
MdiKeyboard: typeof import('~icons/mdi/keyboard')['default']
MdiKeyboardReturn: typeof import('~icons/mdi/keyboard-return')['default']
MdiKeyChange: typeof import('~icons/mdi/key-change')['default']

4
packages/nc-gui/components/account/License.vue

@ -35,10 +35,12 @@ loadLicense()
<template>
<div class="h-full overflow-y-scroll scrollbar-thin-dull">
<div class="text-xl mt-4 mb-8 text-center font-weight-bold">License</div>
<div class="mx-auto w-150">
<div>
<a-textarea v-model:value="key" placeholder="License key" class="!mt-2 !max-w-[600px]"></a-textarea>
</div>
<a-button class="mt-4" @click="setLicense" type="primary">Save license key</a-button>
<div class="text-center"> <a-button class="mt-4" @click="setLicense" type="primary">Save license key</a-button></div>
</div>
</div>
</template>

12
packages/nc-gui/pages/account/index.vue

@ -79,6 +79,18 @@ const openKeys = ref([/^\/account\/users/.test($route.fullPath) && 'users'])
<div class="select-none">App Store</div>
</div>
</a-menu-item>
<a-menu-item
v-if="isUIAllowed('license')"
key="apps"
class="group active:(!ring-0) hover:(!bg-primary !bg-opacity-25)"
@click="navigateTo('/account/license')"
>
<div class="flex items-center space-x-2">
<MdiKey />
<div class="select-none">License</div>
</div>
</a-menu-item>
</a-menu>
</div>
</a-layout-sider>

1
packages/nc-gui/pages/account/index/[page].vue

@ -2,5 +2,6 @@
<AccountUserManagement v-if="$route.params.page === 'users'" />
<AccountToken v-else-if="$route.params.page === 'tokens'" />
<AccountAppStore v-else-if="$route.params.page === 'apps'" />
<AccountLicense v-else-if="$route.params.page === 'license'" />
<span v-else></span>
</template>

7
packages/nocodb/src/lib/Noco.ts

@ -553,9 +553,8 @@ export default class Noco {
public static async loadEEState(): Promise<boolean> {
try {
return (Noco.ee = !!(await Store.get(NC_LICENSE_KEY)));
} catch {
return (Noco.ee = false);
}
return (Noco.ee = !!(await Store.get(NC_LICENSE_KEY))?.value);
} catch {}
return (Noco.ee = false);
}
}

3
packages/nocodb/src/lib/meta/api/orgLicenseApis.ts

@ -2,6 +2,7 @@ import { Router } from 'express';
import { OrgUserRoles } from 'nocodb-sdk';
import { NC_LICENSE_KEY } from '../../constants';
import Store from '../../models/Store';
import Noco from '../../Noco';
import { metaApiMetrics } from '../helpers/apiMetrics';
import ncMetaAclMw from '../helpers/ncMetaAclMw';
@ -13,7 +14,7 @@ async function licenseGet(_req, res) {
async function licenseSet(req, res) {
await Store.saveOrUpdate({ value: req.body.key, key: NC_LICENSE_KEY });
await Noco.loadEEState();
res.json({ msg: 'License key saved' });
}

4
packages/nocodb/src/lib/meta/api/utilApis.ts

@ -3,9 +3,7 @@ import { Request, Response } from 'express';
import { compareVersions, validate } from 'compare-versions';
import { ViewTypes } from 'nocodb-sdk';
import { NC_LICENSE_KEY } from '../../constants';
import Project from '../../models/Project';
import Store from '../../models/Store';
import Noco from '../../Noco';
import NcConnectionMgrv2 from '../../utils/common/NcConnectionMgrv2';
import { MetaTable } from '../../utils/globals';
@ -57,7 +55,7 @@ export async function appInfo(req: Request, res: Response) {
ncMin: !!process.env.NC_MIN,
teleEnabled: !process.env.NC_DISABLE_TELE,
ncSiteUrl: (req as any).ncSiteUrl,
ee: !!(await Store.get(NC_LICENSE_KEY)),
ee: Noco.isEE(),
};
res.json(result);

6
packages/nocodb/src/lib/meta/helpers/getHandler.ts

@ -1,14 +1,12 @@
import express from 'express';
import { NC_LICENSE_KEY } from '../../constants';
import Store from '../../models/Store';
import Noco from '../../Noco';
export default function getHandler(
defaultHandler: express.Handler,
eeHandler: express.Handler
): express.Handler {
return async (...args) => {
const key = await Store.get(NC_LICENSE_KEY);
if (!key?.value) {
if (Noco.isEE()) {
return defaultHandler(...args);
}
return eeHandler(...args);

Loading…
Cancel
Save