Skip to content

Fix view disappearing when switching from WORKSPACE to UNLISTED visibility#16289

Merged
FelixMalfait merged 1 commit intomainfrom
fix/view-visibility-workspace-to-unlisted
Dec 3, 2025
Merged

Fix view disappearing when switching from WORKSPACE to UNLISTED visibility#16289
FelixMalfait merged 1 commit intomainfrom
fix/view-visibility-workspace-to-unlisted

Conversation

@FelixMalfait
Copy link
Copy Markdown
Member

Description

When switching a view's visibility from WORKSPACE to UNLISTED, the code in view-v2.service.ts correctly sets createdByUserWorkspaceId to the current user (to prevent the view from disappearing). However, this property was not included in FLAT_VIEW_EDITABLE_PROPERTIES, which meant:

  1. The comparison logic didn't detect the change
  2. No update action was created for the property
  3. The value was never persisted to the database
  4. The view disappeared because it became UNLISTED with no owner

This fix adds createdByUserWorkspaceId to the editable properties so the change is properly detected and persisted.

Might fix #15955

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Dec 3, 2025

Greptile Overview

Greptile Summary

This PR fixes a bug where views disappear when switching visibility from WORKSPACE to UNLISTED.

Root Cause: The view-v2.service.ts correctly sets createdByUserWorkspaceId to the current user when visibility changes to UNLISTED (to maintain view ownership), but this property was not in FLAT_VIEW_EDITABLE_PROPERTIES. This meant:

  1. The comparison logic couldn't detect the createdByUserWorkspaceId change
  2. No update action was created for this property
  3. The value was never persisted to the database
  4. The view became UNLISTED with no owner, causing it to disappear

Fix: Adding createdByUserWorkspaceId to the editable properties array ensures the change is properly detected and persisted.

Validation: The fix is well-aligned with:

  • Existing logic in view-v2.service.ts:138-149 that sets this property
  • Existing test coverage in view.service.spec.ts:386-419 that verifies the WORKSPACE→UNLISTED behavior
  • TypeScript typing (as const satisfies (keyof FlatView)[]) that validates property names

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk - it's a one-line fix that enables existing functionality to work correctly.
  • The change is minimal (adding one property to an array), the fix directly addresses the documented bug, the property is a valid FlatView property validated by TypeScript, and existing tests already verify the expected behavior this fix enables.
  • No files require special attention.

Important Files Changed

File Analysis

Filename Score Overview
packages/twenty-server/src/engine/metadata-modules/flat-view/constants/flat-view-editable-properties.constant.ts 5/5 Added createdByUserWorkspaceId to editable properties, enabling proper detection and persistence when changing view visibility from WORKSPACE to UNLISTED.

Sequence Diagram

sequenceDiagram
    participant User
    participant ViewResolver
    participant ViewV2Service
    participant FlatViewUtils
    participant MigrationService
    participant Database

    User->>ViewResolver: Update view (visibility: UNLISTED)
    ViewResolver->>ViewV2Service: updateOne(updateViewInput)
    ViewV2Service->>FlatViewUtils: fromUpdateViewInputToFlatViewToUpdateOrThrow()
    Note over FlatViewUtils: Extracts properties in FLAT_VIEW_EDITABLE_PROPERTIES
    FlatViewUtils-->>ViewV2Service: flatViewFromUpdateInput

    alt Visibility changed from WORKSPACE to UNLISTED
        ViewV2Service->>ViewV2Service: Set createdByUserWorkspaceId = userWorkspaceId
        Note over ViewV2Service: Now detected because property<br/>is in FLAT_VIEW_EDITABLE_PROPERTIES
    end

    ViewV2Service->>MigrationService: validateBuildAndRunWorkspaceMigration()
    Note over MigrationService: Compares properties in FLAT_VIEW_EDITABLE_PROPERTIES<br/>to detect changes and create update actions
    MigrationService->>Database: Persist changes including createdByUserWorkspaceId
    Database-->>User: View updated successfully (still visible)
Loading

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

@FelixMalfait FelixMalfait force-pushed the fix/view-visibility-workspace-to-unlisted branch from f914b15 to 53dabfa Compare December 3, 2025 14:29
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Dec 3, 2025

🚀 Preview Environment Ready!

Your preview environment is available at: http://bore.pub:51082

This environment will automatically shut down when the PR is closed or after 5 hours.

@FelixMalfait FelixMalfait merged commit 578aa9d into main Dec 3, 2025
53 checks passed
@FelixMalfait FelixMalfait deleted the fix/view-visibility-workspace-to-unlisted branch December 3, 2025 14:56
@twenty-eng-sync
Copy link
Copy Markdown

Hey @FelixMalfait! After you've done the QA of your Pull Request, you can mark it as done here. Thank you!

NotYen pushed a commit to NotYen/twenty-ym that referenced this pull request Dec 9, 2025
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.

Error when switching a workspace view to an unlisted view

1 participant