Repository: toeverything/AFFiNE
Pull request #12118: refactor(core): use workspace role query instead of isOwner query
Author: login: JimmFly
Labels: name: app:core
Created: 2025-05-03T07:29:20Z | Merged: 2025-05-13T03:33:22Z



<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **Refactor**
  - Updated workspace permission handling to use a unified role field within workspace data instead of separate admin and owner flags.
  - Permission checks now rely on the workspace role for determining admin and owner status.
- **Chores**
  - Removed deprecated queries and types related to admin and owner status.
  - Cleaned up internal logic and variable naming for improved consistency.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->


Diff:
diff --git a/packages/common/graphql/src/graphql/get-is-admin.gql b/packages/common/graphql/src/graphql/get-is-admin.gql
deleted file mode 100644
index 8e9199ab9b479..0000000000000
--- a/packages/common/graphql/src/graphql/get-is-admin.gql
+++ /dev/null
@@ -1,3 +0,0 @@
-query getIsAdmin($workspaceId: String!) {
-  isAdmin(workspaceId: $workspaceId)
-}
diff --git a/packages/common/graphql/src/graphql/get-is-owner.gql b/packages/common/graphql/src/graphql/get-is-owner.gql
deleted file mode 100644
index f9de28c683c2f..0000000000000
--- a/packages/common/graphql/src/graphql/get-is-owner.gql
+++ /dev/null
@@ -1,3 +0,0 @@
-query getIsOwner($workspaceId: String!) {
-  isOwner(workspaceId: $workspaceId)
-}
diff --git a/packages/common/graphql/src/graphql/get-workspace-info.gql b/packages/common/graphql/src/graphql/get-workspace-info.gql
index 3ebd59a2533b6..29bfe9d26977c 100644
--- a/packages/common/graphql/src/graphql/get-workspace-info.gql
+++ b/packages/common/graphql/src/graphql/get-workspace-info.gql
@@ -1,7 +1,6 @@
 query getWorkspaceInfo($workspaceId: String!) {
-  isAdmin(workspaceId: $workspaceId)
-  isOwner(workspaceId: $workspaceId)
   workspace(id: $workspaceId) {
+    role
     team
   }
 }
