Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit b2b21f1

Browse files
committed
Check new listing slug doesn't exist on listing PUT
When updating a listing and renaming the current slug, check that the new slug is not already taken by another listing. If so return an error. Closes #105
1 parent f03d63d commit b2b21f1

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

api/jsonapi.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,13 @@ func (i *jsonAPIHandler) PUTListing(w http.ResponseWriter, r *http.Request) {
446446
return
447447
}
448448
listingPath := path.Join(i.node.RepoPath, "root", "listings", ld.Listing.Slug+".json")
449+
if ld.CurrentSlug != ld.Listing.Slug {
450+
_, ferr := os.Stat(listingPath)
451+
if !os.IsNotExist(ferr) {
452+
ErrorResponse(w, http.StatusConflict, "Cannot rename listing. One already exists with the same slug")
453+
return
454+
}
455+
}
449456
contract, err := i.node.SignListing(ld.Listing)
450457
if err != nil {
451458
ErrorResponse(w, http.StatusInternalServerError, err.Error())

0 commit comments

Comments
 (0)