Use first admin user for all scan operations

This commit is contained in:
Deluan 2020-07-17 20:25:13 -04:00 committed by Deluan Quintão
parent 9cf8c92cae
commit 609d172259
2 changed files with 17 additions and 13 deletions

View File

@ -93,9 +93,7 @@ func (s *playlistSync) parsePlaylist(ctx context.Context, playlistFile string, b
}
func (s *playlistSync) updatePlaylistIfNewer(ctx context.Context, newPls *model.Playlist) error {
owner := s.getPlaylistsOwner(ctx)
ctx = request.WithUsername(ctx, owner.UserName)
ctx = request.WithUser(ctx, *owner)
owner, _ := request.UsernameFrom(ctx)
pls, err := s.ds.Playlist(ctx).FindByPath(newPls.Path)
if err != nil && err != model.ErrNotFound {
@ -113,16 +111,8 @@ func (s *playlistSync) updatePlaylistIfNewer(ctx context.Context, newPls *model.
newPls.Comment = pls.Comment
newPls.Owner = pls.Owner
} else {
log.Info(ctx, "Adding synced playlist", "playlist", newPls.Name, "path", newPls.Path, "owner", owner.UserName)
newPls.Owner = owner.UserName
log.Info(ctx, "Adding synced playlist", "playlist", newPls.Name, "path", newPls.Path, "owner", owner)
newPls.Owner = owner
}
return s.ds.Playlist(ctx).Put(newPls)
}
func (s *playlistSync) getPlaylistsOwner(ctx context.Context) *model.User {
u, err := s.ds.User(ctx).FindFirstAdmin()
if err != nil {
log.Error(ctx, "Error retrieving playlist owner", err)
}
return u
}

View File

@ -9,6 +9,7 @@ import (
"github.com/deluan/navidrome/log"
"github.com/deluan/navidrome/model"
"github.com/deluan/navidrome/model/request"
"github.com/deluan/navidrome/utils"
)
@ -44,6 +45,8 @@ func NewTagScanner2(rootFolder string, ds model.DataStore) *TagScanner2 {
// refresh the collected albums and artists with the metadata from the mediafiles
// Delete all empty albums, delete all empty Artists
func (s *TagScanner2) Scan(ctx context.Context, lastModifiedSince time.Time) error {
ctx = s.setAdminUser(ctx)
start := time.Now()
allDirs, err := s.getDirTree(ctx)
if err != nil {
@ -321,3 +324,14 @@ func (s *TagScanner2) loadTracks(filePaths []string) (model.MediaFiles, error) {
}
return mfs, nil
}
func (s *TagScanner2) setAdminUser(ctx context.Context) context.Context {
u, err := s.ds.User(ctx).FindFirstAdmin()
if err != nil {
log.Error(ctx, "Error retrieving playlist owner", err)
u = &model.User{}
}
ctx = request.WithUsername(ctx, u.UserName)
return request.WithUser(ctx, *u)
}