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(subdomain): use subdomain by workspace #8378

Draft
wants to merge 28 commits into
base: main
Choose a base branch
from

Conversation

AMoreaux
Copy link
Contributor

@AMoreaux AMoreaux commented Nov 6, 2024

Resolve #8386

  • Ensure SSO is functioning properly
  • Develop a strategy for feature flags and deployment that minimizes downtime and risk
  • Add documentation for environment variables
  • Enable listing or creation of workspaces upon logging into the app with Google Connect
  • Update the cookie in the new domain when a workspace is renamed
  • Automatically connect to the default or first workspace without requiring workspace selection
  • Swap the positions of the twenty and workspace logos, and make the twenty logo clickable to redirect to the homepage
  • Implement captchas for public routes. Check Guard Captcha for integration

Copy link

github-actions bot commented Nov 6, 2024

Warnings
⚠️ Changes were made to the environment variables, but not to the documentation - Please review your changes and check if a change needs to be documented!

TODOs/FIXMEs:

  • /* TODO AMOREAUX: Need design for this */}: packages/twenty-front/src/pages/auth/SignInUp.tsx
  • // TODO: improve error management: packages/twenty-server/src/engine/core-modules/auth/controllers/sso-auth.controller.ts
  • // TODO: improve error management: packages/twenty-server/src/engine/core-modules/auth/controllers/sso-auth.controller.ts
  • // TODO AMOREAUX: this logger is trigger twice and the second time the message is undefined for an unknown reason: packages/twenty-server/src/engine/core-modules/workspace/services/workspace.service.ts

Generated by 🚫 dangerJS against d1047ec

@AMoreaux AMoreaux force-pushed the feat/use-subdomain-by-workspace branch 3 times, most recently from 1866118 to ce86332 Compare November 7, 2024 17:08
Copy link
Member

@FelixMalfait FelixMalfait left a comment

Choose a reason for hiding this comment

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

I started having a quick look but not in depth. Looks like great work!!! Big piece!

@@ -0,0 +1,13 @@
export const getWorkspaceSubdomainByOrigin = (origin: string) => {
Copy link
Member

Choose a reason for hiding this comment

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

I didn't really understand what origin meant in this context, is it getWorkspaceSubdomainFromUrl or fromHostName?

Copy link
Contributor Author

Choose a reason for hiding this comment

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


const subdomain = hostParts[0];

if (subdomain === 'app') return;
Copy link
Member

Choose a reason for hiding this comment

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

We already have SERVER_URL and FRONT_BASE_URL I think. Could we re-use that instead of hardcoding app maybe?

# v0.32.0 to v0.33.0

Upgrade your Twenty instance to use v0.33.0 image
Copy link
Member

Choose a reason for hiding this comment

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

One thing we need to do I think is deprecate IS_SIGN_UP_DISABLED, instead it might be handy to introduce something like IS_MULTIWORKSPACE_ENABLED which defaults to false, could that help simplifying the code in other places? I'm not sure if this should be fully handled as part of this PR as there might be a few edge cases that are not well covered with the current IS_SIGN_UP_DISABLED (for the first time the user is signing up on a host instance / if workspaces.count === 0 then he's allowed to create a workspace)

