Repository navigation
fix: chat user login #7803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: chat user login #7803
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,7 +42,7 @@ def _get_login_policy(cls, access_token): | |
| auth_setting.get("lock_time", 10), | ||
| ) | ||
| portal = Portal.objects.first() | ||
| if portal is None or not portal.enable_auth: | ||
| if portal is None: | ||
| return ("portal", 1, 5, 10) | ||
| auth_config = portal.auth_config or {} | ||
| return ( | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is the review of the code snippet provided: 1. Potential Logic Issue (High Priority)Regularity: The logic change might be intentional, but it introduces a potential bypass security risk.
2. Style & Formatting
3. Optimization / Readability Suggestions
RecommendationsOption A: Fix Formatting Only (If business logic requires ignoring
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,8 +21,8 @@ const displayName = computed(() => account.value?.nickName || account.value?.use | |
| // 配额尚未接入时保留空值展示,不将缺失数据表示为零用量。 | ||
| const tokenPercentage = computed(() => { | ||
| const quota = account.value?.token_quota | ||
| if (!quota) return 0 | ||
| return Math.min(100, Math.max(0, (quota.used_tokens / quota.total_tokens) * 100)) | ||
| if (!quota || quota.quota_type === QUOTA_TYPE.UNLIMITED || !quota.token_limit) return 0 | ||
| return Math.min(100, Math.max(0, (quota.used_tokens / quota.token_limit) * 100)) | ||
| }) | ||
|
|
||
| const userPwdDialogRef = useTemplateRef<InstanceType<typeof UserPwdDialog>>('userPwdDialogRef') | ||
|
|
@@ -71,7 +71,7 @@ const goLogin = () => { | |
| <span class="mr-3">Tokens</span> | ||
| <span class="text-primary">{{ formatTokenNumber(account?.token_quota?.used_tokens) }}</span> | ||
| <span class="text-N500"> | ||
| /{{ account?.token_quota?.quota_type === QUOTA_TYPE.UNLIMITED ? '不限' : formatTokenNumber(account?.token_quota?.total_tokens) }} | ||
| /{{ account?.token_quota?.quota_type === QUOTA_TYPE.UNLIMITED ? '不限' : formatTokenNumber(account?.token_quota?.token_limit) }} | ||
| </span> | ||
| </div> | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is an analysis of the code changes, including potential issues and optimization suggestions: 1. Logical Consistency and Data Integrity
2. Code Clarity and Robustness
3. Edge Case Handling
4. Template Change AnalysisIn the template: /{{ account?.token_quota?.quota_type === QUOTA_TYPE.UNLIMITED ? '不限' : formatTokenNumber(account?.token_quota?.token_limit) }}
Summary of Recommendations
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is an analysis of the provided code diff, highlighting potential issues and optimization suggestions. 1. Critical Issue: Inconsistent Data Consistency & "Unlimited" Representation in PercentageProblem:
Optimization/Suggestion: However, looking at the template change, it seems the template also handles 2. Naming Convention & Data Structure Mismatch (
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the review of the code diff provided:
1. Logical/Security Irregularity (Critical)
Issue: Removing
or not portal.enable_authfrom the validation check.enable_auth = False), the system would fall back to default values or a different logic path (depending on what was elsewhere, but here it returned defaults).portal.auth_configeven ifportal.enable_authisFalse.2. Code Quality & Readability
Issue: Unnecessary space before colon.
if portal is None :ifstatement.if portal is None:3. Ambiguity / Logic Flow
Issue: Incomplete visibility of the fallback logic.
returnstatement after this block is cut off (return (). It’s unclear what happens ifauth_configlacks keys or ifenable_authis true/false. Ensure that whenenable_authis false, the function does not proceed to readauth_configunless intended.Recommendation
Revert the semantic change unless you have a specific reason to allow lockout policies on non-authenticating portals. If
enable_auth=False, you should likely still return defaults or skip policy application.If you must keep this change, fix the style:
But seriously, restore the
enable_authcheck unless it's a deliberate and well-documented behavior change.