feat(ui): add allowGuestDemoWorkspace flag to force login
https://github.com/user-attachments/assets/41a659c9-6def-4492-be8e-5910eb148d6f
This PR enforces login‑first access (#8716) by disabling or enabling the guest demo workspace via Admin Server Client Page and redirecting unauthenticated users straight to /sign‑in.
Summary by CodeRabbit
-
New Features
- Added a configuration option to control whether guests can access the demo workspace.
- Server and client interfaces, as well as GraphQL queries and schemas, now support and expose the guest demo workspace setting.
- User navigation after sign-out has been updated to redirect appropriately based on the guest demo workspace setting.
- Unauthenticated users are redirected to sign-in if guest demo workspaces are disabled.
How to use the Graphite Merge Queue
Add either label to this PR to merge it via the merge queue:
- merge - adds this PR to the back of the merge queue
- hotfix - for urgent hot fixes, skip the queue and merge this PR next
You must have a Graphite account in order to use the merge queue. Sign up using this link.
An organization admin has enabled the Graphite Merge Queue in this repository.
Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.
Walkthrough
A new configuration flag, allowGuestDemoWorkspace, was introduced to control whether guest users can create demo workspaces. This flag is integrated across backend and frontend configuration, GraphQL schema, queries, and UI logic, with corresponding updates to access control, navigation, and tests to reflect the flag's value.
Changes
| Files/Paths | Change Summary |
|---|---|
.docker/selfhost/schema.json, packages/frontend/admin/src/config.json |
Added allowGuestDemoWorkspace boolean flag to configuration schemas with description and default value. |
packages/backend/server/src/core/config/config.ts |
Added allowGuestDemoWorkspace property to ServerFlags interface and module config with default/description. |
packages/backend/server/src/core/config/resolver.ts |
Exposed allowGuestDemoWorkspace in serverConfig() return object. |
packages/backend/server/src/core/config/types.ts, packages/backend/server/src/schema.gql |
Added allowGuestDemoWorkspace field to ServerConfigType GraphQL type. |
packages/common/graphql/src/graphql/admin/admin-server-config.gql, server-config.gql |
Added allowGuestDemoWorkspace field to relevant GraphQL queries. |
packages/common/graphql/src/graphql/index.ts |
Extended exported queries to select allowGuestDemoWorkspace. |
packages/common/graphql/src/schema.ts |
Added allowGuestDemoWorkspace to ServerConfigType and relevant query return types. |
packages/frontend/core/src/modules/cloud/types.ts |
Added allowGuestDemoWorkspace to ServerConfig interface. |
packages/frontend/core/src/modules/cloud/constant.ts |
Added allowGuestDemoWorkspace: true to all built-in server configs. |
packages/frontend/core/src/modules/cloud/entities/server.ts, .../services/servers.ts |
Propagated allowGuestDemoWorkspace in server config updates and additions. |
packages/frontend/core/src/components/hooks/affine/use-sign-out.ts |
Updated sign-out logic to route based on allowGuestDemoWorkspace flag. |
packages/frontend/core/src/components/hooks/affine/__tests__/use-sign-out.spec.ts |
Added tests for sign-out logic with/without guest demo workspace allowed. |
packages/frontend/core/src/components/cloud/share-header-right-item/user-avatar.tsx, ... |
After sign-out, added navigation to sign-in page. |
packages/frontend/core/src/components/workspace-selector/user-with-workspace-list/... |
Replaced inline sign-out logic with useSignOut hook. |
packages/frontend/core/src/desktop/pages/index/index.ts |
Enforced guest demo workspace restrictions for unauthenticated users; redirected as needed. |
packages/frontend/core/src/desktop/pages/invite/index.ts, .../mobile/components/.../menu.tsx |
After sign-out, navigated to sign-in page. |
packages/frontend/core/src/components/workspace-selector/user-with-workspace-list/add-workspace/index.tsx |
Replaced feature flag check with live server config allowGuestDemoWorkspace flag for local workspace creation. |
packages/frontend/core/src/components/workspace-selector/user-with-workspace-list/index.tsx |
Replaced feature flag check with live server config allowGuestDemoWorkspace flag for guest demo workspace allowance. |
packages/frontend/core/src/modules/feature-flag/constant.ts |
Removed enable_local_workspace feature flag and related environment check. |
Sequence Diagram(s)
sequenceDiagram
participant GuestUser
participant Frontend
participant Backend
participant Config
GuestUser->>Frontend: Attempt to create demo workspace or sign out
Frontend->>Backend: Fetch server config (includes allowGuestDemoWorkspace)
Backend->>Config: Return allowGuestDemoWorkspace flag
Backend-->>Frontend: allowGuestDemoWorkspace value
alt allowGuestDemoWorkspace == true
Frontend-->>GuestUser: Allow demo workspace / redirect to index after sign out
else allowGuestDemoWorkspace == false
Frontend-->>GuestUser: Block demo workspace / redirect to sign-in after sign out
end
Suggested labels
mod:infra
Suggested reviewers
- forehalo
Poem
A toggle for guests, now added with care,
Controls if demo workspaces appear anywhere.
If true, guests may roam and try out the site,
If false, they’re guided to sign-in’s bright light.
Code and config in harmony sing—
Flexibility’s here, let the rabbits spring! 🐇✨
📜 Recent review details
Configuration used: CodeRabbit UI Review profile: CHILL Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between e2f58cc4c4f0b594c93e91d7c88de8fb863650a7 and efba862600375e01695560e210f35cbf52d1a02b.
📒 Files selected for processing (1)
-
packages/common/graphql/src/schema.ts(3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/common/graphql/src/schema.ts
⏰ Context from checks skipped due to timeout of 90000ms (49)
- GitHub Check: E2E Test (6)
- GitHub Check: E2E Test (9)
- GitHub Check: E2E Test (10)
- GitHub Check: E2E Test (7)
- GitHub Check: E2E BlockSuite Test (7)
- GitHub Check: E2E Test (4)
- GitHub Check: E2E Test (8)
- GitHub Check: E2E Test (2)
- GitHub Check: E2E BlockSuite Cross Browser Test (2, webkit)
- GitHub Check: E2E Test (1)
- GitHub Check: E2E Test (3)
- GitHub Check: E2E Test (5)
- GitHub Check: E2E BlockSuite Test (10)
- GitHub Check: E2E BlockSuite Test (6)
- GitHub Check: E2E BlockSuite Test (5)
- GitHub Check: E2E BlockSuite Test (2)
- GitHub Check: E2E BlockSuite Test (1)
- GitHub Check: E2E BlockSuite Test (8)
- GitHub Check: E2E BlockSuite Test (9)
- GitHub Check: E2E BlockSuite Cross Browser Test (1, webkit)
- GitHub Check: E2E BlockSuite Test (4)
- GitHub Check: E2E BlockSuite Cross Browser Test (2, chromium)
- GitHub Check: Build AFFiNE native (aarch64-apple-darwin)
- GitHub Check: E2E BlockSuite Cross Browser Test (2, firefox)
- GitHub Check: Run native tests
- GitHub Check: E2E BlockSuite Test (3)
- GitHub Check: E2E BlockSuite Cross Browser Test (1, firefox)
- GitHub Check: E2E Mobile Test (5)
- GitHub Check: fuzzing
- GitHub Check: E2E Mobile Test (3)
- GitHub Check: E2E Mobile Test (1)
- GitHub Check: E2E BlockSuite Cross Browser Test (1, chromium)
- GitHub Check: E2E Mobile Test (2)
- GitHub Check: E2E Mobile Test (4)
- GitHub Check: y-octo binding test on x86_64-pc-windows-msvc
- GitHub Check: Build AFFiNE native (aarch64-pc-windows-msvc)
- GitHub Check: y-octo binding test on x86_64-apple-darwin
- GitHub Check: y-octo binding test on aarch64-pc-windows-msvc
- GitHub Check: y-octo binding test on aarch64-unknown-linux-gnu
- GitHub Check: Build AFFiNE native (x86_64-pc-windows-msvc)
- GitHub Check: Build @affine/electron renderer
- GitHub Check: loom thread test
- GitHub Check: Build Server native
- GitHub Check: Analyze (typescript, blocksuite)
- GitHub Check: Analyze (typescript, affine)
- GitHub Check: Analyze (javascript, affine)
- GitHub Check: Analyze (javascript, blocksuite)
- GitHub Check: Typecheck
- GitHub Check: Lint
✨ Finishing Touches
- [ ] 📝 Generate Docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
-
I pushed a fix in commit <commit_id>, please review it. -
Explain this complex logic. -
Open a follow-up GitHub issue for this discussion.
-
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:-
@coderabbitai explain this code block. -
@coderabbitai modularize this function.
-
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:-
@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase. -
@coderabbitai read src/utils.ts and explain its main purpose. -
@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format. -
@coderabbitai help me debug CodeRabbit configuration file.
-
Support
Need help? Create a ticket on our support page for assistance with any issues or questions.
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (Invoked using PR comments)
-
@coderabbitai pauseto pause the reviews on a PR. -
@coderabbitai resumeto resume the paused reviews. -
@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository. -
@coderabbitai full reviewto do a full review from scratch and review all the files again. -
@coderabbitai summaryto regenerate the summary of the PR. -
@coderabbitai generate docstringsto generate docstrings for this PR. -
@coderabbitai generate sequence diagramto generate a sequence diagram of the changes in this PR. -
@coderabbitai resolveresolve all the CodeRabbit review comments. -
@coderabbitai configurationto show the current CodeRabbit configuration for the repository. -
@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 56.28%. Comparing base (
a4680d2) to head (efba862). Report is 1 commits behind head on canary.
Additional details and impacted files
@@ Coverage Diff @@
## canary #12779 +/- ##
==========================================
- Coverage 56.69% 56.28% -0.41%
==========================================
Files 2674 2675 +1
Lines 128571 128606 +35
Branches 20248 20164 -84
==========================================
- Hits 72888 72383 -505
Misses 54055 54055
- Partials 1628 2168 +540
| Flag | Coverage Δ | |
|---|---|---|
| server-test | 78.79% <100.00%> (-0.96%) |
:arrow_down: |
| unittest | 31.90% <100.00%> (+0.01%) |
:arrow_up: |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
@NorkzYT the ci checks pass. plz sign the CLA so we can merge your code right now
Done.
The commit I made now ensures backward compatibility with older servers.
Fixing the typecheck.
@NorkzYT There is still a bug.
I set the allowGuestDemoWorkspace to false on https://affine.fail, but when I first open https://affine.fail in an incognito window, it still creates a demo workspace.
Only when I open https://affine.fail a second time does it redirect to the login page.
There seems to be a state issue here.
https://github.com/user-attachments/assets/5ecebfcf-1c34-42ba-b85e-ff913313deca
@fengmk2
Understood. Was it resolved in the above PR?
@fengmk2
Understood. Was it resolved in the above PR?
no, maybe you can continue to fix it
~~I will work on it this week.~~
Unable to for some weeks.