4
0
Эх сурвалжийг харах

Display an error message on edit feed page when the feed URL is not unique

Frédéric Guillot 2 жил өмнө
parent
commit
e2d862f2f6

+ 1 - 1
internal/api/feed.go

@@ -115,7 +115,7 @@ func (h *handler) updateFeed(w http.ResponseWriter, r *http.Request) {
 		return
 	}
 
-	if validationErr := validator.ValidateFeedModification(h.store, userID, &feedModificationRequest); validationErr != nil {
+	if validationErr := validator.ValidateFeedModification(h.store, userID, originalFeed.ID, &feedModificationRequest); validationErr != nil {
 		json.BadRequest(w, r, validationErr.Error())
 		return
 	}

+ 1 - 1
internal/ui/feed_update.go

@@ -65,7 +65,7 @@ func (h *handler) updateFeed(w http.ResponseWriter, r *http.Request) {
 		UrlRewriteRules: model.OptionalString(feedForm.UrlRewriteRules),
 	}
 
-	if validationErr := validator.ValidateFeedModification(h.store, loggedUser.ID, feedModificationRequest); validationErr != nil {
+	if validationErr := validator.ValidateFeedModification(h.store, loggedUser.ID, feed.ID, feedModificationRequest); validationErr != nil {
 		view.Set("errorMessage", validationErr.Translate(loggedUser.Language))
 		html.OK(w, r, view.Render("edit_feed"))
 		return

+ 5 - 1
internal/validator/feed.go

@@ -39,7 +39,7 @@ func ValidateFeedCreation(store *storage.Storage, userID int64, request *model.F
 }
 
 // ValidateFeedModification validates feed modification.
-func ValidateFeedModification(store *storage.Storage, userID int64, request *model.FeedModificationRequest) *locale.LocalizedError {
+func ValidateFeedModification(store *storage.Storage, userID, feedID int64, request *model.FeedModificationRequest) *locale.LocalizedError {
 	if request.FeedURL != nil {
 		if *request.FeedURL == "" {
 			return locale.NewLocalizedError("error.feed_url_not_empty")
@@ -48,6 +48,10 @@ func ValidateFeedModification(store *storage.Storage, userID int64, request *mod
 		if !IsValidURL(*request.FeedURL) {
 			return locale.NewLocalizedError("error.invalid_feed_url")
 		}
+
+		if store.AnotherFeedURLExists(userID, feedID, *request.FeedURL) {
+			return locale.NewLocalizedError("error.feed_already_exists")
+		}
 	}
 
 	if request.SiteURL != nil {