diff --git a/packages/common/graphql/src/graphql/index.ts b/packages/common/graphql/src/graphql/index.ts
index c23ad056af49f..ff7c06e7b7b27 100644
--- a/packages/common/graphql/src/graphql/index.ts
+++ b/packages/common/graphql/src/graphql/index.ts
@@ -1036,24 +1036,6 @@ export const getInviteInfoQuery = {
 }`,
 };
 
-export const getIsAdminQuery = {
-  id: 'getIsAdminQuery' as const,
-  op: 'getIsAdmin',
-  query: `query getIsAdmin($workspaceId: String!) {
-  isAdmin(workspaceId: $workspaceId)
-}`,
-  deprecations: ["'isAdmin' is deprecated: use WorkspaceType[role] instead"],
-};
-
-export const getIsOwnerQuery = {
-  id: 'getIsOwnerQuery' as const,
-  op: 'getIsOwner',
-  query: `query getIsOwner($workspaceId: String!) {
-  isOwner(workspaceId: $workspaceId)
-}`,
-  deprecations: ["'isOwner' is deprecated: use WorkspaceType[role] instead"],
-};
-
 export const getMemberCountByWorkspaceIdQuery = {
   id: 'getMemberCountByWorkspaceIdQuery' as const,
   op: 'getMemberCountByWorkspaceId',
@@ -1185,13 +1167,11 @@ export const getWorkspaceInfoQuery = {
   id: 'getWorkspaceInfoQuery' as const,
   op: 'getWorkspaceInfo',
   query: `query getWorkspaceInfo($workspaceId: String!) {
-  isAdmin(workspaceId: $workspaceId)
-  isOwner(workspaceId: $workspaceId)
   workspace(id: $workspaceId) {
+    role
     team
   }
 }`,
-  deprecations: ["'isAdmin' is deprecated: use WorkspaceType[role] instead","'isOwner' is deprecated: use WorkspaceType[role] instead"],
 };
 
 export const getWorkspacePageByIdQuery = {
diff --git a/packages/common/graphql/src/schema.ts b/packages/common/graphql/src/schema.ts
index 8444ef8a7383b..97395c613caa4 100644
--- a/packages/common/graphql/src/schema.ts
+++ b/packages/common/graphql/src/schema.ts
@@ -3665,18 +3665,6 @@ export type GetInviteInfoQuery = {
   };
 };
 
-export type GetIsAdminQueryVariables = Exact<{
-  workspaceId: Scalars['String']['input'];
-}>;
-
-export type GetIsAdminQuery = { __typename?: 'Query'; isAdmin: boolean };
-
-export type GetIsOwnerQueryVariables = Exact<{
-  workspaceId: Scalars['String']['input'];
-}>;
-
-export type GetIsOwnerQuery = { __typename?: 'Query'; isOwner: boolean };
-
 export type GetMemberCountByWorkspaceIdQueryVariables = Exact<{
   workspaceId: Scalars['String']['input'];
 }>;
@@ -3829,9 +3817,7 @@ export type GetWorkspaceInfoQueryVariables = Exact<{
 
 export type GetWorkspaceInfoQuery = {
   __typename?: 'Query';
-  isAdmin: boolean;
-  isOwner: boolean;
-  workspace: { __typename?: 'WorkspaceType'; team: boolean };
+  workspace: { __typename?: 'WorkspaceType'; role: Permission; team: boolean };
 };
 
 export type GetWorkspacePageByIdQueryVariables = Exact<{
@@ -4825,16 +4811,6 @@ export type Queries =
       variables: GetInviteInfoQueryVariables;
       response: GetInviteInfoQuery;
     }
-  | {
-      name: 'getIsAdminQuery';
-      variables: GetIsAdminQueryVariables;
-      response: GetIsAdminQuery;
-    }
-  | {
-      name: 'getIsOwnerQuery';
-      variables: GetIsOwnerQueryVariables;
-      response: GetIsOwnerQuery;
-    }
   | {
       name: 'getMemberCountByWorkspaceIdQuery';
       variables: GetMemberCountByWorkspaceIdQueryVariables;
diff --git a/packages/frontend/core/src/components/root-app-sidebar/user-info.tsx b/packages/frontend/core/src/components/root-app-sidebar/user-info.tsx
index b376ecd0d987e..1a2f29226da8f 100644
--- a/packages/frontend/core/src/components/root-app-sidebar/user-info.tsx
+++ b/packages/frontend/core/src/components/root-app-sidebar/user-info.tsx
@@ -83,7 +83,7 @@ const AccountMenu = () => {
   const openSignOutModal = useSignOut();
   const serverService = useService(ServerService);
   const userFeatureService = useService(UserFeatureService);
-  const isAdmin = useLiveData(userFeatureService.userFeature.isAdmin$);
+  const isAFFiNEAdmin = useLiveData(userFeatureService.userFeature.isAdmin$);
 
   const onOpenAccountSetting = useCallback(() => {
     track.$.navigationPanel.profileAndBadge.openSettings({ to: 'account' });
@@ -111,7 +111,7 @@ const AccountMenu = () => {
       >
         {t['com.affine.workspace.cloud.account.settings']()}
       </MenuItem>
-      {isAdmin ? (
+      {isAFFiNEAdmin ? (
         <MenuItem
           prefixIcon={<AdminIcon />}
           data-testid="workspace-modal-account-admin-option"
diff --git a/packages/frontend/core/src/modules/permissions/entities/permission.ts b/packages/frontend/core/src/modules/permissions/entities/permission.ts
index bdfd49013f85c..fd80de9000ca4 100644
--- a/packages/frontend/core/src/modules/permissions/entities/permission.ts
+++ b/packages/frontend/core/src/modules/permissions/entities/permission.ts
@@ -1,3 +1,4 @@
+import { Permission } from '@affine/graphql';
 import {
   backoffRetry,
   effect,
@@ -43,8 +44,8 @@ export class WorkspacePermission extends Entity {
           );
 
           return {
-            isOwner: info.isOwner,
-            isAdmin: info.isAdmin,
+            isOwner: info.workspace.role === Permission.Owner,
+            isAdmin: info.workspace.role === Permission.Admin,
             isTeam: info.workspace.team,
           };
         } else {
diff --git a/packages/frontend/core/src/modules/workspace-engine/impls/cloud.ts b/packages/frontend/core/src/modules/workspace-engine/impls/cloud.ts
index 3a4f49df91f74..238025049e996 100644
--- a/packages/frontend/core/src/modules/workspace-engine/impls/cloud.ts
+++ b/packages/frontend/core/src/modules/workspace-engine/impls/cloud.ts
@@ -4,6 +4,7 @@ import {
   deleteWorkspaceMutation,
   getWorkspaceInfoQuery,
   getWorkspacesQuery,
+  Permission,
   ServerDeploymentType,
 } from '@affine/graphql';
 import type {
@@ -339,8 +340,8 @@ class CloudWorkspaceFlavourProvider implements WorkspaceFlavourProvider {
 
     if (!cloudData && !localData) {
       return {
-        isOwner: info.isOwner,
-        isAdmin: info.isAdmin,
+        isOwner: info.workspace.role === Permission.Owner,
+        isAdmin: info.workspace.role === Permission.Admin,
         isTeam: info.workspace.team,
       };
     }
@@ -355,8 +356,8 @@ class CloudWorkspaceFlavourProvider implements WorkspaceFlavourProvider {
     return {
       name: result.name,
       avatar: result.avatar,
-      isOwner: info.isOwner,
-      isAdmin: info.isAdmin,
+      isOwner: info.workspace.role === Permission.Owner,
+      isAdmin: info.workspace.role === Permission.Admin,
       isTeam: info.workspace.team,
     };
   }


Reviews:
user: login: graphite-app[bot]
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-06T02:44:56Z
user: login: forehalo
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-05-06T06:54:28Z
user: login: graphite-app[bot]
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-06T07:18:00Z
user: login: graphite-app[bot]
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-06T07:33:37Z
user: login: forehalo
state: APPROVED
author_association: COLLABORATOR
submitted_at: 2025-05-08T09:50:57Z

Review comments:
diff_hunk: @@ -40,8 +40,10 @@ export class WorkspacePermission extends Entity {
           );
 
           return {
-            isOwner: info.isOwner,
-            isAdmin: info.isAdmin,
+            isOwner: info.workspace.permissions.Workspace_Administrators_Manage,
+            isAdmin:
+              !info.workspace.permissions.Workspace_Administrators_Manage &&
path: packages/frontend/core/src/modules/permissions/entities/permission.ts
user: login: graphite-app[bot]
body: The logic for determining isOwner and isAdmin might be incorrect. Consider reviewing the permission mapping to ensure it matches the expected behavior in tests. It's possible that isAdmin should be true when Workspace_Users_Manage is true, regardless of Workspace_Administrators_Manage status.

*Spotted by [Diamond](https://app.graphite.dev/diamond/?org=toeverything&ref=ai-review-comment) (based on CI logs)*<i class='graphite__hidden'><br /><br />Is this helpful? React 👍 or 👎 to let us know.</i>
created_at: 2025-05-06T02:44:55Z
author_association: CONTRIBUTOR
diff_hunk: @@ -1,7 +1,9 @@
 query getWorkspaceInfo($workspaceId: String!) {
-  isAdmin(workspaceId: $workspaceId)
-  isOwner(workspaceId: $workspaceId)
   workspace(id: $workspaceId) {
     team
+    permissions {
path: packages/common/graphql/src/graphql/get-workspace-info.gql
user: login: forehalo
body: `role` is still available, `permissions` only used for action controlling
created_at: 2025-05-06T06:54:27Z
author_association: COLLABORATOR
diff_hunk: @@ -83,7 +83,7 @@ const AccountMenu = () => {
   const openSignOutModal = useSignOut();
   const serverService = useService(ServerService);
   const userFeatureService = useService(UserFeatureService);
-  const isAdmin = useLiveData(userFeatureService.userFeature.isAdmin$);
+  const isAFFiNEAdmin = useLiveData(userFeatureService.userFeature.isAdmin$);
path: packages/frontend/core/src/components/root-app-sidebar/user-info.tsx
user: login: graphite-app[bot]
body: The variable name `isAFFiNEAdmin` uses inconsistent capitalization. Consider renaming to `isAffineAdmin` to follow standard camelCase naming conventions used throughout the codebase. This would improve readability and maintain consistent naming patterns for variables.
```suggestion
  const isAffineAdmin = useLiveData(userFeatureService.userFeature.isAdmin$);
