This commit is contained in:
venture
2026-11-15 09:04:18 +01:00
parent 03da7d9fff
commit 29a6ab40f0
16 changed files with 660 additions and 112 deletions
+24 -5
View File
@@ -4,21 +4,28 @@ import (
"context"
"mediarr/ident"
"mediarr/permission"
)
func (s *Service) Get(ctx context.Context, id ident.UUID) (*Document, error) {
func (s *Service) Get(ctx context.Context, actorID, id ident.UUID) (*Document, error) {
document, err := s.getDocument(ctx, id)
if err != nil {
return nil, err
}
if err := s.can(ctx, actorID, id, permission.Read); err != nil {
return nil, err
}
return documentFromDB(*document), nil
}
func (s *Service) ListChildren(ctx context.Context, parentID ident.UUID) ([]Document, error) {
func (s *Service) ListChildren(ctx context.Context, actorID, parentID ident.UUID) ([]Document, error) {
if _, err := s.getActiveDocument(ctx, parentID); err != nil {
return nil, err
}
if err := s.can(ctx, actorID, parentID, permission.Read); err != nil {
return nil, err
}
rows, err := s.db.Queries.ListDocumentChildren(ctx, &parentID)
if err != nil {
@@ -27,13 +34,19 @@ func (s *Service) ListChildren(ctx context.Context, parentID ident.UUID) ([]Docu
documents := make([]Document, 0, len(rows))
for _, row := range rows {
documents = append(documents, *documentFromDB(row))
allowed, err := s.allowed(ctx, actorID, row.ID, permission.Read)
if err != nil {
return nil, err
}
if allowed {
documents = append(documents, *documentFromDB(row))
}
}
return documents, nil
}
func (s *Service) ListLibraries(ctx context.Context) ([]Document, error) {
func (s *Service) ListLibraries(ctx context.Context, actorID ident.UUID) ([]Document, error) {
rows, err := s.db.Queries.ListLibraries(ctx)
if err != nil {
return nil, err
@@ -41,7 +54,13 @@ func (s *Service) ListLibraries(ctx context.Context) ([]Document, error) {
documents := make([]Document, 0, len(rows))
for _, row := range rows {
documents = append(documents, *documentFromDB(row))
allowed, err := s.allowed(ctx, actorID, row.ID, permission.Read)
if err != nil {
return nil, err
}
if allowed {
documents = append(documents, *documentFromDB(row))
}
}
return documents, nil