@@ -171,6 +171,8 @@ func (s *service) ListStorageSpaces(ctx context.Context, req *provider.ListStora
171171 }
172172 sp = append (sp , publicSpaces ... )
173173 } else {
174+ // Here, we only check for the SpaceType filter
175+ // Other filters are handled at the driver level
174176 for _ , filter := range filters {
175177 switch filter .Type {
176178 case provider .ListStorageSpacesRequest_Filter_TYPE_SPACE_TYPE :
@@ -183,38 +185,9 @@ func (s *service) ListStorageSpaces(ctx context.Context, req *provider.ListStora
183185 }
184186 }
185187
186- // for _, filter := range filters {
187- // switch filter.Type {
188- // case provider.ListStorageSpacesRequest_Filter_TYPE_SPACE_TYPE:
189- // spaces, err := s.listSpacesByType(ctx, req, user, spaces.SpaceType(filter.Term.(*provider.ListStorageSpacesRequest_Filter_SpaceType).SpaceType))
190- // if err != nil {
191- // return &provider.ListStorageSpacesResponse{Status: status.NewInternal(ctx, err, err.Error())}, nil
192- // }
193- // sp = append(sp, spaces...)
194- // case provider.ListStorageSpacesRequest_Filter_TYPE_ID:
195- // default:
196- // return nil, errtypes.NotSupported("filter not supported")
197- // }
198- // }
199-
200- // TODO: we should filter at the driver level.
201- // for now let's do it here. optimizations later :)
202- // if id, ok := isFilterByID(req.Filters); ok {
203- // sp = list.Filter(sp, func(s *provider.StorageSpace) bool { return s.Id.OpaqueId == id })
204- // }
205-
206188 return & provider.ListStorageSpacesResponse {Status : status .NewOK (ctx ), StorageSpaces : sp }, nil
207189}
208190
209- func isFilterByID (filters []* provider.ListStorageSpacesRequest_Filter ) (string , bool ) {
210- for _ , f := range filters {
211- if f .Type == provider .ListStorageSpacesRequest_Filter_TYPE_ID {
212- return f .Term .(* provider.ListStorageSpacesRequest_Filter_Id ).Id .OpaqueId , true
213- }
214- }
215- return "" , false
216- }
217-
218191func (s * service ) listSpacesByType (ctx context.Context , req * provider.ListStorageSpacesRequest , user * userpb.User , spaceType spaces.SpaceType ) ([]* provider.StorageSpace , error ) {
219192 sp := []* provider.StorageSpace {}
220193
@@ -247,7 +220,19 @@ func (s *service) listSpacesByType(ctx context.Context, req *provider.ListStorag
247220
248221 // For now, we also return public spaces when you query for projects
249222 // as the front-end will filter these
250- // fallthrough
223+ // but only if the request was not made with an ID-filter,
224+ // as that would mean the requestor is looking for a specific space
225+ //
226+ // Having a `fallthrough` here would've been nice, but Go does
227+ // not allow conditional fallthroughs
228+ if _ , isFilterById := isFilterByID (req .Filters ); ! isFilterById {
229+ publicSpaces , err := s .getPublicSpaces (ctx )
230+ if err != nil {
231+ return nil , err
232+ }
233+
234+ sp = append (sp , publicSpaces ... )
235+ }
251236
252237 case spaces .SpaceTypePublic :
253238 publicSpaces , err := s .getPublicSpaces (ctx )
@@ -455,6 +440,15 @@ func (s *service) DeleteStorageSpace(ctx context.Context, req *provider.DeleteSt
455440 return nil , errors .New ("not supported" )
456441}
457442
443+ func isFilterByID (filters []* provider.ListStorageSpacesRequest_Filter ) (string , bool ) {
444+ for _ , f := range filters {
445+ if f .Type == provider .ListStorageSpacesRequest_Filter_TYPE_ID {
446+ return f .Term .(* provider.ListStorageSpacesRequest_Filter_Id ).Id .OpaqueId , true
447+ }
448+ }
449+ return "" , false
450+ }
451+
458452func (s * service ) Register (ss * grpc.Server ) {
459453 provider .RegisterSpacesAPIServer (ss , s )
460454}
0 commit comments