```
  

*Spotted by [Diamond](https://app.graphite.dev/diamond/?org=toeverything&ref=ai-review-comment) (based on [custom rules](https://app.graphite.dev/diamond/?org=toeverything&ref=ai-review-comment&view=settings))*<i class='graphite__hidden'><br /><br />Is this helpful? React 👍 or 👎 to let us know.</i>
created_at: 2025-05-06T07:17:59Z
author_association: CONTRIBUTOR
diff_hunk: @@ -40,8 +41,8 @@ export class WorkspacePermission extends Entity {
           );
 
           return {
-            isOwner: info.isOwner,
-            isAdmin: info.isAdmin,
+            isOwner: info.workspace.role === Permission.Owner,
+            isAdmin: info.workspace.role === Permission.Admin,
             isTeam: info.workspace.team,
path: packages/frontend/core/src/modules/permissions/entities/permission.ts
user: login: graphite-app[bot]
body: The permission checking logic should handle cases where the workspace information might not be fully loaded yet. Consider adding null checks before accessing info.workspace.role to prevent potential undefined errors. Also, ensure that the role comparison logic correctly handles all possible role values, not just Owner and Admin.

*Spotted by [Diamond](https://app.graphite.dev/diamond/?org=toeverything&ref=ai-review-comment) (based on CI logs)*<i class='graphite__hidden'><br /><br />Is this helpful? React 👍 or 👎 to let us know.</i>
created_at: 2025-05-06T07:33:35Z
author_association: CONTRIBUTOR

PR comments:
user: login: coderabbitai[bot]
created_at: 2025-05-03T07:29:26Z
body: <!-- This is an auto-generated comment: summarize by coderabbit.ai -->
<!-- walkthrough_start -->

"""
## Walkthrough

The standalone GraphQL queries `getIsAdmin` and `getIsOwner` were removed. The `getWorkspaceInfo` query was updated to replace root-level `isAdmin` and `isOwner` fields with a nested `role` field inside the `workspace` object. Corresponding schema types and exports were cleaned up. Logic in the frontend and workspace modules now derives admin and owner status from the `role` field. Variable names related to admin status were also updated for clarity.

## Changes

| File(s)                                                                                     | Change Summary                                                                                                                        |
|---------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------|
| `packages/common/graphql/src/graphql/get-is-admin.gql`,<br>`.../get-is-owner.gql`           | Removed standalone GraphQL queries `getIsAdmin` and `getIsOwner`.                                                                     |
| `packages/common/graphql/src/graphql/get-workspace-info.gql`                                | Removed root-level `isAdmin` and `isOwner` fields; added nested `role` field inside the `workspace` object.                           |
| `packages/common/graphql/src/graphql/index.ts`                                              | Removed exports and deprecation notices for `getIsAdminQuery` and `getIsOwnerQuery`; updated `getWorkspaceInfoQuery` accordingly.   |
| `packages/common/graphql/src/schema.ts`                                                     | Removed types for `GetIsAdminQuery` and `GetIsOwnerQuery`; updated `GetWorkspaceInfoQuery` type to include `role` field; cleaned union.|
| `packages/frontend/core/src/components/root-app-sidebar/user-info.tsx`                      | Renamed `isAdmin` variable to `isAFFiNEAdmin` in `AccountMenu` component; updated conditional rendering to use new variable name.     |
| `packages/frontend/core/src/modules/permissions/entities/permission.ts`                     | Updated `WorkspacePermission` revalidate effect to determine `isOwner` and `isAdmin` by comparing `role` to `Permission.Owner/Admin`. |
| `packages/frontend/core/src/modules/workspace-engine/impls/cloud.ts`                        | Modified `getWorkspaceProfile` to set `isOwner` and `isAdmin` based on `role` field using `Permission` enum instead of booleans.       |

## Sequence Diagram(s)

```mermaid
sequenceDiagram
    participant Frontend
    participant GraphQL_API
    participant Workspace

    Frontend->>GraphQL_API: getWorkspaceInfo(workspaceId)
    GraphQL_API->>Workspace: Fetch workspace data
    Workspace-->>GraphQL_API: Return workspace info with nested role field
    GraphQL_API-->>Frontend: workspace { team, role }
    Frontend->>Frontend: Determine isOwner, isAdmin from role
