From cf498d241a9fb545b19a51c580f3da6f3a2aa4f8 Mon Sep 17 00:00:00 2001 From: Daniel Ponte Date: Sat, 1 Feb 2025 21:02:23 -0500 Subject: [PATCH] Implement share DELETE --- pkg/rest/share.go | 20 ++++++++++++++++++++ pkg/shares/store.go | 7 ++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/pkg/rest/share.go b/pkg/rest/share.go index 44af365..647e837 100644 --- a/pkg/rest/share.go +++ b/pkg/rest/share.go @@ -213,4 +213,24 @@ func (sa *shareAPI) routeShare(w http.ResponseWriter, r *http.Request) { } func (sa *shareAPI) deleteShare(w http.ResponseWriter, r *http.Request) { + ctx := r.Context() + shs := shares.FromCtx(ctx) + + p := struct { + ID string `param:"id"` + }{} + + err := decodeParams(&p, r) + if err != nil { + wErr(w, r, autoError(err)) + return + } + + err = shs.Delete(ctx, p.ID) + if err != nil { + wErr(w, r, autoError(err)) + return + } + + w.WriteHeader(http.StatusNoContent) } diff --git a/pkg/shares/store.go b/pkg/shares/store.go index d0fbad0..cf4e0d6 100644 --- a/pkg/shares/store.go +++ b/pkg/shares/store.go @@ -80,7 +80,12 @@ func (s *postgresStore) Create(ctx context.Context, share *Share) error { } func (s *postgresStore) Delete(ctx context.Context, id string) error { - _, err := rbac.Check(ctx, new(Share), rbac.WithActions(entities.ActionDelete)) + sh, err := s.GetShare(ctx, id) + if err != nil { + return err + } + + _, err = rbac.Check(ctx, sh, rbac.WithActions(entities.ActionDelete)) if err != nil { return err }