return 409 for share token collision. Have property table show strings to correctly render booleans. Fixes #531 and #443

This commit is contained in:
Cam 2024-01-24 09:48:27 -06:00
parent 00d46be77a
commit b69780908c
No known key found for this signature in database
GPG Key ID: 367B7C7EBD84A8BD
6 changed files with 106 additions and 1 deletions

View File

@ -135,6 +135,16 @@ func (h *shareHandler) Handle(params share.ShareParams, principal *rest_model_zr
sshr.FrontendEndpoint = &sshr.ShareMode
}
sh, err := str.FindShareWithToken(sshr.Token, trx)
if err != nil {
logrus.Errorf("error checking share token collision: %v", err)
return share.NewShareInternalServerError()
}
if sh != nil {
logrus.Errorf("attempting to create share with conflcting token: %v", sshr.Token)
return share.NewShareConflict()
}
sid, err := str.CreateShare(envId, sshr, trx)
if err != nil {
logrus.Errorf("error creating share record: %v", err)

View File

@ -41,6 +41,12 @@ func (o *ShareReader) ReadResponse(response runtime.ClientResponse, consumer run
return nil, err
}
return nil, result
case 409:
result := NewShareConflict()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return nil, result
case 422:
result := NewShareUnprocessableEntity()
if err := result.readResponse(response, consumer, o.formats); err != nil {
@ -238,6 +244,62 @@ func (o *ShareNotFound) readResponse(response runtime.ClientResponse, consumer r
return nil
}
// NewShareConflict creates a ShareConflict with default headers values
func NewShareConflict() *ShareConflict {
return &ShareConflict{}
}
/*
ShareConflict describes a response with status code 409, with default header values.
conflict
*/
type ShareConflict struct {
}
// IsSuccess returns true when this share conflict response has a 2xx status code
func (o *ShareConflict) IsSuccess() bool {
return false
}
// IsRedirect returns true when this share conflict response has a 3xx status code
func (o *ShareConflict) IsRedirect() bool {
return false
}
// IsClientError returns true when this share conflict response has a 4xx status code
func (o *ShareConflict) IsClientError() bool {
return true
}
// IsServerError returns true when this share conflict response has a 5xx status code
func (o *ShareConflict) IsServerError() bool {
return false
}
// IsCode returns true when this share conflict response a status code equal to that given
func (o *ShareConflict) IsCode(code int) bool {
return code == 409
}
// Code gets the status code for the share conflict response
func (o *ShareConflict) Code() int {
return 409
}
func (o *ShareConflict) Error() string {
return fmt.Sprintf("[POST /share][%d] shareConflict ", 409)
}
func (o *ShareConflict) String() string {
return fmt.Sprintf("[POST /share][%d] shareConflict ", 409)
}
func (o *ShareConflict) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
return nil
}
// NewShareUnprocessableEntity creates a ShareUnprocessableEntity with default headers values
func NewShareUnprocessableEntity() *ShareUnprocessableEntity {
return &ShareUnprocessableEntity{}

View File

@ -865,6 +865,9 @@ func init() {
"404": {
"description": "not found"
},
"409": {
"description": "conflict"
},
"422": {
"description": "unprocessable"
},
@ -2488,6 +2491,9 @@ func init() {
"404": {
"description": "not found"
},
"409": {
"description": "conflict"
},
"422": {
"description": "unprocessable"
},

View File

@ -108,6 +108,31 @@ func (o *ShareNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.P
rw.WriteHeader(404)
}
// ShareConflictCode is the HTTP code returned for type ShareConflict
const ShareConflictCode int = 409
/*
ShareConflict conflict
swagger:response shareConflict
*/
type ShareConflict struct {
}
// NewShareConflict creates ShareConflict with default headers values
func NewShareConflict() *ShareConflict {
return &ShareConflict{}
}
// WriteResponse to the client
func (o *ShareConflict) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses
rw.WriteHeader(409)
}
// ShareUnprocessableEntityCode is the HTTP code returned for type ShareUnprocessableEntity
const ShareUnprocessableEntityCode int = 422

View File

@ -577,6 +577,8 @@ paths:
description: unauthorized
404:
description: not found
409:
description: conflict
422:
description: unprocessable
500:

View File

@ -18,7 +18,7 @@ const rowToValue = (row) => {
if(row.property.endsWith("At")) {
return new Date(row.value).toLocaleString();
}
return row.value;
return row.value.toString();
};
const PropertyTable = (props) => {