```

## Poem

> 🐇 Through code fields I hop and prance,  
> Admin checks now take a new stance.  
> No queries split, just one role to see,  
> Workspace permissions, clear as can be.  
> Flags aligned, the logic sings,  
> Harmony in workspace things!  
> ✨🌿🐰
"""

<!-- walkthrough_end -->


---

<details>
<summary>📜 Recent review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**
**Plan: Pro**

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between bad6c578d6a49a8e864210f9b900a988a3aaae73 and d1e2d058dd4407d23490e04fbbfd0d3f4ae4620f.

</details>

<details>
<summary>📒 Files selected for processing (8)</summary>

* `packages/common/graphql/src/graphql/get-is-admin.gql` (0 hunks)
* `packages/common/graphql/src/graphql/get-is-owner.gql` (0 hunks)
* `packages/common/graphql/src/graphql/get-workspace-info.gql` (1 hunks)
* `packages/common/graphql/src/graphql/index.ts` (1 hunks)
* `packages/common/graphql/src/schema.ts` (1 hunks)
* `packages/frontend/core/src/components/root-app-sidebar/user-info.tsx` (2 hunks)
* `packages/frontend/core/src/modules/permissions/entities/permission.ts` (2 hunks)
* `packages/frontend/core/src/modules/workspace-engine/impls/cloud.ts` (3 hunks)

</details>

<details>
<summary>💤 Files with no reviewable changes (2)</summary>

* packages/common/graphql/src/graphql/get-is-owner.gql
* packages/common/graphql/src/graphql/get-is-admin.gql

</details>

<details>
<summary>🚧 Files skipped from review as they are similar to previous changes (6)</summary>

* packages/frontend/core/src/modules/workspace-engine/impls/cloud.ts
* packages/frontend/core/src/components/root-app-sidebar/user-info.tsx
* packages/frontend/core/src/modules/permissions/entities/permission.ts
* packages/common/graphql/src/graphql/get-workspace-info.gql
* packages/common/graphql/src/graphql/index.ts
* packages/common/graphql/src/schema.ts

</details>

</details>
<!-- internal state start -->


<!-- DwQgtGAEAqAWCWBnSTIEMB26CuAXA9mAOYCmGJATmriQCaQDG+Ats2bgFyQAOFk+AIwBWJBrngA3EsgEBPRvlqU0AgfFwA6NPEgQAfACgjoCEYDEZyAAUASpETZWaCrKNwSPbABsvkCiQBHbGlcSHFcLzpIACJ/ADM0MXwKAAomfwBKLmxEDwB3ZIBrRG5Ejwp8SMggynl4DEQaNHp8OJREAHk88j4al2jIPLRkBwFmdRp6OTDYDxzK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gXIMaBBWR3aY412hmYmZTAJ430QiyiDCGKuysStVU0pRHTySFEaKhYgS6N0LwB8SuhrT6JYASJSJYRqoVAEz0BlTn1xZhboBxDlI/D4DGywPBZGiUCu1IOBx427B3iDxz0IPGWcR60G0z21YEiwgOCCUpbYQR2x7x6WNdUkRUSjXyQTVTVEDDVtUqj9UYaFECg72AT3gVCA2mi5xGALVknLWbiUm1LUmVK0nAE3VN5Mn3V7WlNo0UmGznWer/TN3pONqMmZYPWo5p5+J1gA3EQ6KJYdOQwUC0yaQKRH1gZv1BMEhsBX1zhz2RDMxU4qgbC90XZbx9xdKYMjyEDyU/ZTwD6zzI0QLQl83LwqCrzdwbyGBfNMzqBVnDiIBVnYMkDOy0BVkAx8wwvbxQAMAAAsAAzAIHEAwEcAAGzksACcaARwVL5LhLRw+LJAhL5wDAVLAA7AkOSxy3QGgGcHEOSwwGcAIAAAwkAACsOLXzZwocBwLIRwArZwHLYrBwcQAgjLAgDAAgvLVLErCQBNErHL+LRwaAHLEr+LZwVLRw0rhckA+LHLorVLAgBwLr5LCiaAJANLDABwerErhLErBwJAorpLtLLLBLpEXrZrUrvcdrMotAQrRrZwCbaA+LNLsrZw5LJrBwIbzrVLororaAVLZwZwaAhLaAFbJAHLhLtrEA50QbRwtAorErybtA+L+LorHLtARwhLab4ror+L6rJLTbtAhLcQ+Lnr+L5LRwIbOLBgcLpYCLSLKLkY3I6LVZxcMLQAA=== -->

<!-- internal state end -->
<!-- finishing_touch_checkbox_start -->

<details open="true">
<summary>✨ Finishing Touches</summary>

- [ ] <!-- {"checkboxId": "7962f53c-55bc-4827-bfbf-6a18da830691"} --> 📝 Generate Docstrings

</details>

<!-- finishing_touch_checkbox_end -->
<!-- tips_start -->

---



<details>
<summary>🪧 Tips</summary>

### Chat

There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=toeverything/AFFiNE&utm_content=12118):

- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
  - `I pushed a fix in commit <commit_id>, please review it.`
  - `Generate unit testing code for this file.`
  - `Open a follow-up GitHub issue for this discussion.`
- Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples:
  - `@coderabbitai generate unit testing code for this file.`
  -	`@coderabbitai modularize this function.`
- PR comments: Tag `@coderabbitai` in 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 generate unit testing code.`
  - `@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](https://www.coderabbit.ai/contact-us/support) 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 pause` to pause the reviews on a PR.
