Skip to content

支持管理员可以查询所有视频任务#4250

Open
feitianbubu wants to merge 1 commit intoQuantumNous:mainfrom
feitianbubu:pr/a37df03acfd1343bef7805e1b953df0f8be75320
Open

支持管理员可以查询所有视频任务#4250
feitianbubu wants to merge 1 commit intoQuantumNous:mainfrom
feitianbubu:pr/a37df03acfd1343bef7805e1b953df0f8be75320

Conversation

@feitianbubu
Copy link
Copy Markdown
Contributor

@feitianbubu feitianbubu commented Apr 14, 2026

⚠️ 提交说明 / PR Notice

如果用户有管理员权限, 可以查询所有任务视频,方面排查问题

📸 运行证明 / Proof of Work

  • 修改前:
image
  • 修改后:
image

Summary by CodeRabbit

  • Bug Fixes
    • Improved admin access to task data by implementing a fallback lookup mechanism. Administrators can now retrieve task information through an alternate retrieval path when the standard lookup doesn't return results.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 14, 2026

Walkthrough

The videoFetchByIDRespBodyBuilder function now includes a fallback mechanism. When initial task lookup by user and task ID fails, and the requesting user is an admin, the function attempts an alternate lookup using only the task ID to retrieve task data.

Changes

Cohort / File(s) Summary
Admin task fallback
relay/relay_task.go
Added fallback task lookup for admin users when initial user-scoped query returns no results, using model.GetByOnlyTaskId() as an alternate retrieval path.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • seefs001

Poem

🐰 A task hides from sight, but admins see clear,
With fallback paths, no task we need fear,
By ID alone, we fetch what we seek,
Special access for those with a peek!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title '支持管理员可以查询所有视频任务' (Support administrators to query all video tasks) directly and accurately summarizes the main change: adding admin capability to query all video tasks regardless of user scope.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@relay/relay_task.go`:
- Around line 370-372: The admin fallback currently runs when !exist regardless
of whether GetByTaskId returned an error; change the logic in the block that
calls model.GetByOnlyTaskId so it only executes when err == nil && !exist &&
model.IsAdmin(userId). In other words, after calling model.GetByTaskId(taskId)
check err first and return/handle the error if non-nil; only if err is nil and
exist is false and model.IsAdmin(userId) call model.GetByOnlyTaskId(taskId) to
populate originTask/exist/err so you don't overwrite or mask the original
database error.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 515f4995-15c7-47f4-b950-928ca9afcd1b

📥 Commits

Reviewing files that changed from the base of the PR and between 8c8661d and 6dbdabf.

📒 Files selected for processing (1)
  • relay/relay_task.go

Comment thread relay/relay_task.go
Comment on lines +370 to +372
if !exist && model.IsAdmin(userId) {
originTask, exist, err = model.GetByOnlyTaskId(taskId)
}
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.

⚠️ Potential issue | 🟠 Major

Check query errors before applying admin fallback.

At Line [370], fallback runs on !exist even when GetByTaskId returned err. That can mask the original DB failure for admins by overwriting err with the second query result.

Suggested fix
 originTask, exist, err := model.GetByTaskId(userId, taskId)
-if !exist && model.IsAdmin(userId) {
+if err != nil {
+	taskResp = service.TaskErrorWrapper(err, "get_task_failed", http.StatusInternalServerError)
+	return
+}
+if !exist && model.IsAdmin(userId) {
 	originTask, exist, err = model.GetByOnlyTaskId(taskId)
-}
-if err != nil {
-	taskResp = service.TaskErrorWrapper(err, "get_task_failed", http.StatusInternalServerError)
-	return
+	if err != nil {
+		taskResp = service.TaskErrorWrapper(err, "get_task_failed", http.StatusInternalServerError)
+		return
+	}
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if !exist && model.IsAdmin(userId) {
originTask, exist, err = model.GetByOnlyTaskId(taskId)
}
originTask, exist, err := model.GetByTaskId(userId, taskId)
if err != nil {
taskResp = service.TaskErrorWrapper(err, "get_task_failed", http.StatusInternalServerError)
return
}
if !exist && model.IsAdmin(userId) {
originTask, exist, err = model.GetByOnlyTaskId(taskId)
if err != nil {
taskResp = service.TaskErrorWrapper(err, "get_task_failed", http.StatusInternalServerError)
return
}
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@relay/relay_task.go` around lines 370 - 372, The admin fallback currently
runs when !exist regardless of whether GetByTaskId returned an error; change the
logic in the block that calls model.GetByOnlyTaskId so it only executes when err
== nil && !exist && model.IsAdmin(userId). In other words, after calling
model.GetByTaskId(taskId) check err first and return/handle the error if
non-nil; only if err is nil and exist is false and model.IsAdmin(userId) call
model.GetByOnlyTaskId(taskId) to populate originTask/exist/err so you don't
overwrite or mask the original database error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant