Browse Source

test: keep default signup settings behaviour same

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/4134/head
Pranav C 2 years ago
parent
commit
aa9090ded0
  1. 6
      packages/nc-gui/components/account/SignupSettings.vue
  2. 2
      packages/nc-gui/lang/en.json
  3. 6
      packages/nocodb-sdk/src/lib/Api.ts
  4. 4
      packages/nocodb/src/lib/meta/api/userApi/userApis.ts
  5. 13
      packages/nocodb/src/lib/version-upgrader/ncProjectRolesUpgrader.ts
  6. 15
      packages/nocodb/tests/unit/rest/tests/org.test.ts
  7. 4
      scripts/sdk/swagger.json

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

@ -6,7 +6,7 @@ const { api } = useApi()
const { t } = useI18n() const { t } = useI18n()
let settings = $ref<{ enable_user_signup?: boolean }>({ enable_user_signup: false }) let settings = $ref<{ invite_only_signup?: boolean }>({ invite_only_signup: false })
const loadSettings = async () => { const loadSettings = async () => {
try { try {
@ -36,13 +36,13 @@ loadSettings()
<div class="-ml-6"> <div class="-ml-6">
<a-form-item> <a-form-item>
<a-checkbox <a-checkbox
v-model:checked="settings.enable_user_signup" v-model:checked="settings.invite_only_signup"
v-e="['c:account:enable-signup']" v-e="['c:account:enable-signup']"
class="nc-checkbox" class="nc-checkbox"
name="virtual" name="virtual"
@change="saveSettings" @change="saveSettings"
> >
{{ $t('labels.enableSignup') }} {{ $t('labels.inviteOnlySignup') }}
</a-checkbox> </a-checkbox>
</a-form-item> </a-form-item>
</div> </div>

2
packages/nc-gui/lang/en.json

@ -300,7 +300,7 @@
"signInWithGoogle": "Sign in with Google", "signInWithGoogle": "Sign in with Google",
"agreeToTos": "By signing up, you agree to the Terms of Service", "agreeToTos": "By signing up, you agree to the Terms of Service",
"welcomeToNc": "Welcome to NocoDB!", "welcomeToNc": "Welcome to NocoDB!",
"enableSignup": "Enable user signup" "inviteOnlySignup": "Allow signup only using invite url"
}, },
"activity": { "activity": {
"createProject": "Create Project", "createProject": "Create Project",

6
packages/nocodb-sdk/src/lib/Api.ts

@ -1207,10 +1207,10 @@ export class Api<
* @name Get * @name Get
* @summary App settings get * @summary App settings get
* @request GET:/api/v1/app-settings * @request GET:/api/v1/app-settings
* @response `200` `{ enable_user_signup?: boolean }` OK * @response `200` `{ invite_only_signup?: boolean }` OK
*/ */
get: (params: RequestParams = {}) => get: (params: RequestParams = {}) =>
this.request<{ enable_user_signup?: boolean }, any>({ this.request<{ invite_only_signup?: boolean }, any>({
path: `/api/v1/app-settings`, path: `/api/v1/app-settings`,
method: 'GET', method: 'GET',
format: 'json', format: 'json',
@ -1226,7 +1226,7 @@ export class Api<
* @request POST:/api/v1/app-settings * @request POST:/api/v1/app-settings
* @response `200` `void` OK * @response `200` `void` OK
*/ */
set: (data: { enable_user_signup?: boolean }, params: RequestParams = {}) => set: (data: { invite_only_signup?: boolean }, params: RequestParams = {}) =>
this.request<void, any>({ this.request<void, any>({
path: `/api/v1/app-settings`, path: `/api/v1/app-settings`,
method: 'POST', method: 'POST',

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

@ -99,12 +99,12 @@ export async function signup(req: Request, res: Response<TableType>) {
count: 1, count: 1,
}); });
} else { } else {
let settings: { enable_user_signup?: boolean } = {}; let settings: { invite_only_signup?: boolean } = {};
try { try {
settings = JSON.parse((await Store.get(NC_APP_SETTINGS))?.value); settings = JSON.parse((await Store.get(NC_APP_SETTINGS))?.value);
} catch {} } catch {}
if (!settings?.enable_user_signup) { if (settings?.invite_only_signup) {
NcError.badRequest('Not allowed to signup, contact super admin.'); NcError.badRequest('Not allowed to signup, contact super admin.');
} else { } else {
roles = OrgUserRoles.VIEWER; roles = OrgUserRoles.VIEWER;

13
packages/nocodb/src/lib/version-upgrader/ncProjectRolesUpgrader.ts

@ -1,4 +1,6 @@
import { OrgUserRoles } from '../../enums/OrgUserRoles'; import { OrgUserRoles } from '../../enums/OrgUserRoles';
import { NC_APP_SETTINGS } from '../constants';
import Store from '../models/Store';
import { MetaTable } from '../utils/globals'; import { MetaTable } from '../utils/globals';
import { NcUpgraderCtx } from './NcUpgrader'; import { NcUpgraderCtx } from './NcUpgrader';
@ -27,4 +29,15 @@ export default async function ({ ncMeta }: NcUpgraderCtx) {
user.id user.id
); );
} }
// set invite only signup if user have environment variable set
if (process.env.NC_INVITE_ONLY_SIGNUP) {
await Store.saveOrUpdate(
{
value: '{ "invite_only_signup": true }',
key: NC_APP_SETTINGS,
},
ncMeta
);
}
} }

15
packages/nocodb/tests/unit/rest/tests/org.test.ts

@ -166,13 +166,21 @@ function authTests() {
}) })
it('Disable/Enable signup', async () => { it.only('Disable/Enable signup', async () => {
const args = { const args = {
email: 'dummyuser@example.com', email: 'dummyuser@example.com',
password: 'A1234abh2@dsad', password: 'A1234abh2@dsad',
}; };
const failedRes = await request(context.app)
await request(context.app)
.post('/api/v1/app-settings')
.set('xc-auth', context.token)
.send({ invite_only_signup: true })
.expect(200)
const failedRes = await request(context.app)
.post('/api/v1/auth/user/signup') .post('/api/v1/auth/user/signup')
.send(args) .send(args)
.expect(400) .expect(400)
@ -184,7 +192,7 @@ function authTests() {
await request(context.app) await request(context.app)
.post('/api/v1/app-settings') .post('/api/v1/app-settings')
.set('xc-auth', context.token) .set('xc-auth', context.token)
.send({ enable_user_signup: true }) .send({ invite_only_signup: false })
.expect(200) .expect(200)
@ -211,5 +219,4 @@ function authTests() {
} }
export default function() { export default function() {
describe('Organisation', authTests)
} }

4
scripts/sdk/swagger.json

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

Loading…
Cancel
Save