Skip to content

Commit

Permalink
fix setting default version on POST /versions
Browse files Browse the repository at this point in the history
Signed-off-by: Doug Davis <[email protected]>
  • Loading branch information
duglin committed Jan 6, 2025
1 parent 0399d99 commit 378d999
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
18 changes: 13 additions & 5 deletions registry/httpStuff.go
Original file line number Diff line number Diff line change
Expand Up @@ -1650,7 +1650,8 @@ func HTTPPutPost(info *RequestInfo) error {
return fmt.Errorf("?setdefaultversionid can not be " +
"'request'")
}
// Only one Version so use its ID as the default version
// Just randomly grab one Verison and make it the default
// one for now
for k, _ := range objMap {
vID = k
break
Expand Down Expand Up @@ -1686,16 +1687,17 @@ func HTTPPutPost(info *RequestInfo) error {
}

// Process the remaining versions
addType := ADD_UPSERT
if method == "PATCH" {
addType = ADD_PATCH
}
for id, obj := range objMap {
addType := ADD_UPSERT
if method == "PATCH" {
addType = ADD_PATCH
}
v, _, err := resource.UpsertVersionWithObject(id, obj, addType)
if err != nil {
info.StatusCode = http.StatusBadRequest
return err
}

paths = append(paths, v.Path)
}

Expand All @@ -1704,6 +1706,12 @@ func HTTPPutPost(info *RequestInfo) error {
return err
}

// Make sure the latest version is chosen appropriately
err = resource.EnsureLatest()
if err != nil {
return err
}

if len(paths) == 0 {
paths = []string{"!"} // Force an empty collection to be returned
}
Expand Down
20 changes: 15 additions & 5 deletions tests/http2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2980,16 +2980,17 @@ func TestHTTPResourcesBulk(t *testing.T) {
Method: "POST",
ReqHeaders: []string{},
ReqBody: `{
"v10": {},
"v1": {},
"v9": {},
"v2": {}
}`,
Code: 200,
ResBody: `{
"v10": {
"v1": {
"fileid": "f99",
"versionid": "v10",
"self": "http://localhost:8181/dirs/dir1/files/f99/versions/v10$structure",
"xid": "/dirs/dir1/files/f99/versions/v10",
"versionid": "v1",
"self": "http://localhost:8181/dirs/dir1/files/f99/versions/v1$structure",
"xid": "/dirs/dir1/files/f99/versions/v1",
"epoch": 1,
"createdat": "2025-01-04T13:31:22.013338763Z",
"modifiedat": "2025-01-04T13:31:22.013338763Z"
Expand All @@ -3000,6 +3001,15 @@ func TestHTTPResourcesBulk(t *testing.T) {
"self": "http://localhost:8181/dirs/dir1/files/f99/versions/v2$structure",
"xid": "/dirs/dir1/files/f99/versions/v2",
"epoch": 1,
"createdat": "2025-01-04T13:31:22.013338763Z",
"modifiedat": "2025-01-04T13:31:22.013338763Z"
},
"v9": {
"fileid": "f99",
"versionid": "v9",
"self": "http://localhost:8181/dirs/dir1/files/f99/versions/v9$structure",
"xid": "/dirs/dir1/files/f99/versions/v9",
"epoch": 1,
"isdefault": true,
"createdat": "2025-01-04T13:31:22.013338763Z",
"modifiedat": "2025-01-04T13:31:22.013338763Z"
Expand Down

0 comments on commit 378d999

Please sign in to comment.