Skip to content

Conversation

@fogelito
Copy link
Contributor

@fogelito fogelito commented Jul 27, 2025

Fix Null permissions issue added in decode

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of document permissions to ensure documents created without explicit permissions include a $permissions key set to an empty array.
    • Enhanced robustness in internal attribute processing by standardizing attribute handling and refining encoding and decoding of $permissions.
    • Strengthened validation of document attributes to correctly check presence and types of $id and $permissions.
  • Tests

    • Added tests to verify that documents created without permissions contain a $permissions key with an empty array as its value.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 27, 2025

Walkthrough

The changes standardize internal attribute handling in the database's encode, decode, and casting methods by appending attributes from getInternalAttributes() and specially handling the $permissions attribute to avoid encoding it as a JSON string when empty. Document constructor validation now uses array_key_exists for $id and $permissions keys. A new test verifies documents created without explicit permissions contain an empty $permissions array.

Changes

Cohort / File(s) Change Summary
Database core logic
src/Database/Database.php
Modified encode, decode, and casting methods to append internal attributes from getInternalAttributes(), explicitly handle empty $permissions, use keyed loops with reassignment, and skip encoding filters for empty $permissions.
Document validation
src/Database/Document.php
Changed constructor key presence checks from isset to array_key_exists for $id and $permissions validation.
Permission tests
tests/e2e/Adapter/Scopes/PermissionTests.php
Added testCreateDocumentsEmptyPermission to verify documents created without permissions have $permissions as an empty array.

Sequence Diagram(s)

sequenceDiagram
    participant Test as PermissionTests
    participant DB as Database
    participant Doc as Document

    Test->>DB: Create collection
    Test->>DB: Create document (without permissions)
    DB->>Doc: Instantiate Document (no $permissions)
    Doc-->>DB: Document (with $permissions as empty array)
    DB-->>Test: Document with $permissions = []

    Test->>DB: Create multiple documents (bulk, no permissions)
    loop For each document
        DB->>Doc: Instantiate Document (no $permissions)
        Doc-->>DB: Document (with $permissions as empty array)
    end
    DB-->>Test: Documents with $permissions = []
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested reviewers

  • abnegate

Poem

In the warren where code does bloom,
Permissions now have met their doom.
No key appears where none belong,
The tests all cheer, the docs are strong!
With careful hops through fields of arrays,
The rabbit reviews and joyfully brays.
🐇✨


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 360a6e9 and 10e7a0a.

📒 Files selected for processing (1)
  • src/Database/Document.php (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Database/Document.php
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: Adapter Tests (SharedTables/SQLite)
  • GitHub Check: Adapter Tests (SharedTables/Postgres)
  • GitHub Check: Adapter Tests (MariaDB)
  • GitHub Check: Adapter Tests (SharedTables/MySQL)
  • GitHub Check: Adapter Tests (SharedTables/MariaDB)
  • GitHub Check: Adapter Tests (MySQL)
  • GitHub Check: Adapter Tests (Pool)
  • GitHub Check: Adapter Tests (Postgres)
  • GitHub Check: Adapter Tests (SQLite)
  • GitHub Check: Adapter Tests (Mirror)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch null-permissions

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.

❤️ Share
🪧 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 @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @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 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 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 for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for 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.

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.


foreach ($value as &$node) {
foreach (\array_reverse($filters) as $filter) {
foreach ($value as $k => $node) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Remove reference

Copy link
Member

Choose a reason for hiding this comment

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

Let's use a better name, $key, or something more descriptive if that collides

Copy link
Contributor Author

@fogelito fogelito Jul 28, 2025

Choose a reason for hiding this comment

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

Changed to $index since $key is in use

@fogelito fogelito requested a review from abnegate July 27, 2025 12:13
@fogelito fogelito removed the request for review from abnegate July 27, 2025 15:36
@abnegate abnegate merged commit 7281582 into main Jul 28, 2025
15 checks passed
@abnegate abnegate deleted the null-permissions branch July 28, 2025 06:21
This was referenced Aug 3, 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.

3 participants