Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(): add IS_MULTIWORKSPACE_ENABLE flag #8656

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/twenty-front/src/generated/graphql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ export type ClientConfig = {
captcha: Captcha;
chromeExtensionId?: Maybe<Scalars['String']>;
debugMode: Scalars['Boolean'];
isMultiworkspaceEnabled: Scalars['Boolean'];
sentry: Sentry;
signInPrefilled: Scalars['Boolean'];
signUpDisabled: Scalars['Boolean'];
support: Support;
};

Expand Down Expand Up @@ -1780,7 +1780,7 @@ export type UpdateBillingSubscriptionMutation = { __typename?: 'Mutation', updat
export type GetClientConfigQueryVariables = Exact<{ [key: string]: never; }>;


export type GetClientConfigQuery = { __typename?: 'Query', clientConfig: { __typename?: 'ClientConfig', signInPrefilled: boolean, signUpDisabled: boolean, debugMode: boolean, analyticsEnabled: boolean, chromeExtensionId?: string | null, authProviders: { __typename?: 'AuthProviders', google: boolean, password: boolean, microsoft: boolean, sso: boolean }, billing: { __typename?: 'Billing', isBillingEnabled: boolean, billingUrl?: string | null, billingFreeTrialDurationInDays?: number | null }, support: { __typename?: 'Support', supportDriver: string, supportFrontChatId?: string | null }, sentry: { __typename?: 'Sentry', dsn?: string | null, environment?: string | null, release?: string | null }, captcha: { __typename?: 'Captcha', provider?: CaptchaDriverType | null, siteKey?: string | null }, api: { __typename?: 'ApiConfig', mutationMaximumAffectedRecords: number } } };
export type GetClientConfigQuery = { __typename?: 'Query', clientConfig: { __typename?: 'ClientConfig', signInPrefilled: boolean, isMultiworkspaceEnabled: boolean, debugMode: boolean, analyticsEnabled: boolean, chromeExtensionId?: string | null, authProviders: { __typename?: 'AuthProviders', google: boolean, password: boolean, microsoft: boolean, sso: boolean }, billing: { __typename?: 'Billing', isBillingEnabled: boolean, billingUrl?: string | null, billingFreeTrialDurationInDays?: number | null }, support: { __typename?: 'Support', supportDriver: string, supportFrontChatId?: string | null }, sentry: { __typename?: 'Sentry', dsn?: string | null, environment?: string | null, release?: string | null }, captcha: { __typename?: 'Captcha', provider?: CaptchaDriverType | null, siteKey?: string | null }, api: { __typename?: 'ApiConfig', mutationMaximumAffectedRecords: number } } };

export type SkipSyncEmailOnboardingStepMutationVariables = Exact<{ [key: string]: never; }>;

Expand Down Expand Up @@ -3096,7 +3096,7 @@ export const GetClientConfigDocument = gql`
billingFreeTrialDurationInDays
}
signInPrefilled
signUpDisabled
isMultiworkspaceEnabled
debugMode
analyticsEnabled
support {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { isAnalyticsEnabledState } from '@/client-config/states/isAnalyticsEnabl
import { isClientConfigLoadedState } from '@/client-config/states/isClientConfigLoadedState';
import { isDebugModeState } from '@/client-config/states/isDebugModeState';
import { isSignInPrefilledState } from '@/client-config/states/isSignInPrefilledState';
import { isSignUpDisabledState } from '@/client-config/states/isSignUpDisabledState';
import { isMultiWorkspaceEnabledState } from '@/client-config/states/isMultiWorkspaceEnabledState';
import { sentryConfigState } from '@/client-config/states/sentryConfigState';
import { supportChatState } from '@/client-config/states/supportChatState';
import { useEffect } from 'react';
Expand All @@ -21,7 +21,9 @@ export const ClientConfigProviderEffect = () => {
const setIsAnalyticsEnabled = useSetRecoilState(isAnalyticsEnabledState);

const setIsSignInPrefilled = useSetRecoilState(isSignInPrefilledState);
const setIsSignUpDisabled = useSetRecoilState(isSignUpDisabledState);
const setIsMultiworkspaceEnabled = useSetRecoilState(
isMultiWorkspaceEnabledState,
);

const setBilling = useSetRecoilState(billingState);
const setSupportChat = useSetRecoilState(supportChatState);
Expand Down Expand Up @@ -54,7 +56,7 @@ export const ClientConfigProviderEffect = () => {
setIsDebugMode(data?.clientConfig.debugMode);
setIsAnalyticsEnabled(data?.clientConfig.analyticsEnabled);
setIsSignInPrefilled(data?.clientConfig.signInPrefilled);
setIsSignUpDisabled(data?.clientConfig.signUpDisabled);
setIsMultiworkspaceEnabled(data?.clientConfig.isMultiworkspaceEnabled);
AMoreaux marked this conversation as resolved.
Show resolved Hide resolved

setBilling(data?.clientConfig.billing);
setSupportChat(data?.clientConfig.support);
Expand All @@ -78,7 +80,7 @@ export const ClientConfigProviderEffect = () => {
setAuthProviders,
setIsDebugMode,
setIsSignInPrefilled,
setIsSignUpDisabled,
setIsMultiworkspaceEnabled,
setSupportChat,
setBilling,
setSentryConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const GET_CLIENT_CONFIG = gql`
billingFreeTrialDurationInDays
}
signInPrefilled
signUpDisabled
isMultiworkspaceEnabled
debugMode
analyticsEnabled
support {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { createState } from 'twenty-ui';

export const isMultiWorkspaceEnabledState = createState<boolean>({
key: 'isMultiworkspaceEnabled',
AMoreaux marked this conversation as resolved.
Show resolved Hide resolved
defaultValue: true,
AMoreaux marked this conversation as resolved.
Show resolved Hide resolved
});

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { NavigationDrawerAnimatedCollapseWrapper } from '@/ui/navigation/navigat
import { isNavigationDrawerExpandedState } from '@/ui/navigation/states/isNavigationDrawerExpanded';
import { isNonEmptyString } from '@sniptt/guards';
import { NavigationDrawerCollapseButton } from './NavigationDrawerCollapseButton';
import { isMultiWorkspaceEnabledState } from '@/client-config/states/isMultiWorkspaceEnabledState';

const StyledContainer = styled.div`
align-items: center;
Expand Down Expand Up @@ -60,7 +61,9 @@ export const NavigationDrawerHeader = ({
}: NavigationDrawerHeaderProps) => {
const isMobile = useIsMobile();
const workspaces = useRecoilValue(workspacesState);
const isMultiWorkspace = workspaces !== null && workspaces.length > 1;
const isMultiWorkspaceEnabled = useRecoilValue(isMultiWorkspaceEnabledState);
const isMultiWorkspace =
workspaces !== null && workspaces.length > 1 && isMultiWorkspaceEnabled;
const isNavigationDrawerExpanded = useRecoilValue(
isNavigationDrawerExpandedState,
);
Expand Down
2 changes: 1 addition & 1 deletion packages/twenty-server/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ACCESS_TOKEN_SECRET=replace_me_with_a_random_string_access
# IS_BILLING_ENABLED=false
# BILLING_PLAN_REQUIRED_LINK=https://twenty.com/stripe-redirection
# AUTH_PASSWORD_ENABLED=false
# IS_SIGN_UP_DISABLED=false
# IS_MULTIWORKSPACE_ENABLED=false
# AUTH_MICROSOFT_ENABLED=false
# AUTH_MICROSOFT_CLIENT_ID=replace_me_with_azure_client_id
# AUTH_MICROSOFT_TENANT_ID=replace_me_with_azure_tenant_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,16 @@ export class SignInUpService {
lastName: string;
picture: SignInUpServiceInput['picture'];
}) {
if (this.environmentService.get('IS_SIGN_UP_DISABLED')) {
throw new AuthException(
'Sign up is disabled',
AuthExceptionCode.FORBIDDEN_EXCEPTION,
);
if (!this.environmentService.get('IS_MULTIWORKSPACE_ENABLED')) {
const numberOfWorkspaces = await this.workspaceRepository.count();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

workspacesCount


// let the creation of the first workspace
if (numberOfWorkspaces > 0) {
throw new AuthException(
'New workspace setup is disabled',
AuthExceptionCode.FORBIDDEN_EXCEPTION,
);
}
}

const workspaceToCreate = this.workspaceRepository.create({
AMoreaux marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class ClientConfig {
signInPrefilled: boolean;

@Field(() => Boolean)
signUpDisabled: boolean;
isMultiworkspaceEnabled: boolean;

@Field(() => Boolean)
debugMode: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ export class ClientConfigResolver {
'BILLING_FREE_TRIAL_DURATION_IN_DAYS',
),
},

signInPrefilled: this.environmentService.get('SIGN_IN_PREFILLED'),
signUpDisabled: this.environmentService.get('IS_SIGN_UP_DISABLED'),
isMultiworkspaceEnabled: this.environmentService.get(
'IS_MULTIWORKSPACE_ENABLED',
),
debugMode: this.environmentService.get('DEBUG_MODE'),
support: {
supportDriver: this.environmentService.get('SUPPORT_DRIVER'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ export class EnvironmentVariables {
@IsOptional()
ENTERPRISE_KEY: string;

@CastToBoolean()
@IsOptional()
@IsBoolean()
IS_MULTIWORKSPACE_ENABLED = false;
AMoreaux marked this conversation as resolved.
Show resolved Hide resolved

// Custom Code Engine
@IsEnum(ServerlessDriverType)
@IsOptional()
Expand Down Expand Up @@ -368,11 +373,6 @@ export class EnvironmentVariables {
@ValidateIf((env) => env.WORKSPACE_INACTIVE_DAYS_BEFORE_NOTIFICATION > 0)
WORKSPACE_INACTIVE_DAYS_BEFORE_DELETION = 60;

@CastToBoolean()
@IsOptional()
@IsBoolean()
IS_SIGN_UP_DISABLED = false;

@IsEnum(CaptchaDriverType)
@IsOptional()
CAPTCHA_DRIVER?: CaptchaDriverType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ yarn command:prod cron:calendar:calendar-event-list-fetch
['AUTH_MICROSOFT_CALLBACK_URL', 'http://[YourDomain]/auth/microsoft/redirect', 'Microsoft auth callback'],
['AUTH_MICROSOFT_APIS_CALLBACK_URL', 'http://[YourDomain]/auth/microsoft-apis/get-access-token', 'Microsoft APIs auth callback'],
['FRONT_AUTH_CALLBACK_URL', 'http://localhost:3001/verify ', 'Callback used for Login page'],
['IS_SIGN_UP_DISABLED', 'false', 'Disable sign-up'],
['IS_MULTIWORKSPACE_ENABLED', 'false', 'Allows the use of multiple workspaces. Requires a web server that can manage wildcards for subdomains.'],
['PASSWORD_RESET_TOKEN_EXPIRES_IN', '5m', 'Password reset token expiration time'],
]}></ArticleTable>

Expand Down
Loading