mirror of https://github.com/cloudreve/Cloudreve
				
				
				
			enhance(dbfs): admin should be able to access user's files even if it's inactive (#2327)
							parent
							
								
									1b8beb3390
								
							
						
					
					
						commit
						71a624c10e
					
				| 
						 | 
				
			
			@ -3,7 +3,9 @@ package dbfs
 | 
			
		|||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"fmt"
 | 
			
		||||
 | 
			
		||||
	"github.com/cloudreve/Cloudreve/v4/ent"
 | 
			
		||||
	"github.com/cloudreve/Cloudreve/v4/ent/user"
 | 
			
		||||
	"github.com/cloudreve/Cloudreve/v4/inventory"
 | 
			
		||||
	"github.com/cloudreve/Cloudreve/v4/pkg/boolset"
 | 
			
		||||
	"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
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		targetUser, err := n.userClient.GetLoginUserByID(ctx, fsUid)
 | 
			
		||||
		ctx = context.WithValue(ctx, inventory.LoadUserGroup{}, true)
 | 
			
		||||
		targetUser, err := n.userClient.GetByID(ctx, fsUid)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			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)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			n.l.Info("User's root folder not found: %s, will initialize it.", err)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue