From a12c4b2fe349f2cd182e92478b7a0c737a5cace6 Mon Sep 17 00:00:00 2001 From: Abhishek Shroff Date: Mon, 24 Mar 2025 22:18:12 +0530 Subject: [PATCH] [server][cmd] Populate newly created resources with parent permissions --- server/internal/core/fs/copy_move.go | 1 + server/internal/core/fs/create.go | 10 ++++++++-- server/internal/core/fs/sql_common.go | 3 +-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/server/internal/core/fs/copy_move.go b/server/internal/core/fs/copy_move.go index 9341d99b..358b0e22 100644 --- a/server/internal/core/fs/copy_move.go +++ b/server/internal/core/fs/copy_move.go @@ -126,6 +126,7 @@ func (r Resource) Copy(target string, id uuid.UUID, recursive bool, conflictReso r.contentType, r.contentSHA256, conflictResolution, + r.permissions, ) // createResource may return an already existing resources, depending on the specified conflictResolution id = res.id diff --git a/server/internal/core/fs/create.go b/server/internal/core/fs/create.go index 98a84610..64afa36e 100644 --- a/server/internal/core/fs/create.go +++ b/server/internal/core/fs/create.go @@ -54,7 +54,7 @@ func (r Resource) CreateMemberResource(name string, id uuid.UUID, dir bool, conf var created bool err := r.f.runInTx(func(f filesystem) error { var err error - if res, created, _, err = f.createResource(id, r.id, name, dir, 0, emptyContentType, emptyContentSHA256, conflictResolution); err != nil { + if res, created, _, err = f.createResource(id, r.id, name, dir, 0, emptyContentType, emptyContentSHA256, conflictResolution, r.permissions); err != nil { return err } else if created { if err := f.db.RecomputePermissions(f.ctx, id); err != nil { @@ -94,6 +94,7 @@ func (f filesystem) createResource( contentType string, contentSHA256 string, conflictResolution ResourceBindConflictResolution, + permissions []byte, ) (res Resource, created, deleted bool, err error) { err = f.runInTx(func(f filesystem) error { res, err = f.insertResource( @@ -104,6 +105,7 @@ func (f filesystem) createResource( contentLength, contentType, contentSHA256, + permissions, ) return err }) @@ -135,6 +137,7 @@ func (f filesystem) createResource( contentLength, contentType, contentSHA256, + permissions, ) return err }) @@ -178,6 +181,7 @@ func (f filesystem) createResource( contentType, contentSHA256, ResourceBindConflictResolutionError, + permissions, ) } } @@ -197,6 +201,7 @@ func (f filesystem) createResource( contentType, contentSHA256, ResourceBindConflictResolutionError, + permissions, ) } } @@ -208,7 +213,7 @@ func (f filesystem) createResource( return } -func (f filesystem) insertResource(id, parent uuid.UUID, name string, dir bool, contentLength int64, contentType, contentSha256 string) (Resource, error) { +func (f filesystem) insertResource(id, parent uuid.UUID, name string, dir bool, contentLength int64, contentType, contentSha256 string, permissions []byte) (Resource, error) { query, args, _ := pg.From("resources"). Insert(). Rows(goqu.Record{ @@ -219,6 +224,7 @@ func (f filesystem) insertResource(id, parent uuid.UUID, name string, dir bool, "content_length": goqu.V(contentLength), "content_type": goqu.V(contentType), "content_sha256": goqu.V(contentSha256), + "permissions": goqu.V(permissions), }). Returning("*"). ToSQL() diff --git a/server/internal/core/fs/sql_common.go b/server/internal/core/fs/sql_common.go index d5471b6f..30778466 100644 --- a/server/internal/core/fs/sql_common.go +++ b/server/internal/core/fs/sql_common.go @@ -57,7 +57,7 @@ func (f filesystem) collectResource(rows pgx.Rows) (Resource, error) { } func (f filesystem) scanResource(row pgx.CollectableRow) (Resource, error) { - var r Resource + r := Resource{f: f} err := row.Scan( &r.id, &r.name, @@ -86,7 +86,6 @@ func (f filesystem) scanResource(row pgx.CollectableRow) (Resource, error) { if permission&PermissionRead == 0 { return Resource{}, ErrResourceNotFound } - r.f = f r.userPermission = permission return r, err }