8000 added encrypt property in the attribute string response model by ArnabChatterjee20k · Pull Request #9868 · appwrite/appwrite · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

added encrypt property in the attribute string response model #9868

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 23, 2025

Conversation

ArnabChatterjee20k
Copy link
Contributor
@ArnabChatterjee20k ArnabChatterjee20k commented May 23, 2025

What does this PR do?

(Provide a description of what this PR does and why it's needed.)

Test Plan

(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work. Screenshots may also be helpful.)

Related PRs and Issues

  • (Related PR or issue)

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?

Summary by CodeRabbit

  • New Features
    • The API now explicitly includes the encryption status in responses for creating, listing, and retrieving string attributes.
  • Tests
    • Added validations to confirm the encryption flag is correctly reflected immediately after creation and upon retrieval of attributes.

Copy link
coderabbitai bot commented May 23, 2025

Warning

Rate limit exceeded

@ArnabChatterjee20k has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 17 minutes and 9 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between e586afc and b8cb6f2.

📒 Files selected for processing (1)
  • app/controllers/api/databases.php (4 hunks)

Walkthrough

The changes introduce an encrypt boolean flag to the API response model for string attributes in database collections. The API endpoints for creating, listing, and retrieving attributes and collections now include this flag in their responses. The AttributeString model is updated with a new encrypt validation rule. End-to-end tests are added to assert the presence and correctness of the encrypt property for both encrypted and non-encrypted attributes. Additionally, attribute filtering logic is updated to derive the encrypt flag from the presence of the 'encrypt' filter.

Changes

File(s) Change Summary
app/controllers/api/databases.php Enhanced attribute creation, listing, retrieval, and collection retrieval endpoints to include an explicit encrypt boolean flag in string attribute responses.
src/Appwrite/Utopia/Response/Model/AttributeString.php Added a new boolean validation rule encrypt (default false) to the AttributeString model.
app/init/database/filters.php Added logic to set an encrypt boolean attribute for string-type attributes based on the presence of 'encrypt' in their filters array during subquery attribute processing.
tests/e2e/Services/Databases/DatabasesBase.php Added an assertion verifying the encrypt property is false in the attribute creation test.
tests/e2e/Services/Databases/DatabasesCustomServerTest.php Added assertions verifying the encrypt property is true immediately after creation and upon retrieval of an encrypted attribute; verified encrypt presence and correctness in collection attributes.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API_Controller
    participant Attribute_Model
    participant Response

    Client->>API_Controller: POST /databases/{id}/collections/{id}/attributes/string
    API_Controller->>Attribute_Model: createAttribute(...)
    Attribute_Model-->>API_Controller: Attribute Document
    API_Controller->>API_Controller: Add 'encrypt' flag to attribute data
    API_Controller->>Response: Send Document with 'encrypt' in response
    Response-->>Client: 202 Accepted + Attribute data (with 'encrypt')
Loading

Poem

In the database fields where the string values play,
A new flag called "encrypt" now lights up the way.
Responses are clearer, with secrets in tow,
Tests check the flag, so we always will know.
🐇✨ Secure and precise, onward we go!

✨ 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.

❤️ 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 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.

Copy link
github-actions bot commented May 23, 2025

Security Scan Results for PR

Docker Image Scan Results

Package Version Vulnerability Severity
binutils 2.42-r0 CVE-2025-0840 HIGH
libexpat 2.6.4-r0 CVE-2024-8176 HIGH
libxml2 2.12.7-r0 CVE-2024-56171 HIGH
libxml2 2.12.7-r0 CVE-2025-24928 HIGH
libxml2 2.12.7-r0 CVE-2025-27113 HIGH
libxml2 2.12.7-r0 CVE-2025-32414 HIGH
libxml2 2.12.7-r0 CVE-2025-32415 HIGH
sqlite-libs 3.45.3-r1 CVE-2025-29087 HIGH
xz 5.6.2-r0 CVE-2025-31115 HIGH
xz-libs 5.6.2-r0 CVE-2025-31115 HIGH
golang.org/x/crypto v0.31.0 CVE-2025-22869 HIGH

Source Code Scan Results

🎉 No vulnerabilities found!

Copy link
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/e2e/Services/Databases/DatabasesBase.php (1)

301-301: Added assertion for the new encrypt flag
The new assertFalse($title['body']['encrypt']) correctly validates that the encrypt property is included and defaults to false. Great addition. Consider extending this coverage by asserting the encrypt field in the GET‐based tests (testAttributeResponseModels, testListAttributes) to ensure it’s propagated consistently across all response models.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1e22076 and 0cccb75.

📒 Files selected for processing (3)
  • app/controllers/api/databases.php (1 hunks)
  • src/Appwrite/Utopia/Response/Model/AttributeString.php (1 hunks)
  • tests/e2e/Services/Databases/DatabasesBase.php (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: scan
🔇 Additional comments (2)
src/Appwrite/Utopia/Response/Model/AttributeString.php (1)

27-33: LGTM! Well-implemented encryption flag with proper documentation.

The implementation follows best practices:

  • Consistent pattern: Matches the existing addRule() structure used throughout the constructor
  • Appropriate typing: Boolean type is perfect for this encryption flag
  • Comprehensive documentation: The description clearly explains both the security benefit and the important trade-off (encrypted attributes cannot be queried)
  • Backward compatibility: Default value of false and required: false ensures existing code continues to work
  • Clear example: The example value matches the default, maintaining consistency

The warning about query limitations in the description is particularly valuable for developers who need to understand the implications of enabling encryption.

app/controllers/api/databases.php (1)

1375-1377: LGTM! Good approach to expose encrypt flag in API response.

The implementation correctly adds the encrypt property to the string attribute response by:

  1. Creating a copy of the attribute data
  2. Adding the encrypt flag from the request parameter
  3. Wrapping it back into a Document object

This provides a clean API interface where clients get the encrypt status directly rather than parsing it from the filters array.

Comment on lines 1375 to 1377
$stringAttribute = $attribute->getArrayCopy();
$stringAttribute['encrypt'] = $encrypt;
$stringAttribute = new Document($stringAttribute);
Copy link
Member

Choose a reason for hiding this comment

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

could simply just be - $attribute->setAttribute('encrypt', $encrypt); since its a document already.

Comment on lines 2058 to 2064
foreach ($attributes as $attribute) {
$filters = $attribute->getAttribute('filters', []);
$attributeArray = $attribute->getArrayCopy();
$attributeArray['encrypt'] = in_array('encrypt', $filters);
$updatedAttribute = new Document($attributeArray);
$updatedAttributes[] = $updatedAttribute;
}
Copy link
Member

Choose a reason for hiding this comment

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

why do we need this to add encrypt to all the attributes?

Copy link
Member
@abnegate abnegate left a comment

Choose a reason for hiding this comment

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

Let's also update here:

Database::addFilter(

This is called when you get a collection from the database to populate it's attributes. Let's also add a check in the getCollection test to ensure that it's set

Comment on lines 80 to 91
8000
$attributeType = $attribute->getAttribute('type');
if ($attributeType === Database::VAR_RELATIONSHIP) {
$options = $attribute->getAttribute('options');
foreach ($options as $key => $value) {
$attribute->setAttribute($key, $value);
}
$attribute->removeAttribute('options');
}
if ($attributeType === Database::VAR_STRING) {
$filters = $attribute->getAttribute('filters', []);
$attribute->setAttribute('encrypt', in_array('encrypt', $filters));
}
Copy link
Member

Choose a reason for hiding this comment

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

In these sort of cases, lets always use a switch. Even if we only have two cases now, switch is easier to extend cleanly in future than multiple if's

Comment on lines 761 to 771
foreach ($attributes as $attribute) {
$this->assertArrayHasKey('encrypt', $attribute);
if ($attribute['key'] === 'firstName') {
$firstNameAttribute = $attribute['encrypt'];
}
if ($attribute['key'] === 'lastName') {
$lastNameAttribute = $attribute['encrypt'];
}
}
$this->assertTrue($lastNameAttribute);
$this->assertFalse($firstNameAttribute);
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 just assert inside the loop, then we will fail fast if we get the wrong value

@abnegate abnegate merged commit 5eab81c into appwrite:main May 23, 2025
37 checks passed
abnegate added a commit that referenced this pull request May 23, 2025
added encrypt property in the attribute string response model
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
0