Skip to content

refactor: replace hardcoded user plan strings with CloudPlan enum - #27675

Merged
crazywoola merged 1 commit into
mainfrom
feat/add-enum-for-user-plan
Nov 3, 2025
Merged

refactor: replace hardcoded user plan strings with CloudPlan enum#27675
crazywoola merged 1 commit into
mainfrom
feat/add-enum-for-user-plan

Conversation

@laipz8200

Copy link
Copy Markdown
Member

Summary

This PR introduces a CloudPlan StrEnum to replace hardcoded user plan string literals throughout the backend codebase, improving type safety and maintainability.

Changes:

  • Created api/enums/cloud_plan.py with CloudPlan enum (SANDBOX, PROFESSIONAL, TEAM)
  • Used Python's auto() for automatic lowercase value generation
  • Replaced hardcoded 'sandbox' strings with CloudPlan.SANDBOX in 18 production files
  • Updated 4 test files for consistency
  • All existing tests pass, lint and type checks pass

Benefits:

  • Type Safety: Compile-time checking prevents typos and invalid plan values
  • Maintainability: Centralized plan definitions in one location
  • Code Clarity: Explicit enum members are more self-documenting than string literals
  • Consistency: Ensures uniform plan identifiers across the codebase

Fixes #27674

Screenshots

N/A - Backend refactoring only, no UI changes

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Oct 30, 2025
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @laipz8200, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the backend codebase by replacing hardcoded user plan string literals with a new CloudPlan StrEnum. This change aims to enhance the application's robustness and readability by centralizing plan definitions, improving type safety, and ensuring consistent usage across various modules. The refactoring covers both production and test files, making the system more maintainable and less prone to errors related to plan identification.

Highlights

  • New CloudPlan StrEnum: Introduced a CloudPlan StrEnum (SANDBOX, PROFESSIONAL, TEAM) to centralize user plan definitions, using Python's auto() for automatic lowercase value generation.
  • Enhanced Type Safety and Maintainability: Replaced hardcoded 'sandbox' string literals with CloudPlan.SANDBOX across 18 production files and updated 4 test files, significantly improving type safety, code clarity, and maintainability.
  • Improved Consistency: Ensures uniform plan identifiers throughout the backend codebase, reducing the likelihood of typos and invalid plan values.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request is a solid refactoring that replaces hardcoded plan strings with a CloudPlan enum, significantly improving type safety and maintainability across the codebase. The changes are well-executed and consistent. I've added a couple of suggestions to further leverage the new enum for even better type safety in a Pydantic model and a request parser, which aligns with the goals of this PR.

Comment thread api/controllers/console/billing/billing.py
Comment thread api/services/feature_service.py
@laipz8200
laipz8200 force-pushed the feat/add-enum-for-user-plan branch 2 times, most recently from 1f5e56d to e5cbf84 Compare October 31, 2025 06:33
@laipz8200
laipz8200 requested a review from crazywoola October 31, 2025 06:44
- Create CloudPlan StrEnum with SANDBOX, PROFESSIONAL, and TEAM values
- Replace all hardcoded 'sandbox' strings with CloudPlan.SANDBOX throughout backend
- Update 18 production files and 4 test files for consistency
- Use auto() for automatic lowercase value generation from enum names

Fixes #27674
@laipz8200
laipz8200 force-pushed the feat/add-enum-for-user-plan branch from e5cbf84 to 306edc0 Compare October 31, 2025 18:47
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Nov 1, 2025
@crazywoola
crazywoola merged commit 2abbc14 into main Nov 3, 2025
14 checks passed
@crazywoola
crazywoola deleted the feat/add-enum-for-user-plan branch November 3, 2025 03:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Chore/Refactor] Replace hardcoded user plan strings with CloudPlan enum

3 participants