- `@coderabbitai resume` to resume the paused reviews.
- `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
- `@coderabbitai full review` to do a full review from scratch and review all the files again.
- `@coderabbitai summary` to regenerate the summary of the PR.
- `@coderabbitai generate docstrings` to [generate docstrings](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR.
- `@coderabbitai generate sequence diagram` to generate a sequence diagram of the changes in this PR.
- `@coderabbitai resolve` resolve all the CodeRabbit review comments.
- `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository.
- `@coderabbitai help` to get help.

### Other keywords and placeholders

- Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed.
- Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description.
- Add `@coderabbitai` anywhere in the PR title to generate the title automatically.

### CodeRabbit Configuration File (`.coderabbit.yaml`)

- You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository.
- Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit.
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback.
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.

</details>

<!-- tips_end -->
author_association: CONTRIBUTOR
user: login: JimmFly
created_at: 2025-05-03T07:29:34Z
body: * **#12144** <a href="https://app.graphite.dev/github/pr/toeverything/AFFiNE/12144?utm_source=stack-comment-icon" target="_blank"><img src="https://static.graphite.dev/graphite-32x32-black.png" alt="Graphite" width="10px" height="10px"/></a>
* **#12118** <a href="https://app.graphite.dev/github/pr/toeverything/AFFiNE/12118?utm_source=stack-comment-icon" target="_blank"><img src="https://static.graphite.dev/graphite-32x32-black.png" alt="Graphite" width="10px" height="10px"/></a> 👈 <a href="https://app.graphite.dev/github/pr/toeverything/AFFiNE/12118?utm_source=stack-comment-view-in-graphite" target="_blank">(View in Graphite)</a>
* `canary`
<hr />

## How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:
- <kbd>merge</kbd> - adds this PR to the back of the merge queue
- <kbd>hotfix</kbd> - 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](https://app.graphite.dev/invite/github/toeverything?ref=merge-queue-instructions-in-stack-comment&prId=12118).

<h2></h2>
<sub>

An organization admin has enabled the [Graphite Merge Queue](https://graphite.dev/docs/graphite-merge-queue) in this repository.

</sub>

<sub>

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

</sub>

<h2></h2>

This stack of pull requests is managed by <a href="https://graphite.dev?utm-source=stack-comment"><b>Graphite</b></a>. Learn more about <a href="https://stacking.dev/?utm_source=stack-comment">stacking</a>.
<!-- Current dependencies on/for this PR: -->
author_association: COLLABORATOR
user: login: codecov[bot]
created_at: 2025-05-03T07:35:11Z
body: ## [Codecov](https://app.codecov.io/gh/toeverything/AFFiNE/pull/12118?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=toeverything) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 54.17%. Comparing base [(`662614d`)](https://app.codecov.io/gh/toeverything/AFFiNE/commit/662614de0d6643a7099a15819366bf6357b3569c?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=toeverything) to head [(`cfe7b7c`)](https://app.codecov.io/gh/toeverything/AFFiNE/commit/cfe7b7cf29710ce5410b08c6a58206b9a29882f3?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=toeverything).
> Report is 1 commits behind head on canary.

<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff            @@
##           canary   #12118    +/-   ##
========================================
  Coverage   54.16%   54.17%            
========================================
  Files        2599     2599            
  Lines      118382   118382            
  Branches    19182    19182            
========================================
+ Hits        64126    64136    +10     
+ Misses      52694    52173   -521     
- Partials     1562     2073   +511     
```

| [Flag](https://app.codecov.io/gh/toeverything/AFFiNE/pull/12118/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=toeverything) | Coverage Δ | |
|---|---|---|
| [server-test](https://app.codecov.io/gh/toeverything/AFFiNE/pull/12118/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=toeverything) | `77.55% <ø> (ø)` | |
| [unittest](https://app.codecov.io/gh/toeverything/AFFiNE/pull/12118/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=toeverything) | `31.17% <ø> (+<0.01%)` | :arrow_up: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=toeverything#carryforward-flags-in-the-pull-request-comment) to find out more.

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/toeverything/AFFiNE/pull/12118?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=toeverything).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=toeverything).

<details><summary> :rocket: New features to boost your workflow: </summary>

- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
author_association: NONE
user: login: graphite-app[bot]
created_at: 2025-05-13T03:20:39Z
body: ### Merge activity

* **May 12, 11:20 PM EDT**: `JimmFly` added this pull request to the [Graphite merge queue](https://app.graphite.dev/merges?org=toeverything&repo=AFFiNE).
* **May 12, 11:33 PM EDT**: Merged by the [Graphite merge queue](https://app.graphite.dev/merges?org=toeverything&repo=AFFiNE).

author_association: CONTRIBUTOR