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. 13
      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()
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 () => {
try {
@ -36,13 +36,13 @@ loadSettings()
<div class="-ml-6">
<a-form-item>
<a-checkbox
v-model:checked="settings.enable_user_signup"
v-model:checked="settings.invite_only_signup"
v-e="['c:account:enable-signup']"
class="nc-checkbox"
name="virtual"
@change="saveSettings"
>
{{ $t('labels.enableSignup') }}
{{ $t('labels.inviteOnlySignup') }}
</a-checkbox>
</a-form-item>
</div>

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

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

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

@ -1207,10 +1207,10 @@ export class Api<
* @name Get
* @summary App settings get
* @request GET:/api/v1/app-settings
* @response `200` `{ enable_user_signup?: boolean }` OK
* @response `200` `{ invite_only_signup?: boolean }` OK
*/
get: (params: RequestParams = {}) =>
this.request<{ enable_user_signup?: boolean }, any>({
this.request<{ invite_only_signup?: boolean }, any>({
path: `/api/v1/app-settings`,
method: 'GET',
format: 'json',
@ -1226,7 +1226,7 @@ export class Api<
* @request POST:/api/v1/app-settings
* @response `200` `void` OK
*/
set: (data: { enable_user_signup?: boolean }, params: RequestParams = {}) =>
set: (data: { invite_only_signup?: boolean }, params: RequestParams = {}) =>
this.request<void, any>({
path: `/api/v1/app-settings`,
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,
});
} else {
let settings: { enable_user_signup?: boolean } = {};
let settings: { invite_only_signup?: boolean } = {};
try {
settings = JSON.parse((await Store.get(NC_APP_SETTINGS))?.value);
} catch {}
if (!settings?.enable_user_signup) {
if (settings?.invite_only_signup) {
NcError.badRequest('Not allowed to signup, contact super admin.');
} else {
roles = OrgUserRoles.VIEWER;

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

@ -1,4 +1,6 @@
import { OrgUserRoles } from '../../enums/OrgUserRoles';
import { NC_APP_SETTINGS } from '../constants';
import Store from '../models/Store';
import { MetaTable } from '../utils/globals';
import { NcUpgraderCtx } from './NcUpgrader';
@ -27,4 +29,15 @@ export default async function ({ ncMeta }: NcUpgraderCtx) {
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
);
}
}

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

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

4
scripts/sdk/swagger.json

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

Loading…
Cancel
Save