Skip to content

[WEB-4013]chore: publish login and standardize urls in common settings #7013

Merged
sriramveeraghanta merged 4 commits intopreviewfrom
chore-base-url-paths
May 5, 2025
Merged

[WEB-4013]chore: publish login and standardize urls in common settings #7013
sriramveeraghanta merged 4 commits intopreviewfrom
chore-base-url-paths

Conversation

@pablohashescobar
Copy link
Member

@pablohashescobar pablohashescobar commented May 5, 2025

Description

chore: publish login and standardize urls in common settings

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Improvement (change that would cause existing functionality to not work as expected)

Test Scenarios

  • sign-in/sign-up functionality for published project

References

WEB-4013

Summary by CodeRabbit

  • New Features

    • Added utilities to validate URLs and parse URL components.
  • Bug Fixes

    • Enhanced configuration by validating base URLs and setting default paths.
    • Prevented external service synchronization when the live URL is unset or invalid.
  • Style

    • Reformatted function signatures and refined comments for better readability.

@makeplane
Copy link

makeplane bot commented May 5, 2025

Pull Request Linked with Plane Work Items

Comment Automatically Generated by Plane

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 5, 2025

"""

Walkthrough

The changes introduce URL validation and default path assignments for several base URL configuration variables in the settings. A new utility function, is_valid_url, is added to check the correctness of URLs. Another utility function, get_url_components, is added to parse URLs into components. The settings logic now ensures that only valid URLs are used and constructs a new composite LIVE_URL variable. In the S3 object copy background task, a guard clause is added to prevent HTTP requests when the live URL is missing or invalid, and the request URL construction is updated to use parsed components. Minor formatting and comment improvements are made to the base_host function in two modules, without altering their logic.

Changes

File(s) Change Summary
apiserver/plane/utils/url.py Added is_valid_url to validate URLs using urllib.parse.urlparse. Added get_url_components to parse URLs into components if valid. Both include docstrings with usage examples.
apiserver/plane/settings/common.py Added URL validation for base URL environment variables using is_valid_url. Assigned default path values if not set. Introduced composite LIVE_URL by concatenating validated LIVE_BASE_URL and LIVE_BASE_PATH.
apiserver/plane/bgtasks/copy_s3_object.py Added guard clause to sync_with_external_service to skip HTTP POST if settings.LIVE_URL is missing or invalid. Changed POST URL construction to use parsed URL components from get_url_components and appended endpoint path with urljoin.
apiserver/plane/authentication/utils/host.py
apiserver/plane/utils/host.py
Reformatted base_host function signature to multi-line style for readability. Updated comments from plural to singular for "redirection". No logic or parameter changes.

Sequence Diagram(s)

sequenceDiagram
    participant Env as Environment Variables
    participant Settings as common.py
    participant Utils as is_valid_url / get_url_components
    participant App as Application

    Env->>Settings: Provide *_BASE_URL and *_BASE_PATH variables
    Settings->>Utils: Validate each *_BASE_URL with is_valid_url
    Utils-->>Settings: Return True/False for each URL
    Settings->>Settings: Assign default *_BASE_PATH if missing
    Settings->>Settings: If valid, concatenate LIVE_BASE_URL + LIVE_BASE_PATH to form LIVE_URL
    App->>Settings: Use validated URLs and LIVE_URL
Loading
sequenceDiagram
    participant Task as sync_with_external_service
    participant Settings as common.py
    participant Utils as get_url_components
    participant ExternalService as External HTTP Service

    Task->>Settings: Check LIVE_URL
    alt LIVE_URL is valid
        Task->>Utils: Parse LIVE_URL components
        Utils-->>Task: Return URL components
        Task->>ExternalService: POST to constructed URL (scheme + netloc + path + endpoint)
        ExternalService-->>Task: Return response
    else LIVE_URL is not set or invalid
        Task-->>Task: Return empty dict, skip POST
    end
Loading

Poem

In the warren of URLs, we check each one twice,
With is_valid_url, they must look nice!
Paths get defaults, no more unset fright,
And if LIVE_URL is missing, we skip the flight.
Little tweaks to comments, a signature neat—
This bunny’s code is now more complete!
🐇✨
"""


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7fa3ff9 and d8eef4e.

