acl
This commit is contained in:
+17
-2
@@ -9,9 +9,17 @@ import (
|
||||
|
||||
"mediarr/database"
|
||||
"mediarr/ident"
|
||||
"mediarr/permission"
|
||||
)
|
||||
|
||||
func (s *Service) CreateLibrary(ctx context.Context, params CreateLibraryParams) (*Document, error) {
|
||||
func (s *Service) CreateLibrary(ctx context.Context, actorID ident.UUID, params CreateLibraryParams) (*Document, error) {
|
||||
if err := s.requireActive(ctx, actorID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if params.OwnerID != actorID || params.CreatedBy != actorID {
|
||||
return nil, fmt.Errorf("%w: owner_id et created_by doivent être l'acteur", ErrPermissionDenied)
|
||||
}
|
||||
|
||||
name, nameKey, err := normalizeName(params.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -64,7 +72,11 @@ func (s *Service) CreateLibrary(ctx context.Context, params CreateLibraryParams)
|
||||
return documentFromDB(created), nil
|
||||
}
|
||||
|
||||
func (s *Service) CreateFolder(ctx context.Context, params CreateFolderParams) (*Document, error) {
|
||||
func (s *Service) CreateFolder(ctx context.Context, actorID ident.UUID, params CreateFolderParams) (*Document, error) {
|
||||
if params.OwnerID != actorID || params.CreatedBy != actorID {
|
||||
return nil, fmt.Errorf("%w: owner_id et created_by doivent être l'acteur", ErrPermissionDenied)
|
||||
}
|
||||
|
||||
name, nameKey, err := normalizeName(params.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -83,6 +95,9 @@ func (s *Service) CreateFolder(ctx context.Context, params CreateFolderParams) (
|
||||
if !isContainerKind(parent.Kind) {
|
||||
return nil, fmt.Errorf("%w: %s", ErrInvalidParent, parent.Kind)
|
||||
}
|
||||
if err := s.can(ctx, actorID, params.ParentID, permission.Create); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
id, err := ident.NewV7()
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user