Skip to content

fix: refactor admin permission checks into util package#2060

Merged
hsluoyz merged 4 commits into
masterfrom
copilot/refactor-admin-checks-to-util
Dec 10, 2025
Merged

fix: refactor admin permission checks into util package#2060
hsluoyz merged 4 commits into
masterfrom
copilot/refactor-admin-checks-to-util

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 10, 2025

Hardcoded role strings like "chat-admin" and "video-normal-user" were scattered across controllers, routers, and object packages, making role management brittle and difficult to maintain.

Changes

  • New util/permission.go with centralized permission functions:

    • IsAdminOrChatAdmin(user) - combines system admin and chat-admin checks
    • IsChatAdmin(user) - chat-admin role check
    • IsVideoNormalUser(user) - video user role check
    • Constants: UserTypeChatAdmin, UserTypeVideoNormalUser
  • Replaced inline checks in 5 files:

    • routers/authz_filter.go
    • controllers/util.go, controllers/account.go, controllers/video.go
    • object/util.go

Before:

// Duplicated across codebase
isAdmin := user != nil && (user.IsAdmin || user.Type == "chat-admin")
if user.Type == "video-normal-user" { ... }

After:

// Single source of truth
if !util.IsAdminOrChatAdmin(user) { ... }
if util.IsVideoNormalUser(user) { ... }

All role strings now exist only in util/permission.go.

Original prompt

This section details on the original issue you should resolve

<issue_title>[feature] refactor out all admin checks like "chat-admin" in backend</issue_title>
<issue_description>Put all permission checking code like user.IsAdmin, user.Type == "chat-admin" into util functions in util package

finally we will not have any static values like "chat-admin" outside of util package</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@hsluoyz hsluoyz marked this pull request as ready for review December 10, 2025 07:27
- Created util/permission.go with centralized permission checking functions
- Added IsChatAdmin(), IsAdminOrChatAdmin(), and IsVideoNormalUser() functions
- Defined constants for user types: UserTypeChatAdmin and UserTypeVideoNormalUser
- Updated all files to use new util functions instead of hardcoded checks
- Added comprehensive tests for permission utility functions
- All hardcoded role strings like "chat-admin" now only exist in util package

Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor admin permission checks to util package Refactor admin permission checks into util package Dec 10, 2025
Copilot AI requested a review from hsluoyz December 10, 2025 07:42
@hsluoyz hsluoyz changed the title Refactor admin permission checks into util package fix: refactor admin permission checks into util package Dec 10, 2025
@hsluoyz hsluoyz merged commit fc349a0 into master Dec 10, 2025
1 of 2 checks passed
@hsluoyz hsluoyz deleted the copilot/refactor-admin-checks-to-util branch January 1, 2026 18:09
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.

[feature] refactor out all admin checks like "chat-admin" in backend

2 participants