Skip to content

Go: fix CLI logout command - #14672

Merged
JinHai-CN merged 1 commit into
infiniflow:mainfrom
JinHai-CN:fix418
May 8, 2026
Merged

JinHai-CN merged 1 commit into
infiniflow:mainfrom
JinHai-CN:fix418

Conversation

@JinHai-CN

Copy link
Copy Markdown
Member

What problem does this PR solve?

RAGFlow(user)> logout;
SUCCESS

Type of change

  • Bug Fix (non-breaking change which fixes an issue)

@JinHai-CN JinHai-CN added the ci Continue Integration label May 8, 2026
@coderabbitai

coderabbitai Bot commented May 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR updates the CLI authentication flow by changing the admin logout endpoint from /user/logout to /auth/logout and switching the HTTP method to POST, while simultaneously removing unused LIST command handlers and simplifying SHOW CURRENT error validation in the command parser.

Changes

CLI Authentication and Command Parsing

Layer / File(s) Summary
Logout Endpoint Update
internal/cli/common_command.go
Logout now targets "/auth/logout" with POST method for admin server type; response validation logic unchanged.
Command Parser Simplifications
internal/cli/user_parser.go
TokenServices, TokenUsers, and TokenRoles LIST cases removed from parseListCommand; SHOW CURRENT error handling simplified to direct return for non-USER/MODEL tokens.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • infiniflow/ragflow#14658: Modifies CLI auth endpoints in internal/cli/common_command.go—switching between /auth/* and /user/* paths and request methods.
  • infiniflow/ragflow#14665: Changes server-side routing to POST /auth/logout, coordinating with this client-side update.

Suggested labels

🐞 bug, size:S

Poem

🐰 Through the auth gate we softly hop,
From /user/logout to POST/auth*,*
And old LIST commands we must drop,
While SHOW CURRENT finds its way—
Simpler paths to brighter days!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Go: fix CLI logout command' accurately reflects the main changes to the logout endpoint and HTTP method in the CLI logout implementation.
Description check ✅ Passed The description follows the required template with both sections completed: 'What problem does this PR solve?' and 'Type of change' with bug fix selected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

@JinHai-CN
JinHai-CN marked this pull request as ready for review May 8, 2026 07:58
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label May 8, 2026

@coderabbitai coderabbitai 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
internal/cli/common_command.go (2)

204-231: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Clear LoginToken after a successful logout.

After a successful server-side logout, c.HTTPClient.LoginToken is never zeroed. This means:

  • Logout() can be called again without hitting the "not logged in" guard.
  • Any subsequent method that uses the HTTP client will send the now-invalidated token and receive a server-side auth error instead of a clear "not logged in" client-side error.
🐛 Proposed fix
 	if result.Code != 0 {
 		return nil, fmt.Errorf("login failed: %s", result.Message)
 	}

+	c.HTTPClient.LoginToken = ""
 	return &result, nil
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/cli/common_command.go` around lines 204 - 231, The Logout() method
in RAGFlowClient doesn't clear c.HTTPClient.LoginToken after a successful
server-side logout; update Logout (after unmarshalling into result and verifying
result.Code == 0) to set c.HTTPClient.LoginToken = "" (clear the token on
success) before returning the SimpleResponse so subsequent calls hit the
client-side "not logged in" guard and no stale token is sent; modify the Logout
function around the result SimpleResponse handling to perform this token
zeroing.

222-227: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Stale "login failed" error messages inside Logout().

Both error returns in the logout path copy the wording from loginUser, making failures harder to diagnose.

🐛 Proposed fix
 	if err = json.Unmarshal(resp.Body, &result); err != nil {
-		return nil, fmt.Errorf("login failed: invalid JSON (%w)", err)
+		return nil, fmt.Errorf("logout failed: invalid JSON (%w)", err)
 	}

 	if result.Code != 0 {
-		return nil, fmt.Errorf("login failed: %s", result.Message)
+		return nil, fmt.Errorf("logout failed: %s", result.Message)
 	}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/cli/common_command.go` around lines 222 - 227, The error messages in
the Logout() path incorrectly say "login failed" and should reflect logout;
update the two error returns in the logout flow (the json.Unmarshal error check
that currently returns fmt.Errorf("login failed: invalid JSON (%w)", err) and
the result.Code != 0 branch that returns fmt.Errorf("login failed: %s",
result.Message)) to use "logout failed" and preserve the wrapped error/detail
(e.g., "logout failed: invalid JSON (%w)" and "logout failed: %s") so failures
are correctly attributed to Logout() rather than loginUser.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@internal/cli/common_command.go`:
- Around line 204-231: The Logout() method in RAGFlowClient doesn't clear
c.HTTPClient.LoginToken after a successful server-side logout; update Logout
(after unmarshalling into result and verifying result.Code == 0) to set
c.HTTPClient.LoginToken = "" (clear the token on success) before returning the
SimpleResponse so subsequent calls hit the client-side "not logged in" guard and
no stale token is sent; modify the Logout function around the result
SimpleResponse handling to perform this token zeroing.
- Around line 222-227: The error messages in the Logout() path incorrectly say
"login failed" and should reflect logout; update the two error returns in the
logout flow (the json.Unmarshal error check that currently returns
fmt.Errorf("login failed: invalid JSON (%w)", err) and the result.Code != 0
branch that returns fmt.Errorf("login failed: %s", result.Message)) to use
"logout failed" and preserve the wrapped error/detail (e.g., "logout failed:
invalid JSON (%w)" and "logout failed: %s") so failures are correctly attributed
to Logout() rather than loginUser.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9ffacf3b-d219-4761-b93f-2261edebb0b0

📥 Commits

Reviewing files that changed from the base of the PR and between 94f82ac and 20c0734.

📒 Files selected for processing (2)
  • internal/cli/common_command.go
  • internal/cli/user_parser.go

@codecov

codecov Bot commented May 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.16%. Comparing base (94f82ac) to head (20c0734).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #14672   +/-   ##
=======================================
  Coverage   94.16%   94.16%           
=======================================
  Files          10       10           
  Lines         703      703           
  Branches      112      112           
=======================================
  Hits          662      662           
  Misses         25       25           
  Partials       16       16           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JinHai-CN
JinHai-CN merged commit ce2ec86 into infiniflow:main May 8, 2026
1 check failed
pekar9781 pushed a commit to pekar9781/ragflow that referenced this pull request May 8, 2026
### What problem does this PR solve?

```
RAGFlow(user)> logout;
SUCCESS
```

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)

Signed-off-by: Jin Hai <[email protected]>
Ricardo-M-L pushed a commit to Ricardo-M-L/ragflow that referenced this pull request Aug 17, 2026
### What problem does this PR solve?

```
RAGFlow(user)> logout;
SUCCESS
```

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)

Signed-off-by: Jin Hai <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant