Browse Source

Merge pull request #7044 from nocodb/fix/4330-hide-signup-link

Remove signup link from signup page if invite only signup enabled
nc-oss/44517c26
Raju Udava 1 year ago committed by GitHub
parent
commit
0384ec5b91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      packages/nc-gui/composables/useGlobal/state.ts
  2. 1
      packages/nc-gui/composables/useGlobal/types.ts
  3. 2
      packages/nc-gui/pages/signin.vue
  4. 32
      packages/nocodb/src/models/Store.ts
  5. 11
      packages/nocodb/src/services/utils.service.ts
  6. 1
      packages/nocodb/src/utils/globals.ts

1
packages/nc-gui/composables/useGlobal/state.ts

@ -109,6 +109,7 @@ export function useGlobalState(storageKey = 'nocodb-gui-v2'): State {
automationLogLevel: 'OFF', automationLogLevel: 'OFF',
disableEmailAuth: false, disableEmailAuth: false,
dashboardPath: '/dashboard', dashboardPath: '/dashboard',
inviteOnlySignup: false,
}) })
/** reactive token payload */ /** reactive token payload */

1
packages/nc-gui/composables/useGlobal/types.ts

@ -34,6 +34,7 @@ export interface AppInfo {
disableEmailAuth: boolean disableEmailAuth: boolean
mainSubDomain?: string mainSubDomain?: string
dashboardPath: string dashboardPath: string
inviteOnlySignup: boolean
} }
export interface StoredState { export interface StoredState {

2
packages/nc-gui/pages/signin.vue

@ -184,7 +184,7 @@ function navigateForgotPassword() {
</a> </a>
</div> </div>
<div class="text-end prose-sm"> <div class="text-end prose-sm" v-if="!appInfo.inviteOnlySignup">
{{ $t('msg.info.signUp.dontHaveAccount') }} {{ $t('msg.info.signUp.dontHaveAccount') }}
<nuxt-link @click="navigateSignUp">{{ $t('general.signUp') }}</nuxt-link> <nuxt-link @click="navigateSignUp">{{ $t('general.signUp') }}</nuxt-link>
</div> </div>

32
packages/nocodb/src/models/Store.ts

@ -2,7 +2,8 @@ import type { SortType } from 'nocodb-sdk';
import { NcError } from '~/helpers/catchError'; import { NcError } from '~/helpers/catchError';
import { extractProps } from '~/helpers/extractProps'; import { extractProps } from '~/helpers/extractProps';
import Noco from '~/Noco'; import Noco from '~/Noco';
import { MetaTable } from '~/utils/globals'; import { CacheGetType, CacheScope, MetaTable } from '~/utils/globals';
import NocoCache from '~/cache/NocoCache';
// Store is used for storing key value pairs // Store is used for storing key value pairs
export default class Store { export default class Store {
@ -18,8 +19,30 @@ export default class Store {
Object.assign(this, data); Object.assign(this, data);
} }
public static get(key: string, ncMeta = Noco.ncMeta): Promise<Store> { public static async get(
return ncMeta.metaGet(null, null, MetaTable.STORE, { key }); key: string,
lookInCache = false,
ncMeta = Noco.ncMeta,
): Promise<Store> {
// get from cache if lookInCache is true
if (lookInCache) {
const storeData =
key &&
(await NocoCache.get(
`${CacheScope.STORE}:${key}`,
CacheGetType.TYPE_OBJECT,
));
if (storeData) return storeData;
}
const storeData = await ncMeta.metaGet(null, null, MetaTable.STORE, {
key,
});
if (lookInCache)
await NocoCache.set(`${CacheScope.STORE}:${key}`, storeData);
return storeData;
} }
static async saveOrUpdate(store: Store, ncMeta = Noco.ncMeta) { static async saveOrUpdate(store: Store, ncMeta = Noco.ncMeta) {
@ -35,7 +58,7 @@ export default class Store {
'tag', 'tag',
]); ]);
const existing = await Store.get(store.key, ncMeta); const existing = await Store.get(store.key,false, ncMeta);
if (existing) { if (existing) {
await ncMeta.metaUpdate(null, null, MetaTable.STORE, insertObj, { await ncMeta.metaUpdate(null, null, MetaTable.STORE, insertObj, {
key: store.key, key: store.key,
@ -43,5 +66,6 @@ export default class Store {
} else { } else {
await ncMeta.metaInsert(null, null, MetaTable.STORE, insertObj); await ncMeta.metaInsert(null, null, MetaTable.STORE, insertObj);
} }
if (store.key) await NocoCache.del(`${CacheScope.STORE}:${store.key}`);
} }
} }

11
packages/nocodb/src/services/utils.service.ts

@ -5,10 +5,10 @@ import { ViewTypes } from 'nocodb-sdk';
import { ConfigService } from '@nestjs/config'; import { ConfigService } from '@nestjs/config';
import { useAgent } from 'request-filtering-agent'; import { useAgent } from 'request-filtering-agent';
import type { AppConfig } from '~/interface/config'; import type { AppConfig } from '~/interface/config';
import { NC_ATTACHMENT_FIELD_SIZE } from '~/constants'; import { NC_APP_SETTINGS, NC_ATTACHMENT_FIELD_SIZE } from '~/constants';
import SqlMgrv2 from '~/db/sql-mgr/v2/SqlMgrv2'; import SqlMgrv2 from '~/db/sql-mgr/v2/SqlMgrv2';
import { NcError } from '~/helpers/catchError'; import { NcError } from '~/helpers/catchError';
import { Base, User } from '~/models'; import { Base, Store, User } from '~/models';
import Noco from '~/Noco'; import Noco from '~/Noco';
import NcConnectionMgrv2 from '~/utils/common/NcConnectionMgrv2'; import NcConnectionMgrv2 from '~/utils/common/NcConnectionMgrv2';
import { MetaTable } from '~/utils/globals'; import { MetaTable } from '~/utils/globals';
@ -365,6 +365,12 @@ export class UtilsService {
async appInfo(param: { req: { ncSiteUrl: string } }) { async appInfo(param: { req: { ncSiteUrl: string } }) {
const baseHasAdmin = !(await User.isFirst()); const baseHasAdmin = !(await User.isFirst());
let settings: { invite_only_signup?: boolean } = {};
try {
settings = JSON.parse((await Store.get(NC_APP_SETTINGS, true))?.value);
} catch {}
const oidcAuthEnabled = !!( const oidcAuthEnabled = !!(
process.env.NC_OIDC_ISSUER && process.env.NC_OIDC_ISSUER &&
process.env.NC_OIDC_AUTHORIZATION_URL && process.env.NC_OIDC_AUTHORIZATION_URL &&
@ -415,6 +421,7 @@ export class UtilsService {
}), }),
mainSubDomain: this.configService.get('mainSubDomain', { infer: true }), mainSubDomain: this.configService.get('mainSubDomain', { infer: true }),
dashboardPath: this.configService.get('dashboardPath', { infer: true }), dashboardPath: this.configService.get('dashboardPath', { infer: true }),
inviteOnlySignup: settings.invite_only_signup,
}; };
return result; return result;

1
packages/nocodb/src/utils/globals.ts

@ -158,6 +158,7 @@ export enum CacheScope {
SINGLE_QUERY = 'singleQuery', SINGLE_QUERY = 'singleQuery',
JOBS = 'nc_jobs', JOBS = 'nc_jobs',
PRESIGNED_URL = 'presignedUrl', PRESIGNED_URL = 'presignedUrl',
STORE = 'presignedUrl',
} }
export enum CacheGetType { export enum CacheGetType {

Loading…
Cancel
Save