Skip to content

Commit

Permalink
remove requirement for ?setdefaultversionid when createdat timestamps…
Browse files Browse the repository at this point in the history
… are all the same

Signed-off-by: Doug Davis <[email protected]>
  • Loading branch information
duglin committed Jan 4, 2025
1 parent 8a4f609 commit 4918164
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
8 changes: 3 additions & 5 deletions registry/httpStuff.go
Original file line number Diff line number Diff line change
Expand Up @@ -1640,11 +1640,8 @@ func HTTPPutPost(info *RequestInfo) error {

vID := info.GetFlag("setdefaultversionid")
if vID == "" || vID == "request" {
if len(objMap) > 1 {
if vID == "request" && len(objMap) > 1 {
info.StatusCode = http.StatusBadRequest
if vID == "" {
return fmt.Errorf("?setdefaultversionid is required")
}
return fmt.Errorf("?setdefaultversionid can not be " +
"'request'")
}
Expand Down Expand Up @@ -1907,7 +1904,8 @@ func ProcessSetDefaultVersionIDFlag(info *RequestInfo, resource *Resource, versi
if vID == "request" {
if version == nil {
info.StatusCode = http.StatusBadRequest
return fmt.Errorf("Can't use 'request' if a version wasn't processed")
return fmt.Errorf("Can't use 'request' if a version wasn't " +
"processed")
}
// stick default version to current one we just processed
return resource.SetDefault(version)
Expand Down
37 changes: 27 additions & 10 deletions tests/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10087,25 +10087,42 @@ func TestHTTPResourcesBulk(t *testing.T) {
})

xCheckHTTP(t, reg, &HTTPTest{
Name: "POST resources/f10/versions - new res,version-2v",
URL: "/dirs/dir1/files/f10/versions",
Name: "POST resources/f99/versions - new res,version-2v,newest=alphabetical",
URL: "/dirs/dir1/files/f99/versions",
Method: "POST",
ReqHeaders: []string{},
ReqBody: `{
"v1": {},
"v10": {},
"v2": {}
}`,
Code: 400,
ResHeaders: []string{
"Content-Type:text/plain; charset=utf-8",
},
ResBody: `?setdefaultversionid is required
Code: 200,
ResBody: `{
"v10": {
"fileid": "f99",
"versionid": "v10",
"self": "http://localhost:8181/dirs/dir1/files/f99/versions/v10$structure",
"xid": "/dirs/dir1/files/f99/versions/v10",
"epoch": 1,
"createdat": "2025-01-04T13:31:22.013338763Z",
"modifiedat": "2025-01-04T13:31:22.013338763Z"
},
"v2": {
"fileid": "f99",
"versionid": "v2",
"self": "http://localhost:8181/dirs/dir1/files/f99/versions/v2$structure",
"xid": "/dirs/dir1/files/f99/versions/v2",
"epoch": 1,
"isdefault": true,
"createdat": "2025-01-04T13:31:22.013338763Z",
"modifiedat": "2025-01-04T13:31:22.013338763Z"
}
}
`,
})

xCheckHTTP(t, reg, &HTTPTest{
Name: "POST resources/f10/versions - new res,version-1v",
URL: "/dirs/dir1/files/f10/versions?setdefaultversionid=v2",
URL: "/dirs/dir1/files/f10/versions?setdefaultversionid=v3",
Method: "POST",
ReqHeaders: []string{},
ReqBody: `{
Expand All @@ -10115,7 +10132,7 @@ func TestHTTPResourcesBulk(t *testing.T) {
ResHeaders: []string{
"Content-Type:text/plain; charset=utf-8",
},
ResBody: `Version "v2" not found
ResBody: `Version "v3" not found
`,
})

Expand Down

0 comments on commit 4918164

Please sign in to comment.