Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Comments

Fix: Redirect rule parent resource#9982

Merged
Meldiron merged 2 commits into1.7.xfrom
fix-redirect-rule-parent-1.7.x
Jun 9, 2025
Merged

Fix: Redirect rule parent resource#9982
Meldiron merged 2 commits into1.7.xfrom
fix-redirect-rule-parent-1.7.x

Conversation

@Meldiron
Copy link
Contributor

@Meldiron Meldiron commented Jun 9, 2025

What does this PR do?

Adds parent to redirect type rule. Doing this allow to query it by it then, so it can be shown properly in site's rules tab in Console

Test Plan

New tests

Related PRs and Issues

x

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

    • Redirect rules can now be explicitly linked to a specific site or function resource.
    • When creating redirect rules, users must specify the resource type ('site' or 'function') and the corresponding resource ID.
  • Bug Fixes

    • Improved validation and error handling when associating redirect rules with resources.
  • Tests

    • End-to-end tests updated to verify redirect rule creation and association with site resources.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 9, 2025

Walkthrough

This update extends the redirect rule creation process to require explicit association with a parent resource, either a site or function. Code changes introduce new parameters for resource type and ID, update rule creation logic, and modify related SDK formatting and end-to-end tests to accommodate and verify these associations.

Changes

File(s) Change Summary
src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php Extended constructor and action method to accept resourceId and resourceType, fetch and validate parent resource, and add resource linkage attributes to created rules.
src/Appwrite/SDK/Specification/Format.php Updated enum handling for the "proxy" service to support "resourceType" and "statusCode" enums for redirect rule creation.
tests/e2e/Services/Proxy/ProxyBase.php Modified createRedirectRule and setupRedirectRule to require and use resourceType and resourceId parameters.
tests/e2e/Services/Proxy/ProxyCustomServerTest.php Adjusted test to create and associate redirect rules with a site resource, and verified correct rule-resource association.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant ProxyModule
    participant DBProject
    participant DBPlatform

    Client->>ProxyModule: createRedirectRule(domain, url, statusCode, resourceType, resourceId)
    ProxyModule->>DBProject: Fetch resource (site/function) by resourceId
    DBProject-->>ProxyModule: Return resource or not found
    alt Resource found
        ProxyModule->>DBPlatform: Create redirect rule with resource linkage
        DBPlatform-->>ProxyModule: Rule created
        ProxyModule-->>Client: Success response
    else Resource not found
        ProxyModule-->>Client: RULE_RESOURCE_NOT_FOUND error
    end
Loading

Possibly related PRs

  • appwrite/appwrite#9859: Modifies downstream usage of deploymentResourceType in redirect rules, related through the handling and propagation of resource linkage in redirect rules.

Suggested reviewers

  • christyjacob4

Poem

In tunnels of code where the proxies leap,
New rules now nest where resources sleep.
Sites and functions, now tightly bound,
Redirects with parents—connections profound!
Tests hop along, SDKs align—
The code grows stronger, line by line.
🐇✨


📜 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 9866e6f and d6bcb46.

⛔ Files ignored due to path filters (2)
  • app/config/specs/open-api3-latest-console.json is excluded by !app/config/specs/**
  • app/config/specs/swagger2-latest-console.json is excluded by !app/config/specs/**
📒 Files selected for processing (4)
  • src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php (4 hunks)
  • src/Appwrite/SDK/Specification/Format.php (2 hunks)
  • tests/e2e/Services/Proxy/ProxyBase.php (3 hunks)
  • tests/e2e/Services/Proxy/ProxyCustomServerTest.php (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: Setup & Build SDK
  • GitHub Check: scan
🔇 Additional comments (10)
tests/e2e/Services/Proxy/ProxyCustomServerTest.php (2)

134-136: LGTM! Proper resource association setup.

The test correctly creates a site first and then associates redirect rules with it using the new parameters. This properly tests the parent resource requirement.


163-173: Excellent test coverage for querying by parent resource.

The test properly verifies that redirect rules can be filtered by their parent resource using the new deploymentResourceType and deploymentResourceId fields. This ensures the core functionality works as intended.

tests/e2e/Services/Proxy/ProxyBase.php (2)

71-85: LGTM! Method signature correctly updated.

The createRedirectRule method properly adds the new resourceType and resourceId parameters and includes them in the request payload. The implementation is consistent and correct.


120-127: LGTM! Setup method properly updated.

The setupRedirectRule method signature and implementation correctly forward the new parameters to createRedirectRule. The changes maintain consistency across the helper methods.

src/Appwrite/SDK/Specification/Format.php (2)

116-125: LGTM! Proper enum name definition.

The getEnumName method correctly adds support for the proxy service and returns ProxyResourceType for the resourceType parameter. This follows the established pattern and naming convention.


454-460: LGTM! Correct enum keys defined.

The enum keys properly define:

  • HTTP redirect status codes (301, 302, 307, 308) for statusCode
  • Resource types (Site, Function) for resourceType

These align with the implementation requirements and standard HTTP redirect codes.

src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php (4)

69-70: LGTM! Proper parameter validation.

The new parameters are correctly defined with appropriate validators:

  • resourceId uses UID validator ensuring valid resource identifiers
  • resourceType uses WhiteList validator restricting to 'site' or 'function'

This ensures data integrity and prevents invalid associations.


123-130: LGTM! Robust resource validation logic.

The implementation correctly:

  • Maps resource types to appropriate collections using a match statement
  • Fetches the resource from the project database
  • Throws RULE_RESOURCE_NOT_FOUND exception if resource doesn't exist

This ensures redirect rules can only be created with valid parent resources.


180-182: LGTM! Proper parent resource association.

The rule document correctly stores the parent resource information:

  • deploymentResourceType stores the resource type
  • deploymentResourceId stores the resource ID
  • deploymentResourceInternalId stores the internal ID

This enables querying rules by their parent resource as demonstrated in the tests.


69-70: Note: Breaking change introduced.

The new resourceId and resourceType parameters don't have default values, making them required. This will break existing API calls that don't provide these parameters. Ensure this breaking change is documented and communicated to users.

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

@Meldiron Meldiron mentioned this pull request Jun 9, 2025
2 tasks
@github-actions
Copy link

github-actions bot commented Jun 9, 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!

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jun 9, 2025

Open in StackBlitz

npm i https://pkg.pr.new/appwrite/appwrite/@appwrite.io/console@9982

commit: d6bcb46

@github-actions
Copy link

github-actions bot commented Jun 9, 2025

✨ Benchmark results

  • Requests per second: 880
  • Requests with 200 status code: 158,504
  • P99 latency: 0.215525308

⚡ Benchmark Comparison

Metric This PR Latest version
RPS 880 1,100
200 158,504 197,967
P99 0.215525308 0.170359806

@Meldiron Meldiron merged commit 166b19b into 1.7.x Jun 9, 2025
40 checks passed
@ItzNotABug ItzNotABug deleted the fix-redirect-rule-parent-1.7.x branch June 9, 2025 12:23
@coderabbitai coderabbitai bot mentioned this pull request Jun 11, 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.

2 participants