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

Commit

Permalink
Check new listing slug doesn't exist on listing PUT
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cpacia committed Oct 13, 2016
1 parent f03d63d commit b2b21f1
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions api/jsonapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,13 @@ func (i *jsonAPIHandler) PUTListing(w http.ResponseWriter, r *http.Request) {
return
}
listingPath := path.Join(i.node.RepoPath, "root", "listings", ld.Listing.Slug+".json")
if ld.CurrentSlug != ld.Listing.Slug {
_, ferr := os.Stat(listingPath)
if !os.IsNotExist(ferr) {
ErrorResponse(w, http.StatusConflict, "Cannot rename listing. One already exists with the same slug")
return
}
}
contract, err := i.node.SignListing(ld.Listing)
if err != nil {
ErrorResponse(w, http.StatusInternalServerError, err.Error())
Expand Down

0 comments on commit b2b21f1

Please sign in to comment.