enhance(dbfs): admin should be able to access user's files even if it's inactive (#2327)

pull/2224/merge
Aaron Liu 2025-05-13 15:08:00 +08:00
parent 1b8beb3390
commit 71a624c10e
1 changed files with 8 additions and 1 deletions

View File

@ -3,7 +3,9 @@ package dbfs
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/cloudreve/Cloudreve/v4/ent" "github.com/cloudreve/Cloudreve/v4/ent"
"github.com/cloudreve/Cloudreve/v4/ent/user"
"github.com/cloudreve/Cloudreve/v4/inventory" "github.com/cloudreve/Cloudreve/v4/inventory"
"github.com/cloudreve/Cloudreve/v4/pkg/boolset" "github.com/cloudreve/Cloudreve/v4/pkg/boolset"
"github.com/cloudreve/Cloudreve/v4/pkg/cache" "github.com/cloudreve/Cloudreve/v4/pkg/cache"
@ -83,11 +85,16 @@ func (n *myNavigator) To(ctx context.Context, path *fs.URI) (*File, error) {
return nil, ErrPermissionDenied return nil, ErrPermissionDenied
} }
targetUser, err := n.userClient.GetLoginUserByID(ctx, fsUid) ctx = context.WithValue(ctx, inventory.LoadUserGroup{}, true)
targetUser, err := n.userClient.GetByID(ctx, fsUid)
if err != nil { if err != nil {
return nil, fs.ErrPathNotExist.WithError(fmt.Errorf("user not found: %w", err)) return nil, fs.ErrPathNotExist.WithError(fmt.Errorf("user not found: %w", err))
} }
if targetUser.Status != user.StatusActive && !n.user.Edges.Group.Permissions.Enabled(int(types.GroupPermissionIsAdmin)) {
return nil, fs.ErrPathNotExist.WithError(fmt.Errorf("inactive user"))
}
rootFile, err := n.fileClient.Root(ctx, targetUser) rootFile, err := n.fileClient.Root(ctx, targetUser)
if err != nil { if err != nil {
n.l.Info("User's root folder not found: %s, will initialize it.", err) n.l.Info("User's root folder not found: %s, will initialize it.", err)