[PR #819] [MERGED] fix(user): enforce address count limit when anonymous creation disabled #786

Closed
opened 2026-02-26 21:32:57 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/dreamhunter2333/cloudflare_temp_email/pull/819
Author: @dreamhunter2333
Created: 1/23/2026
Status: Merged
Merged: 1/23/2026
Merged by: @dreamhunter2333

Base: mainHead: feature/email


📝 Commits (1)

  • 8ee65eb fix(user): enforce address count limit when anonymous creation disabled

📊 Changes

5 files changed (+89 additions, -45 deletions)

View changed files

📝 CHANGELOG.md (+15 -1)
📝 CHANGELOG_EN.md (+15 -1)
📝 worker/src/mails_api/index.ts (+13 -2)
📝 worker/src/user_api/bind_address.ts (+5 -41)
📝 worker/src/utils.ts (+41 -0)

📄 Description

User description

问题描述

DISABLE_ANONYMOUS_USER_CREATE_EMAIL=true 时,已登录用户创建地址时没有检查地址数量限制,导致用户可以创建超过限制数量的地址。

修复内容

1. 新增地址数量限制检查

  • /api/new_address 接口中,当禁止匿名创建且用户已登录时,创建地址前检查用户的地址数量限制
  • 如果已达到限制,返回 400 错误

2. 提取公共函数

  • 新增 isAddressCountLimitReached() 函数,统一处理地址数量限制检查逻辑
  • 新增 getMaxAddressCount() 函数,获取用户的最大地址数量(支持角色配置)
  • 重构 bind_address.ts 中的 3 处重复代码,使用新的公共函数

3. 代码改进

  • 添加 JSDoc 文档注释
  • 函数命名清晰:isAddressCountLimitReached 明确表示"是否已达到限制"
  • 减少代码重复,提升可维护性

修改的文件

  • worker/src/utils.ts: 新增公共函数
  • worker/src/mails_api/index.ts: 添加地址数量检查
  • worker/src/user_api/bind_address.ts: 重构使用公共函数
  • CHANGELOG.md / CHANGELOG_EN.md: 更新 v1.3.0 变更日志

测试

  • 编译通过
  • 匿名用户创建地址被拒绝
  • 已登录用户未超限时可以创建
  • 已登录用户已超限时被拒绝
  • 绑定地址时检查限制(最终防线)
  • 转移地址时检查目标用户限制

相关 Issue

Fixes #[issue_number]


PR Type

Bug fix, Enhancement


Description

  • Enforced address count limit for logged-in users when anonymous creation is disabled.

  • Extracted and centralized address count limit logic into reusable functions.

  • Refactored code to improve maintainability and reduce duplication.

  • Updated changelogs to document the changes and improvements.


Diagram Walkthrough

flowchart LR
  A["/api/new_address"] -- "Check address count limit" --> B["isAddressCountLimitReached"]
  B -- "Limit reached" --> C["Return 400 error"]
  B -- "Limit not reached" --> D["Proceed with address creation"]
  E["bind_address.ts"] -- "Refactor to use" --> B
  F["utils.ts"] -- "Add reusable functions" --> B

File Walkthrough

Relevant files
Bug fix
index.ts
Enforce address count limit in new address API                     

worker/src/mails_api/index.ts

  • Added address count limit check in /api/new_address.
  • Integrated isAddressCountLimitReached for logged-in users.
  • Improved error handling for address creation limits.
+13/-2   
Enhancement
bind_address.ts
Refactor address binding to use centralized limit check   

worker/src/user_api/bind_address.ts

  • Refactored to use isAddressCountLimitReached for address binding.
  • Removed redundant code for address count checks.
  • Improved maintainability by centralizing logic.
+5/-41   
utils.ts
Add reusable functions for address count limit checks       

worker/src/utils.ts

  • Added isAddressCountLimitReached to check address limits.
  • Added getMaxAddressCount to fetch role-based address limits.
  • Centralized and documented address limit logic.
+41/-0   
Documentation
CHANGELOG.md
Update changelog for v1.3.0 with bug fixes and improvements

CHANGELOG.md

  • Documented bug fix for address count limit enforcement.
  • Added details about new reusable functions.
  • Updated version to v1.3.0.
+15/-1   
CHANGELOG_EN.md
Update English changelog for v1.3.0 with bug fixes and improvements

CHANGELOG_EN.md

  • Documented bug fix for address count limit enforcement.
  • Added details about new reusable functions.
  • Updated version to v1.3.0.
+15/-1   


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/dreamhunter2333/cloudflare_temp_email/pull/819 **Author:** [@dreamhunter2333](https://github.com/dreamhunter2333) **Created:** 1/23/2026 **Status:** ✅ Merged **Merged:** 1/23/2026 **Merged by:** [@dreamhunter2333](https://github.com/dreamhunter2333) **Base:** `main` ← **Head:** `feature/email` --- ### 📝 Commits (1) - [`8ee65eb`](https://github.com/dreamhunter2333/cloudflare_temp_email/commit/8ee65ebe8a3f8085540c2300f782546da14e751d) fix(user): enforce address count limit when anonymous creation disabled ### 📊 Changes **5 files changed** (+89 additions, -45 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+15 -1) 📝 `CHANGELOG_EN.md` (+15 -1) 📝 `worker/src/mails_api/index.ts` (+13 -2) 📝 `worker/src/user_api/bind_address.ts` (+5 -41) 📝 `worker/src/utils.ts` (+41 -0) </details> ### 📄 Description ### **User description** ## 问题描述 当 `DISABLE_ANONYMOUS_USER_CREATE_EMAIL=true` 时,已登录用户创建地址时没有检查地址数量限制,导致用户可以创建超过限制数量的地址。 ## 修复内容 ### 1. 新增地址数量限制检查 - 在 `/api/new_address` 接口中,当禁止匿名创建且用户已登录时,创建地址前检查用户的地址数量限制 - 如果已达到限制,返回 400 错误 ### 2. 提取公共函数 - 新增 `isAddressCountLimitReached()` 函数,统一处理地址数量限制检查逻辑 - 新增 `getMaxAddressCount()` 函数,获取用户的最大地址数量(支持角色配置) - 重构 `bind_address.ts` 中的 3 处重复代码,使用新的公共函数 ### 3. 代码改进 - 添加 JSDoc 文档注释 - 函数命名清晰:`isAddressCountLimitReached` 明确表示"是否已达到限制" - 减少代码重复,提升可维护性 ## 修改的文件 - `worker/src/utils.ts`: 新增公共函数 - `worker/src/mails_api/index.ts`: 添加地址数量检查 - `worker/src/user_api/bind_address.ts`: 重构使用公共函数 - `CHANGELOG.md` / `CHANGELOG_EN.md`: 更新 v1.3.0 变更日志 ## 测试 - [x] 编译通过 - [x] 匿名用户创建地址被拒绝 - [x] 已登录用户未超限时可以创建 - [x] 已登录用户已超限时被拒绝 - [x] 绑定地址时检查限制(最终防线) - [x] 转移地址时检查目标用户限制 ## 相关 Issue Fixes #[issue_number] ___ ### **PR Type** Bug fix, Enhancement ___ ### **Description** - Enforced address count limit for logged-in users when anonymous creation is disabled. - Extracted and centralized address count limit logic into reusable functions. - Refactored code to improve maintainability and reduce duplication. - Updated changelogs to document the changes and improvements. ___ ### Diagram Walkthrough ```mermaid flowchart LR A["/api/new_address"] -- "Check address count limit" --> B["isAddressCountLimitReached"] B -- "Limit reached" --> C["Return 400 error"] B -- "Limit not reached" --> D["Proceed with address creation"] E["bind_address.ts"] -- "Refactor to use" --> B F["utils.ts"] -- "Add reusable functions" --> B ``` <details> <summary><h3> File Walkthrough</h3></summary> <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Bug fix</strong></td><td><table> <tr> <td> <details> <summary><strong>index.ts</strong><dd><code>Enforce address count limit in new address API</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary> <hr> worker/src/mails_api/index.ts <ul><li>Added address count limit check in <code>/api/new_address</code>.<br> <li> Integrated <code>isAddressCountLimitReached</code> for logged-in users.<br> <li> Improved error handling for address creation limits.</ul> </details> </td> <td><a href="https://github.com/dreamhunter2333/cloudflare_temp_email/pull/819/files#diff-83710df6a60b2b512e134f32ad9890ab9a255040f6019f0d5603f72f4561cea4">+13/-2</a>&nbsp; &nbsp; </td> </tr> </table></td></tr><tr><td><strong>Enhancement</strong></td><td><table> <tr> <td> <details> <summary><strong>bind_address.ts</strong><dd><code>Refactor address binding to use centralized limit check</code>&nbsp; &nbsp; </dd></summary> <hr> worker/src/user_api/bind_address.ts <ul><li>Refactored to use <code>isAddressCountLimitReached</code> for address binding.<br> <li> Removed redundant code for address count checks.<br> <li> Improved maintainability by centralizing logic.</ul> </details> </td> <td><a href="https://github.com/dreamhunter2333/cloudflare_temp_email/pull/819/files#diff-ada3e8ad268246f0c99c97065551303c02fded466c73a4f525f6206cb49bdebf">+5/-41</a>&nbsp; &nbsp; </td> </tr> <tr> <td> <details> <summary><strong>utils.ts</strong><dd><code>Add reusable functions for address count limit checks</code>&nbsp; &nbsp; &nbsp; &nbsp; </dd></summary> <hr> worker/src/utils.ts <ul><li>Added <code>isAddressCountLimitReached</code> to check address limits.<br> <li> Added <code>getMaxAddressCount</code> to fetch role-based address limits.<br> <li> Centralized and documented address limit logic.</ul> </details> </td> <td><a href="https://github.com/dreamhunter2333/cloudflare_temp_email/pull/819/files#diff-87b77c56897ffc7830773b3d665c51ecf2210b44921bef7098a1dd6d64e56db6">+41/-0</a>&nbsp; &nbsp; </td> </tr> </table></td></tr><tr><td><strong>Documentation</strong></td><td><table> <tr> <td> <details> <summary><strong>CHANGELOG.md</strong><dd><code>Update changelog for v1.3.0 with bug fixes and improvements</code></dd></summary> <hr> CHANGELOG.md <ul><li>Documented bug fix for address count limit enforcement.<br> <li> Added details about new reusable functions.<br> <li> Updated version to v1.3.0.</ul> </details> </td> <td><a href="https://github.com/dreamhunter2333/cloudflare_temp_email/pull/819/files#diff-06572a96a58dc510037d5efa622f9bec8519bc1beab13c9f251e97e657a9d4ed">+15/-1</a>&nbsp; &nbsp; </td> </tr> <tr> <td> <details> <summary><strong>CHANGELOG_EN.md</strong><dd><code>Update English changelog for v1.3.0 with bug fixes and improvements</code></dd></summary> <hr> CHANGELOG_EN.md <ul><li>Documented bug fix for address count limit enforcement.<br> <li> Added details about new reusable functions.<br> <li> Updated version to v1.3.0.</ul> </details> </td> <td><a href="https://github.com/dreamhunter2333/cloudflare_temp_email/pull/819/files#diff-77d2276dbbf8eb648363b81ea97049986b18e2cf1e90bd20fb5133ed5ff4fcae">+15/-1</a>&nbsp; &nbsp; </td> </tr> </table></td></tr></tr></tbody></table> </details> ___ --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-26 21:32:57 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/cloudflare_temp_email#786
No description provided.