BLOG-128 Fix logic for determining published post access based on user login status #129

Merged
squid merged 1 commits from BLOG-128_fix_unpublished_posts_query into release/0.3 2025-08-12 21:58:25 +08:00
Owner

Description

The relationship between is_published_only and has_logged_in:

is_published_only has_logged_in result
T T T
T F T
F T F
F F T

Package Changes

No response

Screenshots

No response

Reference

Resolves #128

Checklist

  • A milestone is set
  • The related issuse has been linked to this branch
### Description The relationship between `is_published_only` and `has_logged_in`: | is_published_only | has_logged_in | result | | ----------------- | ------------- | ------ | | T | T | T | | T | F | T | | F | T | F | | F | F | T | ### Package Changes _No response_ ### Screenshots _No response_ ### Reference Resolves #128 ### Checklist - [x] A milestone is set - [x] The related issuse has been linked to this branch
squid added this to the 0.3 milestone 2025-08-12 21:56:59 +08:00
squid added 1 commit 2025-08-12 21:56:59 +08:00
BLOG-128 fix: logic for determining published post access based on user login status
All checks were successful
Frontend CI / build (push) Successful in 1m11s
Auto Comment On PR / add_improve_comment (pull_request) Successful in 13s
PR Title Check / pr-title-check (pull_request) Successful in 16s
ce65078e8d
Collaborator

/improve

/improve
Collaborator

PR Code Suggestions

CategorySuggestion                                                                                                                                    Impact
General
Rename variable for clarity

The is_published_only variable is used as an input parameter and then reassigned to
represent the effective filter. This overloading can be confusing. Introduce a new
variable, such as effective_is_published_only, to store the calculated filter,
improving clarity and maintainability of the access control logic.

backend/feature/post/src/application/use_case/get_all_post_info_use_case.rs [38-44]

-// | is_published_only | has_logged_in | result |
-// | ----------------- | ------------- | ------ |
-// | T                 | T             | T      |
-// | T                 | F             | T      |
-// | F                 | T             | F      |
-// | F                 | F             | T      |
-let is_published_only = is_published_only || !has_logged_in;
+// | is_published_only (input) | has_logged_in | effective_is_published_only |
+// | ------------------------- | ------------- | --------------------------- |
+// | T                         | T             | T                           |
+// | T                         | F             | T                           |
+// | F                         | T             | F                           |
+// | F                         | F             | T                           |
+let effective_is_published_only = is_published_only || !has_logged_in;
+// Use `effective_is_published_only` in the subsequent call to `get_all_post_info`.
Suggestion importance[1-10]: 7

__

Why: Reassigning the input parameter is_published_only with a derived value can be confusing. Introducing a new variable like effective_is_published_only improves code clarity and maintainability by explicitly separating the input from the calculated filter.

Medium
## PR Code Suggestions ✨ <!-- --> <table><thead><tr><td><strong>Category</strong></td><td align=left><strong>Suggestion&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </strong></td><td align=center><strong>Impact</strong></td></tr><tbody><tr><td rowspan=1>General</td> <td> <details><summary>Rename variable for clarity</summary> ___ **The <code>is_published_only</code> variable is used as an input parameter and then reassigned to <br>represent the effective filter. This overloading can be confusing. Introduce a new <br>variable, such as <code>effective_is_published_only</code>, to store the calculated filter, <br>improving clarity and maintainability of the access control logic.** [backend/feature/post/src/application/use_case/get_all_post_info_use_case.rs [38-44]](https://git.squidspirit.com/squid/blog/src/branch/BLOG-128_fix_unpublished_posts_query/backend/feature/post/src/application/use_case/get_all_post_info_use_case.rs#L38-L44) ```diff -// | is_published_only | has_logged_in | result | -// | ----------------- | ------------- | ------ | -// | T | T | T | -// | T | F | T | -// | F | T | F | -// | F | F | T | -let is_published_only = is_published_only || !has_logged_in; +// | is_published_only (input) | has_logged_in | effective_is_published_only | +// | ------------------------- | ------------- | --------------------------- | +// | T | T | T | +// | T | F | T | +// | F | T | F | +// | F | F | T | +let effective_is_published_only = is_published_only || !has_logged_in; +// Use `effective_is_published_only` in the subsequent call to `get_all_post_info`. ``` <details><summary>Suggestion importance[1-10]: 7</summary> __ Why: Reassigning the input parameter `is_published_only` with a derived value can be confusing. Introducing a new variable like `effective_is_published_only` improves code clarity and maintainability by explicitly separating the input from the calculated filter. </details></details></td><td align=center>Medium </td></tr></tr></tbody></table>
squid merged commit fcada15211 into release/0.3 2025-08-12 21:58:25 +08:00
squid deleted branch BLOG-128_fix_unpublished_posts_query 2025-08-12 21:58:25 +08:00
Sign in to join this conversation.
No description provided.