```

The `yarn database:migrate:prod` command will apply the migrations to the database structure (core and metadata schemas)
Copy link
Member

Choose a reason for hiding this comment

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

Could you add instructions somewhere in the doc on how to setup/test multi-sub domains locally? That would help me review the PR also, as I didn't figure out how to test this locally

import { isDefined } from '~/utils/isDefined';
import { sleep } from '~/utils/sleep';
import { buildWorkspaceUrl } from '~/utils/workspace-url.helper';

export const useWorkspaceSwitching = () => {
Copy link
Member

Choose a reason for hiding this comment

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

The workspace switcher still works locally even though I'm in mono-domain mode, is that expected? I thought we wouldn't manage to make it work without multi-domain

# Conflicts:
#	packages/twenty-website/src/content/developers/self-hosting/upgrade-guide.mdx

# Conflicts:
#	packages/twenty-front/vite.config.ts
# Conflicts:
#	packages/twenty-front/src/generated/graphql.tsx
# Conflicts:
#	packages/twenty-front/src/modules/settings/security/components/SettingsSecurityOptionsList.tsx
@AMoreaux AMoreaux force-pushed the feat/use-subdomain-by-workspace branch from d6b17ee to 42eafbb Compare November 8, 2024 18:09
@AMoreaux AMoreaux force-pushed the feat/use-subdomain-by-workspace branch from 42eafbb to d80e940 Compare November 12, 2024 09:33
…ML parsing

Simplified the retrieval of server URLs by introducing `ServerUrl` utility. Updated callback and issuer URL building in SSO service to use this utility. Enhanced SAML metadata parsing to handle potential null scenarios, and fixed type issues in several frontend components.
Replace SignInUpForm with SignInUpWorkspaceScopeForm to handle SSO identity provider selection. Update workspace service and GraphQL queries to support detailed SSO identity provider information.
Separated sign-in/up password and email input fields into their own components for better modularity and readability. Also unified various states and utility functions under a multi-workspace enablement flag.
…by-workspace

# Conflicts:
#	packages/twenty-front/src/modules/auth/sign-in-up/components/SignInUpForm.tsx
#	packages/twenty-front/src/pages/auth/SSOWorkspaceSelection.tsx
Consolidate all HorizontalSeparator imports to 'twenty-ui' instead of local paths. This change simplifies module dependencies and ensures consistency across the sign-in and sign-up components.
@AMoreaux AMoreaux force-pushed the feat/use-subdomain-by-workspace branch from 836b2d5 to f63f488 Compare November 15, 2024 09:36
Refactor codebase to streamline user workspace handling by removing the findAvailableWorkspacesByEmail query. Updated related resolvers and components to integrate workspace retrieval logic directly within checkUserExists. Simplified GraphQL and client-side state management by consolidating workspace data flow.
Removed the useFindAvailableWorkspacesByEmail hook as it was no longer in use. Improved the workspace token handling by adding support for workspace-specific tokens and streamlined subdomain generation for workspaces based on user email or display name.
…by-workspace

# Conflicts:
#	packages/twenty-front/src/modules/settings/components/SettingsOptionCardContent.tsx
#	packages/twenty-front/src/modules/settings/security/components/SettingsSecurityOptionsList.tsx
#	packages/twenty-front/src/pages/settings/security/SettingsSecurity.tsx
#	packages/twenty-front/vite.config.ts
Simplify the login token generation process by eliminating the workspace ID parameter. Adjust relevant services and controllers to accommodate this change, reducing parameter dependency and enhancing code clarity.
Renamed StyledDeveloperSection to StyledContainer for reuse. Adjusted the security item rendering to conditionally include the advanced mode icon when enabled. Added comments regarding design considerations for this change.
Remove the workspace selection component and its associated state management logic. Updated the authentication flow to redirect to the first available workspace directly.
Updated various controllers and services to include WorkspaceService for multiworkspace subdomain conditional logic. Adjusted URL construction logic to handle single and multiworkspace modes seamlessly, ensuring proper redirects and configurations based on the environment settings.
…by-workspace

# Conflicts:
#	packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/NavigationDrawerSection.tsx
@AMoreaux AMoreaux marked this pull request as ready for review November 18, 2024 18:35
…ndling

Add a TODO comment for workspace logger issue where message becomes undefined. Adjust target workspace subdomain initialization based on multi-workspace environment setting.
Add conditional rendering to the domain section based on the multi-workspace feature state. This ensures the section is only displayed if the multi-workspace feature is enabled.
@AMoreaux
Copy link
Contributor Author

AMoreaux commented Nov 19, 2024

Please do not review this PR, I will split it into smaller PR.

#8579
#8581
#8587
#8585
#8589
#8604

@AMoreaux AMoreaux marked this pull request as draft November 19, 2024 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Environment variable IS_SIGN_UP_DISABLED ignored
3 participants