📒 Files selected for processing (1)
  • apiserver/plane/settings/common.py (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apiserver/plane/settings/common.py
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (python)
✨ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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
Contributor

@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: 0

🧹 Nitpick comments (3)
apiserver/plane/settings/common.py (3)

343-343: Improve URL construction for LIVE_URL.

The current string concatenation method might lead to issues if LIVE_BASE_URL ends with a slash and LIVE_BASE_PATH starts with a slash (double slash) or if neither has a slash (missing slash).

Consider using urllib.parse.urljoin for more robust URL construction:

-LIVE_URL = f"{LIVE_BASE_URL}{LIVE_BASE_PATH}" if LIVE_BASE_URL else None
+from urllib.parse import urljoin
+LIVE_URL = urljoin(LIVE_BASE_URL, LIVE_BASE_PATH) if LIVE_BASE_URL else None

317-343: Consider adding composite URLs for consistency.

Only LIVE_URL has a composite variable created. For consistency and to avoid duplicating this logic elsewhere, consider creating similar composite variables for the other base URLs.

ADMIN_BASE_PATH = os.environ.get("ADMIN_BASE_PATH", "/god-mode/")
+ADMIN_URL = f"{ADMIN_BASE_URL}{ADMIN_BASE_PATH}" if ADMIN_BASE_URL else None

SPACE_BASE_PATH = os.environ.get("SPACE_BASE_PATH", "/spaces/")
+SPACE_URL = f"{SPACE_BASE_URL}{SPACE_BASE_PATH}" if SPACE_BASE_URL else None

APP_BASE_PATH = os.environ.get("APP_BASE_PATH", "/")
+APP_URL = f"{APP_BASE_URL}{APP_BASE_PATH}" if APP_BASE_URL else None

If you implement this along with the urljoin suggestion, you'd use the same pattern for all URLs.


321-341: Consider adding logging for invalid URLs.

The code currently silently sets invalid URLs to None. While this is a safe approach, adding logging would help administrators diagnose configuration issues.

+import logging
+logger = logging.getLogger(__name__)

if ADMIN_BASE_URL and not is_valid_url(ADMIN_BASE_URL):
+    logger.warning(f"Invalid ADMIN_BASE_URL provided: {ADMIN_BASE_URL}")
    ADMIN_BASE_URL = None

if SPACE_BASE_URL and not is_valid_url(SPACE_BASE_URL):
+    logger.warning(f"Invalid SPACE_BASE_URL provided: {SPACE_BASE_URL}")
    SPACE_BASE_URL = None

if APP_BASE_URL and not is_valid_url(APP_BASE_URL):
+    logger.warning(f"Invalid APP_BASE_URL provided: {APP_BASE_URL}")
    APP_BASE_URL = None

if LIVE_BASE_URL and not is_valid_url(LIVE_BASE_URL):
+    logger.warning(f"Invalid LIVE_BASE_URL provided: {LIVE_BASE_URL}")
    LIVE_BASE_URL = None
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fbca9d9 and 3d20e33.

📒 Files selected for processing (5)
  • apiserver/plane/authentication/utils/host.py (2 hunks)
  • apiserver/plane/bgtasks/copy_s3_object.py (1 hunks)
  • apiserver/plane/settings/common.py (2 hunks)
  • apiserver/plane/utils/host.py (2 hunks)
  • apiserver/plane/utils/url.py (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
apiserver/plane/bgtasks/copy_s3_object.py (1)
apiserver/plane/app/views/page/base.py (2)
  • post (431-436)
  • post (570-623)
apiserver/plane/authentication/utils/host.py (1)
apiserver/plane/utils/host.py (1)
  • base_host (13-59)
apiserver/plane/utils/host.py (1)
apiserver/plane/authentication/utils/host.py (1)
  • base_host (12-55)
apiserver/plane/settings/common.py (1)
apiserver/plane/utils/url.py (1)
  • is_valid_url (5-26)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (python)
🔇 Additional comments (13)
apiserver/plane/bgtasks/copy_s3_object.py (2)

71-73: Good addition of defensive programming

Adding this guard clause prevents making unnecessary HTTP requests when LIVE_URL is not configured, which improves robustness and performance.


75-75: Change from LIVE_BASE_URL to LIVE_URL properly aligns with URL standardization

This change utilizes the new composite URL setting that combines base URL and path with validation, providing a more standardized approach to URL configuration.

apiserver/plane/authentication/utils/host.py (2)

12-17: Style improvement for better readability

Reformatting the function signature from a single line to multiple lines improves code readability and maintainability.


22-22: Consistent terminology in comments

Changing from "redirections" to "redirection" maintains consistency in terminology across the codebase.

Also applies to: 35-35

apiserver/plane/utils/host.py (2)

13-18: Style improvement for better readability

Reformatting the function signature from a single line to multiple lines improves code readability and maintainability, consistent with changes in the authentication module.


26-26: Consistent terminology in comments

Changing from "redirections" to "redirection" maintains consistency in terminology across the codebase, matching the changes in the authentication module.

Also applies to: 39-39

apiserver/plane/utils/url.py (1)

5-26: Well-implemented URL validation utility

This new utility function properly validates URLs by checking for the presence of both scheme and network location, with appropriate exception handling. The comprehensive docstring with examples is a good practice.

The function could be enhanced in the future to support more complex validation scenarios, but for the current use case of validating configuration URLs, this implementation is sufficient.

apiserver/plane/settings/common.py (6)

16-17: Good choice of utility function import.

The imported is_valid_url function provides a clean way to validate URLs consistently throughout the settings.


317-318: Clean section header for improved readability.

The addition of this section header clearly organizes the code and makes it easier to locate URL-related settings.


321-323: Robust URL validation for ADMIN_BASE_URL.

The validation logic ensures that only properly formed URLs are used, preventing potential issues with malformed URLs.


327-329: Robust URL validation for SPACE_BASE_URL.

The validation logic ensures that only properly formed URLs are used, preventing potential issues with malformed URLs.


332-335: Robust URL validation for APP_BASE_URL.

The validation logic ensures that only properly formed URLs are used, preventing potential issues with malformed URLs.


338-341: Robust URL validation for LIVE_BASE_URL.

The validation logic ensures that only properly formed URLs are used, preventing potential issues with malformed URLs.

Copy link
Contributor

@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: 0

🧹 Nitpick comments (1)
apiserver/plane/utils/url.py (1)

42-42: Consider breaking long docstring example line.

The example line exceeds the project's line length limit (119 > 88 characters).

-        >>> get_url_components("https://example.com/path?query=1")
+        >>> get_url_components("https://example.com/path?query=1")
+        # Returns:
🧰 Tools
🪛 Ruff (0.8.2)

42-42: Line too long (119 > 88)

(E501)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3d20e33 and 7fa3ff9.

📒 Files selected for processing (2)
  • apiserver/plane/bgtasks/copy_s3_object.py (3 hunks)
  • apiserver/plane/utils/url.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apiserver/plane/bgtasks/copy_s3_object.py
🧰 Additional context used
🪛 Ruff (0.8.2)
apiserver/plane/utils/url.py

42-42: Line too long (119 > 88)

(E501)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (python)
🔇 Additional comments (2)
apiserver/plane/utils/url.py (2)

1-28: Well-implemented URL validation function with proper error handling.

The is_valid_url function is well-structured with comprehensive documentation, proper type hints, and robust validation logic. The implementation correctly checks for both scheme and netloc components, which are essential for a valid URL, and includes error handling for potential TypeError exceptions.


30-55: Good URL component extraction with proper validation.

The get_url_components function effectively builds on the validation logic and properly parses URL components into a structured dictionary. The function correctly returns None for invalid URLs and includes comprehensive documentation.

🧰 Tools
🪛 Ruff (0.8.2)

42-42: Line too long (119 > 88)

(E501)

@sriramveeraghanta sriramveeraghanta merged commit 42e2b78 into preview May 5, 2025
5 of 6 checks passed
@sriramveeraghanta sriramveeraghanta deleted the chore-base-url-paths branch May 5, 2025 13:28
@coderabbitai coderabbitai bot mentioned this pull request May 5, 2025
1 task
al-jaber-nishad pushed a commit to Xinotrix-Home/task-and-meeting-management that referenced this pull request May 27, 2025
makeplane#7013)

* chore: handling base path and urls

* chore: uniformize urls in common settings

* correct live url

* chore: use url join to correctly join urls

---------

Co-authored-by: sriram veeraghanta <veeraghanta.sriram@gmail.com>
lifeiscontent pushed a commit that referenced this pull request Aug 18, 2025
#7013)

* chore: handling base path and urls

* chore: uniformize urls in common settings

* correct live url

* chore: use url join to correctly join urls

---------

Co-authored-by: sriram veeraghanta <veeraghanta.sriram@gmail.com>
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