satellite/{admin,console,satellitedb}: fix geofence removal
deleteGeofenceForProject wasn't able to work correctly, because Console().Projects().Update() declines to update default_placement when the input value is 0. This introduces a Console().Projects().UpdateDefaultPlacement() method, congruent to the method of the same name on Console().Users(). deleteGeofenceForProject now uses this new method, so that specifying a new placement of 0 will work correctly. Change-Id: I4589b36707f7e4f1cfdc66543520b0d4205c1a84
This commit is contained in:
parent
e98b94f114
commit
a9265ae543
@ -684,7 +684,7 @@ func (server *Server) createGeofenceForProject(w http.ResponseWriter, r *http.Re
|
||||
}
|
||||
|
||||
func (server *Server) deleteGeofenceForProject(w http.ResponseWriter, r *http.Request) {
|
||||
server.setGeofenceForProject(w, r, storj.EveryCountry)
|
||||
server.setGeofenceForProject(w, r, storj.DefaultPlacement)
|
||||
}
|
||||
|
||||
func (server *Server) setGeofenceForProject(w http.ResponseWriter, r *http.Request, placement storj.PlacementConstraint) {
|
||||
@ -711,9 +711,7 @@ func (server *Server) setGeofenceForProject(w http.ResponseWriter, r *http.Reque
|
||||
|
||||
}
|
||||
|
||||
project.DefaultPlacement = placement
|
||||
|
||||
err = server.db.Console().Projects().Update(ctx, project)
|
||||
err = server.db.Console().Projects().UpdateDefaultPlacement(ctx, project.ID, placement)
|
||||
if err != nil {
|
||||
sendJSONError(w, "unable to set geofence for project",
|
||||
err.Error(), http.StatusInternalServerError)
|
||||
|
@ -58,6 +58,9 @@ type Projects interface {
|
||||
|
||||
// UpdateUserAgent is a method for updating projects user agent.
|
||||
UpdateUserAgent(ctx context.Context, id uuid.UUID, userAgent []byte) error
|
||||
|
||||
// UpdateDefaultPlacement is a method to update the project's default placement for new segments.
|
||||
UpdateDefaultPlacement(ctx context.Context, id uuid.UUID, placement storj.PlacementConstraint) error
|
||||
}
|
||||
|
||||
// UsageLimitsConfig is a configuration struct for default per-project usage limits.
|
||||
|
@ -324,6 +324,21 @@ func (projects *projects) UpdateUserAgent(ctx context.Context, id uuid.UUID, use
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdateDefaultPlacement is a method to update the project's default placement for new segments.
|
||||
func (projects *projects) UpdateDefaultPlacement(ctx context.Context, id uuid.UUID, placement storj.PlacementConstraint) (err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
_, err = projects.db.Update_Project_By_Id(
|
||||
ctx,
|
||||
dbx.Project_Id(id[:]),
|
||||
dbx.Project_Update_Fields{
|
||||
DefaultPlacement: dbx.Project_DefaultPlacement(int(placement)),
|
||||
},
|
||||
)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// List returns paginated projects, created before provided timestamp.
|
||||
func (projects *projects) List(ctx context.Context, offset int64, limit int, before time.Time) (_ console.ProjectsPage, err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
Loading…
Reference in New Issue
Block a user