Skip to content

Conversation

@LucasXu0
Copy link
Collaborator

@LucasXu0 LucasXu0 commented Jun 4, 2025

Feature Preview


PR Checklist

  • My code adheres to AppFlowy's Conventions
  • I've listed at least one issue that this PR fixes in the description above.
  • I've added a test(s) to validate changes in this PR, or this PR only contains semantic changes.
  • All existing tests are passing.

Summary by Sourcery

Fix permission control on initial page load by defaulting share access to read-only and switching to Rust backend implementations for sharing repositories; lower view log verbosity.

Bug Fixes:

  • Default share access level fallback and initial state changed to readOnly instead of readAndWrite to correct permission control.
  • Replace local mock repositories with Rust-based implementations for share button and shared section to use real backend data.

Enhancements:

  • Change view operation log statements from info to debug to reduce log noise.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jun 4, 2025

Reviewer's Guide

This PR updates the page‐access control to use a read‐only default on first load, fixes initial permission logic, lowers logging verbosity for view operations, and switches shared‐feature widgets to Rust‐backed repositories.

Sequence Diagram: Initial Page Access Level Determination

sequenceDiagram
    actor User
    participant PageUI
    participant PageAccessLevelBloc
    participant RustPageAccessLevelRepositoryImpl
    participant UserAuthService

    User->>PageUI: Opens page
    PageUI->>PageAccessLevelBloc: Request page access level for pageId
    PageAccessLevelBloc->>RustPageAccessLevelRepositoryImpl: getCurrentUserAccessLevelInPage(pageId)
    RustPageAccessLevelRepositoryImpl->>UserAuthService: currentUser()
    UserAuthService-->>RustPageAccessLevelRepositoryImpl: UserProfile (or null)
    alt User is null or not found in page members list
        RustPageAccessLevelRepositoryImpl-->>PageAccessLevelBloc: FlowyResult.success(ShareAccessLevel.readOnly) # New default
    else User is in page members list
        RustPageAccessLevelRepositoryImpl-->>PageAccessLevelBloc: FlowyResult.success(DeterminedAccessLevel) # Existing logic
    end
    PageAccessLevelBloc-->>PageUI: Update with determined access level
    PageUI-->>User: Displays page with appropriate access
Loading

Class Diagram: PageAccessLevelState Default Initialization Update

classDiagram
    class PageAccessLevelState {
        +ShareAccessLevel accessLevel
        +bool isLocked
        +int lockCounter
        +SharedSectionType sectionType
        +static PageAccessLevelState initial()
    }
    class ShareAccessLevel {
        <<enumeration>>
        readOnly
        readAndWrite
        fullAccess
        none
    }
    PageAccessLevelState o-- ShareAccessLevel : accessLevel
    note "The initial() method now sets 'accessLevel' to ShareAccessLevel.readOnly instead of ShareAccessLevel.readAndWrite."
Loading

Class Diagram: RustPageAccessLevelRepositoryImpl Default Fallback Update

classDiagram
    class RustPageAccessLevelRepositoryImpl {
        +Future<FlowyResult<View>> getView(String pageId)
        +Future<FlowyResult<void>> lockView(String pageId)
        +Future<FlowyResult<void>> unlockView(String pageId)
        +Future<FlowyResult<ShareAccessLevel>> getCurrentUserAccessLevelInPage(String pageId)
    }
    class ShareAccessLevel {
        <<enumeration>>
        readOnly
        readAndWrite
    }
    RustPageAccessLevelRepositoryImpl ..> ShareAccessLevel : uses
    note for RustPageAccessLevelRepositoryImpl "getCurrentUserAccessLevelInPage now defaults to ShareAccessLevel.readOnly if user/permissions not found, previously ShareAccessLevel.readAndWrite."
Loading

Class Diagram: ShareButton's Updated Dependency via ShareTabBloc

classDiagram
    class ShareButton {
        +View view
        +String workspaceId
        +Widget build(BuildContext context)
    }
    class ShareTabBloc {
        +ShareTabBloc(IShareWithUserRepository repository, String pageId, String workspaceId)
    }
    class RustShareWithUserRepositoryImpl {
        +IShareWithUserRepository
    }
    class IShareWithUserRepository {
        <<interface>>
    }
    IShareWithUserRepository <|.. RustShareWithUserRepositoryImpl
    ShareButton ..> ShareTabBloc : creates & provides via BlocProvider
    ShareTabBloc o-- IShareWithUserRepository : repository (now RustShareWithUserRepositoryImpl)
Loading

Class Diagram: SharedSection's Updated Dependency via SharedSectionBloc

classDiagram
    class SharedSection {
        +Widget build(BuildContext context)
    }
    class SharedSectionBloc {
        +SharedSectionBloc(ISharedPagesRepository repository, String workspaceId)
    }
    class RustSharedPagesRepositoryImpl {
        +ISharedPagesRepository
    }
    class ISharedPagesRepository {
        <<interface>>
    }
    ISharedPagesRepository <|.. RustSharedPagesRepositoryImpl
    SharedSection ..> SharedSectionBloc : creates & provides via BlocProvider
    SharedSectionBloc o-- ISharedPagesRepository : repository (now RustSharedPagesRepositoryImpl)
Loading

File-Level Changes

Change Details Files
Logging level reduced for view operations in repository implementation
  • Changed Log.info to Log.debug in getView, lockView, and unlockView handlers
rust_page_access_level_repository_impl.dart
Default share access fallback changed from read‐write to read‐only
  • Updated fallback ShareAccessLevel in permission resolution to readOnly instead of readAndWrite
  • Adjusted getAccessLevel success branch to return readOnly when user not found
rust_page_access_level_repository_impl.dart
Swapped local to Rust‐based share repositories in UI widgets
  • Replaced LocalShareWithUserRepositoryImpl with RustShareWithUserRepositoryImpl in ShareButton
  • Replaced LocalSharedPagesRepositoryImpl with RustSharePagesRepositoryImpl in SharedSection
share_button.dart
shared_section.dart
Default PageAccessLevelState now initializes to readOnly
  • Changed initial accessLevel in PageAccessLevelState from readAndWrite to readOnly
page_access_level_state.dart

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @LucasXu0 - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

'failed to get user access level: $failure, in page: $pageId',
);

// return the read and write access level if the user is not found
Copy link
Contributor

Choose a reason for hiding this comment

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

issue: Update or remove outdated inline comment

The inline comment is now inaccurate; please update it to match the current return value or remove it.

@LucasXu0 LucasXu0 force-pushed the guest_role_issues branch from e5b4eef to 1b20289 Compare June 5, 2025 01:12
@LucasXu0 LucasXu0 merged commit dd2dbed into AppFlowy-IO:main Jun 5, 2025
19 checks passed
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.

1 participant