Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions pkg/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,11 @@ func (s *Server) AddCatalogHandler(db *database.Catalog) {

updated, err := db.UpdateRating(r.Context(), user, &rating)
if err != nil {
s.writeJSONErrorResponse(w, r, err, http.StatusBadRequest)
if errors.Is(err, database.ErrGlobalOperationNotPermitted) {
s.writeJSONErrorResponse(w, r, err, http.StatusForbidden)
} else {
s.writeJSONErrorResponse(w, r, err, http.StatusBadRequest)
}
return
}

Expand Down Expand Up @@ -902,7 +906,11 @@ func (s *Server) AddCatalogHandler(db *database.Catalog) {

err := db.DeleteRatings(r.Context(), user)
if err != nil {
s.writeJSONErrorResponse(w, r, err, http.StatusBadRequest)
if errors.Is(err, database.ErrGlobalOperationNotPermitted) {
s.writeJSONErrorResponse(w, r, err, http.StatusForbidden)
} else {
s.writeJSONErrorResponse(w, r, err, http.StatusBadRequest)
}
return
}

Expand All @@ -924,7 +932,11 @@ func (s *Server) AddCatalogHandler(db *database.Catalog) {

err = db.DeleteRating(r.Context(), user, idParam)
if err != nil {
s.writeJSONErrorResponse(w, r, err, http.StatusBadRequest)
if errors.Is(err, database.ErrGlobalOperationNotPermitted) {
s.writeJSONErrorResponse(w, r, err, http.StatusForbidden)
} else {
s.writeJSONErrorResponse(w, r, err, http.StatusBadRequest)
}
return
}

Expand Down
15 changes: 14 additions & 1 deletion pkg/web/src/routes/login/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,23 @@
}

async function deleteRatings() {
await fetch(`${PUBLIC_BACKEND_ENDPOINT}/api/ratings`, {
const res = await fetch(`${PUBLIC_BACKEND_ENDPOINT}/api/ratings`, {
method: 'DELETE',
credentials: 'same-origin'
});

if (!res.ok) {
if (res.status === 403) {
const json = await res.json();
alert('Cannot clear ratings: The default user is not allowed to delete ratings. Please create your own user account.');
} else if (res.status === 401) {
alert('You need to be logged in to clear ratings.');
} else {
alert('Failed to clear ratings: ' + res.statusText);
}
return;
}

location.reload();
}

Expand Down