fix: [OCISDEV-828] Fix the response code on deleting a non-existing link share on a space (#12266)

fix: Return 404 when deleting a non-existing link share on a space
This commit is contained in:
Roman Perekhod authored and GitHub committed 2026-06-22 14:10:44 +02:00
1 parent 84c0641d7c
commit f3d2bc0557
10 files changed
+83 -28

No files matched your search

@@ -0,0 +1,10 @@
Bugfix: Return 404 when deleting a non-existing link share on a space
Deleting an already-removed link share via
`DELETE /graph/v1beta1/drives/{driveID}/root/permissions/{permissionID}`
returned `400 Bad Request` instead of `404 Not Found`. The underlying
reva `RemovePublicShare` and `RemoveShare` handlers now propagate
not-found errors as `CODE_NOT_FOUND` rather than `CODE_INTERNAL`,
ensuring the correct `404` HTTP response is returned.
https://github.com/owncloud/ocis/issues/12266
+1
View File
@@ -7,3 +7,4 @@ https://github.com/owncloud/ocis/pull/12087
https://github.com/owncloud/ocis/pull/12137
https://github.com/owncloud/ocis/pull/12302
https://github.com/owncloud/ocis/pull/12439
https://github.com/owncloud/ocis/pull/12266
+1 -1
View File
@@ -65,7 +65,7 @@ require (
github.com/open-policy-agent/opa v1.17.1
github.com/orcaman/concurrent-map v1.0.0
github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245
github.com/owncloud/reva/v2 v2.0.0-20260617085643-abda3f89dbd0
github.com/owncloud/reva/v2 v2.0.0-20260622073440-d60fcb5db155
github.com/pkg/errors v0.9.1
github.com/pkg/xattr v0.4.12
github.com/prometheus/client_golang v1.23.2
+2 -4
View File
@@ -738,8 +738,8 @@ github.com/orcaman/concurrent-map v1.0.0 h1:I/2A2XPCb4IuQWcQhBhSwGfiuybl/J0ev9HD
github.com/orcaman/concurrent-map v1.0.0/go.mod h1:Lu3tH6HLW3feq74c2GC+jIMS/K2CFcDWnWD9XkenwhI=
github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245 h1:JRidLTAKhnvyLMRtVtSF4lhBa0NSAOs6fof+d6JnKII=
github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245/go.mod h1:z61VMGAJRtR1nbgXWiNoCkxUXP1B3Je9rMuJbnGd+Og=
github.com/owncloud/reva/v2 v2.0.0-20260617085643-abda3f89dbd0 h1:zPhDPz/17viirEREAujV5lTCEn741VsqhOowiRSvZQY=
github.com/owncloud/reva/v2 v2.0.0-20260617085643-abda3f89dbd0/go.mod h1:gNSgpblFyfCDi1OQfU4VqPIHWtAPR3YPTE1ZaTNnG/U=
github.com/owncloud/reva/v2 v2.0.0-20260622073440-d60fcb5db155 h1:RaT3PLjficoMB6SMoeU1BfcwBULTjbuHbXC+bmW1780=
github.com/owncloud/reva/v2 v2.0.0-20260622073440-d60fcb5db155/go.mod h1:gNSgpblFyfCDi1OQfU4VqPIHWtAPR3YPTE1ZaTNnG/U=
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw=
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0=
github.com/pablodz/inotifywaitgo v0.0.9 h1:njquRbBU7fuwIe5rEvtaniVBjwWzcpdUVptSgzFqZsw=
@@ -1369,8 +1369,6 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/ini.v1 v1.67.2 h1:JtOSMb9OuaCZKr7h5D/h6iii14sK0hLbplTc6frx4Ss=
gopkg.in/ini.v1 v1.67.2/go.mod h1:x/cyOwCgZqOkJoDIJ3c1KNHMo10+nLGAhh+kn3Zizss=
gopkg.in/ini.v1 v1.67.3 h1:iM9Lhz5MRSGhHVGGwCuzG9KO8PoirCXj/m/qTmOJJQw=
gopkg.in/ini.v1 v1.67.3/go.mod h1:x/cyOwCgZqOkJoDIJ3c1KNHMo10+nLGAhh+kn3Zizss=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
@@ -247,6 +247,19 @@ Feature: Remove access to a drive
Then the HTTP status code should be "204"
And user "Alice" should not have any "link" permissions on space "projectSpace"
Scenario: user tries to remove an already-deleted link share from project space using root endpoint
Given the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API
And user "Alice" has created a space "NewSpace" with the default quota using the Graph API
And user "Alice" has created the following space link share:
| space | NewSpace |
| permissionsRole | View |
| password | %public% |
And user "Alice" removes the link from space "NewSpace" using root endpoint of the Graph API
And the HTTP status code should be "204"
When user "Alice" removes the link from space "NewSpace" using root endpoint of the Graph API
Then the HTTP status code should be "404"
@env-config
Scenario: remove space share after the share role Space Editor Without Versions has been disabled
Given using spaces DAV path
@@ -31,13 +31,13 @@ import (
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
link "github.com/cs3org/go-cs3apis/cs3/sharing/link/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/mitchellh/mapstructure"
"github.com/owncloud/reva/v2/pkg/password"
"github.com/owncloud/reva/v2/pkg/permission"
"github.com/owncloud/reva/v2/pkg/rgrpc/todo/pool"
"github.com/owncloud/reva/v2/pkg/sharedconf"
"github.com/owncloud/reva/v2/pkg/storage/utils/grants"
"github.com/owncloud/reva/v2/pkg/utils"
"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
"github.com/rs/zerolog"
"google.golang.org/grpc"
@@ -352,9 +352,14 @@ func (s *service) RemovePublicShare(ctx context.Context, req *link.RemovePublicS
user := ctxpkg.ContextMustGetUser(ctx)
ps, err := s.sm.GetPublicShare(ctx, user, req.GetRef(), false)
if err != nil {
return &link.RemovePublicShareResponse{
Status: status.NewInternal(ctx, "error loading public share"),
}, err
var st *rpc.Status
switch err.(type) {
case errtypes.IsNotFound:
st = status.NewNotFound(ctx, err.Error())
default:
st = status.NewInternal(ctx, "error loading public share")
}
return &link.RemovePublicShareResponse{Status: st}, nil
}
sRes, err := gatewayClient.Stat(ctx, &provider.StatRequest{Ref: &provider.Reference{ResourceId: ps.ResourceId}})
@@ -262,9 +262,14 @@ func (s *service) RemoveShare(ctx context.Context, req *collaboration.RemoveShar
user := ctxpkg.ContextMustGetUser(ctx)
share, err := s.sm.GetShare(ctx, req.Ref)
if err != nil {
return &collaboration.RemoveShareResponse{
Status: status.NewInternal(ctx, "error getting share"),
}, nil
var st *rpc.Status
switch err.(type) {
case errtypes.IsNotFound:
st = status.NewNotFound(ctx, err.Error())
default:
st = status.NewInternal(ctx, "error getting share")
}
return &collaboration.RemoveShareResponse{Status: st}, nil
}
gatewayClient, err := s.gatewaySelector.Next()
@@ -29,6 +29,7 @@ import (
"strings"
"github.com/google/renameio/v2"
"github.com/owncloud/reva/v2/pkg/appctx"
"github.com/owncloud/reva/v2/pkg/storage/cache"
"github.com/pkg/xattr"
"github.com/rogpeppe/go-internal/lockedfile"
@@ -263,7 +264,10 @@ func (b MessagePackBackend) loadAttributes(ctx context.Context, path string, sou
err = b.metaCache.PushToCache(b.cacheKey(path), attribs)
subspan.End()
if err != nil {
return nil, err
// The attributes were read successfully from disk. A failure to
// write them back into the cache (e.g. a dead NATS connection) must
// not fail the read - log it and return the data we already have.
appctx.GetLogger(ctx).Warn().Err(err).Str("path", path).Msg("failed to write attributes to cache")
}
return attribs, nil
+33 -14
View File
@@ -23,13 +23,13 @@ import (
"strings"
"time"
"github.com/owncloud/reva/v2/pkg/store/etcd"
"github.com/owncloud/reva/v2/pkg/store/memory"
natsjs "github.com/go-micro/plugins/v4/store/nats-js"
natsjskv "github.com/go-micro/plugins/v4/store/nats-js-kv"
"github.com/go-micro/plugins/v4/store/redis"
redisopts "github.com/go-redis/redis/v8"
"github.com/nats-io/nats.go"
"github.com/owncloud/reva/v2/pkg/store/etcd"
"github.com/owncloud/reva/v2/pkg/store/memory"
"go-micro.dev/v4/logger"
microstore "go-micro.dev/v4/store"
)
@@ -125,12 +125,7 @@ func Create(opts ...microstore.Option) microstore.Store {
// TODO nats needs a DefaultTTL option as it does not support per Write TTL ...
// FIXME nats has restrictions on the key, we cannot use slashes AFAICT
// host, port, clusterid
natsOptions := nats.GetDefaultOptions()
natsOptions.Name = "TODO" // we can pass in the service name to allow identifying the client, but that requires adding a custom context option
if auth, ok := options.Context.Value(authenticationContextKey{}).([]string); ok && len(auth) == 2 {
natsOptions.User = auth[0]
natsOptions.Password = auth[1]
}
natsOptions := defaultNatsOptions(options)
return natsjs.NewStore(
append(opts,
natsjs.NatsOptions(natsOptions), // always pass in properly initialized default nats options
@@ -143,12 +138,7 @@ func Create(opts ...microstore.Option) microstore.Store {
opts = append(opts, natsjskv.DefaultMemory())
}
natsOptions := nats.GetDefaultOptions()
natsOptions.Name = "TODO" // we can pass in the service name to allow identifying the client, but that requires adding a custom context option
if auth, ok := options.Context.Value(authenticationContextKey{}).([]string); ok && len(auth) == 2 {
natsOptions.User = auth[0]
natsOptions.Password = auth[1]
}
natsOptions := defaultNatsOptions(options)
return natsjskv.NewStore(
append(opts,
natsjskv.NatsOptions(natsOptions), // always pass in properly initialized default nats options
@@ -166,3 +156,32 @@ func Create(opts ...microstore.Option) microstore.Store {
return microstore.NewMemoryStore(opts...)
}
}
// defaultNatsOptions builds the nats.Options shared by the nats-js and
// nats-js-kv store backends. It overrides the NATS client defaults so the
// client never permanently gives up on a closed connection: the default
// MaxReconnect (60) combined with the default ReconnectWait (2s) means any
// NATS outage longer than ~2 minutes leaves the client permanently closed,
// which the store plugins then surface as "nats: connection closed" on every
// subsequent operation. Reconnecting forever, together with the connection
// state handlers, keeps the client alive and makes the transitions visible.
func defaultNatsOptions(options *microstore.Options) nats.Options {
natsOptions := nats.GetDefaultOptions()
natsOptions.Name = "reva-store"
natsOptions.MaxReconnect = -1 // reconnect forever; the default of 60 gives up after ~2 minutes
natsOptions.ReconnectWait = 5 * time.Second
if auth, ok := options.Context.Value(authenticationContextKey{}).([]string); ok && len(auth) == 2 {
natsOptions.User = auth[0]
natsOptions.Password = auth[1]
}
natsOptions.DisconnectedErrCB = func(_ *nats.Conn, err error) {
logger.Logf(logger.WarnLevel, "reva-store: nats connection disconnected: %v", err)
}
natsOptions.ReconnectedCB = func(c *nats.Conn) {
logger.Logf(logger.InfoLevel, "reva-store: nats connection reconnected to %s", c.ConnectedUrl())
}
natsOptions.ClosedCB = func(_ *nats.Conn) {
logger.Logf(logger.ErrorLevel, "reva-store: nats connection closed")
}
return natsOptions
}
+1 -1
View File
@@ -1319,7 +1319,7 @@ github.com/orcaman/concurrent-map
# github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245
## explicit; go 1.18
github.com/owncloud/libre-graph-api-go
# github.com/owncloud/reva/v2 v2.0.0-20260617085643-abda3f89dbd0
# github.com/owncloud/reva/v2 v2.0.0-20260622073440-d60fcb5db155
## explicit; go 1.25.7
github.com/owncloud/reva/v2/cmd/revad/internal/grace
github.com/owncloud/reva/v2/cmd/revad/runtime