Tencent/WeKnora · error

user is not a system administrator

Error message

user is not a system administrator

What it means

Sentinel ErrUserNotSystemAdmin returned when revoking system-admin from a user whose IsSystemAdmin flag is false — the target simply lacks the privilege. The repo still returns the user plus this error so an audit row with changed=false is recorded for probing attempts.

Source

Thrown at internal/application/repository/user.go:19

package repository

import (
	"context"
	"errors"

	"github.com/Tencent/WeKnora/internal/types"
	"github.com/Tencent/WeKnora/internal/types/interfaces"
	"gorm.io/gorm"
	"gorm.io/gorm/clause"
)

var (
	ErrUserNotFound       = errors.New("user not found")
	ErrUserAlreadyExists  = errors.New("user already exists")
	ErrTokenNotFound      = errors.New("token not found")
	ErrCannotRevokeSelf   = errors.New("cannot revoke your own system admin privileges")
	ErrLastSystemAdmin    = errors.New("cannot revoke the last remaining system administrator")
	ErrUserNotSystemAdmin = errors.New("user is not a system administrator")
)

// userRepository implements user repository interface
type userRepository struct {
	db *gorm.DB
}

// NewUserRepository creates a new user repository
func NewUserRepository(db *gorm.DB) interfaces.UserRepository {
	return &userRepository{db: db}
}

// CreateUser creates a user
func (r *userRepository) CreateUser(ctx context.Context, user *types.User) error {
	// users.tenant_id is nullable in both PostgreSQL and SQLite. GORM would
	// otherwise serialise the uint64 zero value as 0, which violates the
	// PostgreSQL FK and loses the distinction between "not provisioned yet"
	// and a real tenant. Omitting the column stores SQL NULL; reads hydrate it

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Verify the target is actually a system admin before revoking
  2. Treat as a no-op success in the UI, since nothing changed; check for probing patterns in audit logs
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/application/repository/user.go:19 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02). Data as JSON: /api/errors/e8de1c37675847a1. Report an issue: GitHub.