Browse Source

feat: implement signup disable based on app settings

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/4134/head
Pranav C 2 years ago
parent
commit
49bdffe4fc
  1. 6
      packages/nc-gui/components/admin/SignupSettings.vue
  2. 18
      packages/nocodb/src/lib/meta/api/ee/index.ts
  3. 2
      packages/nocodb/src/lib/meta/api/orgUserApis.ts
  4. 10
      packages/nocodb/src/lib/meta/api/userApi/userApis.ts
  5. 4
      scripts/sdk/swagger.json

6
packages/nc-gui/components/admin/SignupSettings.vue

@ -4,7 +4,7 @@ import { extractSdkResponseErrorMsg, useApi } from '#imports'
const { api } = useApi()
let settings = $ref({ enable_user_signup: false })
let settings = $ref({ disable_user_signup: false })
const loadSettings = async () => {
try {
@ -33,8 +33,8 @@ loadSettings()
<div class="text-xl">Settings</div>
<a-divider class="!my-3" />
<a-form-item>
<a-checkbox v-model:checked="settings.enable_user_signup" name="virtual" @change="saveSettings"
>Enable user signup</a-checkbox
<a-checkbox v-model:checked="settings.disable_user_signup" name="virtual" @change="saveSettings"
>Disable user signup</a-checkbox
>
</a-form-item>
</div>

18
packages/nocodb/src/lib/meta/api/ee/index.ts

@ -0,0 +1,18 @@
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;

2
packages/nocodb/src/lib/meta/api/orgUserApis.ts

@ -243,7 +243,7 @@ async function appSettingsSet(req, res) {
key: NC_APP_SETTINGS,
});
res.json({ msg: 'License key saved' });
res.json({ msg: 'Settings saved' });
}
const router = Router({ mergeParams: true });

10
packages/nocodb/src/lib/meta/api/userApi/userApis.ts

@ -1,8 +1,11 @@
import { Request, Response } from 'express';
import { TableType, validatePassword } from 'nocodb-sdk';
import { OrgUserRoles } from '../../../../enums/OrgUserRoles';
import { NC_APP_SETTINGS } from '../../../constants';
import Store from '../../../models/Store';
import { Tele } from '../../../utils/Tele';
import catchError, { NcError } from '../../helpers/catchError';
const { isEmail } = require('validator');
import * as ejs from 'ejs';
@ -96,7 +99,12 @@ export async function signup(req: Request, res: Response<TableType>) {
count: 1,
});
} else {
if (process.env.NC_INVITE_ONLY_SIGNUP) {
let settings: { disable_user_signup?: boolean } = {};
try {
settings = JSON.parse((await Store.get(NC_APP_SETTINGS))?.value);
} catch {}
if (process.env.NC_INVITE_ONLY_SIGNUP || settings?.disable_user_signup) {
NcError.badRequest('Not allowed to signup, contact super admin.');
} else {
roles = OrgUserRoles.VIEWER;

4
scripts/sdk/swagger.json

@ -584,7 +584,7 @@
"schema": {
"type": "object",
"properties": {
"enable_user_signup": {
"disable_user_signup": {
"type": "boolean"
}
}
@ -613,7 +613,7 @@
"schema": {
"type": "object",
"properties": {
"enable_user_signup": {
"disable_user_signup": {
"type": "boolean"
}
}

Loading…
Cancel
Save