prevent users from starring/tagging entries that are not theirs

This commit is contained in:
Athou
2026-08-22 08:09:28 +02:00
parent d2aaddea33
commit 43588df2b4
11 changed files with 20 additions and 31 deletions

View File

@@ -98,15 +98,14 @@ public class FeedEntryService {
}
}
public void starEntry(User user, Long entryId, Long subscriptionId, boolean starred) {
FeedSubscription sub = feedSubscriptionDAO.findById(user, subscriptionId);
if (sub == null) {
public void starEntry(User user, Long entryId, boolean starred) {
FeedEntry entry = feedEntryDAO.findById(entryId);
if (entry == null) {
return;
}
FeedEntry entry = feedEntryDAO.findById(entryId);
if (entry == null) {
FeedSubscription sub = feedSubscriptionDAO.findByFeed(user, entry.getFeed());
if (sub == null) {
return;
}

View File

@@ -2,8 +2,10 @@ package com.commafeed.backend.service;
import com.commafeed.backend.dao.FeedEntryDAO;
import com.commafeed.backend.dao.FeedEntryTagDAO;
import com.commafeed.backend.dao.FeedSubscriptionDAO;
import com.commafeed.backend.model.FeedEntry;
import com.commafeed.backend.model.FeedEntryTag;
import com.commafeed.backend.model.FeedSubscription;
import com.commafeed.backend.model.User;
import jakarta.inject.Singleton;
@@ -20,6 +22,7 @@ public class FeedEntryTagService {
private final FeedEntryDAO feedEntryDAO;
private final FeedEntryTagDAO feedEntryTagDAO;
private final FeedSubscriptionDAO feedSubscriptionDAO;
public void updateTags(User user, Long entryId, List<String> tagNames) {
FeedEntry entry = feedEntryDAO.findById(entryId);
@@ -27,6 +30,11 @@ public class FeedEntryTagService {
return;
}
FeedSubscription sub = feedSubscriptionDAO.findByFeed(user, entry.getFeed());
if (sub == null) {
return;
}
List<FeedEntryTag> existingTags = feedEntryTagDAO.findByEntry(user, entry);
Set<String> existingTagNames =
existingTags.stream().map(FeedEntryTag::getName).collect(Collectors.toSet());

View File

@@ -19,9 +19,6 @@ public class StarRequest implements Serializable {
@Size(max = 128)
private String id;
@Schema(description = "feed id", required = true)
private Long feedId;
@Schema(description = "starred or not", required = true)
private boolean starred;
}

View File

@@ -89,11 +89,9 @@ public class EntryREST {
@Valid @Parameter(description = "Star Request", required = true) StarRequest req) {
Preconditions.checkNotNull(req);
Preconditions.checkNotNull(req.getId());
Preconditions.checkNotNull(req.getFeedId());
User user = authenticationContext.getCurrentUser();
feedEntryService.starEntry(
user, Long.valueOf(req.getId()), req.getFeedId(), req.isStarred());
feedEntryService.starEntry(user, Long.valueOf(req.getId()), req.isStarred());
return Response.ok().build();
}

View File

@@ -388,9 +388,7 @@ public class FeverREST {
if ("read".equals(action) || "unread".equals(action)) {
feedEntryService.markEntry(user, id, "read".equals(action));
} else if ("saved".equals(action) || "unsaved".equals(action)) {
FeedEntry entry = feedEntryDAO.findById(id);
FeedSubscription sub = feedSubscriptionDAO.findByFeed(user, entry.getFeed());
feedEntryService.starEntry(user, id, sub.getId(), "saved".equals(action));
feedEntryService.starEntry(user, id, "saved".equals(action));
}
} else if ("feed".equals(source)) {
FeedSubscription subscription = feedSubscriptionDAO.findById(user, id);

View File

@@ -402,16 +402,11 @@ public class GoogleReaderREST {
if (markUnread) {
feedEntryService.markEntry(user, entryId, false);
}
if (star || unstar) {
FeedSubscription sub = feedSubscriptionDAO.findByFeed(user, entry.getFeed());
if (sub != null) {
if (star) {
feedEntryService.starEntry(user, entryId, sub.getId(), true);
}
if (unstar) {
feedEntryService.starEntry(user, entryId, sub.getId(), false);
}
}
if (star) {
feedEntryService.starEntry(user, entryId, true);
}
if (unstar) {
feedEntryService.starEntry(user, entryId, false);
}
}

View File

@@ -45,7 +45,6 @@ class DatabaseCleaningIT extends BaseIT {
private void starEntry(String entryId, Long subscriptionId) {
StarRequest starRequest = new StarRequest();
starRequest.setId(entryId);
starRequest.setFeedId(subscriptionId);
starRequest.setStarred(true);
RestAssured.given()
.body(starRequest)
@@ -58,7 +57,6 @@ class DatabaseCleaningIT extends BaseIT {
private void unstarEntry(String entryId, Long subscriptionId) {
StarRequest starRequest = new StarRequest();
starRequest.setId(entryId);
starRequest.setFeedId(subscriptionId);
starRequest.setStarred(false);
RestAssured.given()
.body(starRequest)

View File

@@ -240,7 +240,6 @@ class CategoryIT extends BaseIT {
StarRequest starRequest = new StarRequest();
starRequest.setId(entry.getId());
starRequest.setFeedId(subscriptionId);
starRequest.setStarred(true);
RestAssured.given()
.body(starRequest)

View File

@@ -121,7 +121,6 @@ class FeverIT extends BaseIT {
StarRequest starRequest = new StarRequest();
starRequest.setId(entry.getId());
starRequest.setFeedId(subscriptionId);
starRequest.setStarred(true);
RestAssured.given().body(starRequest).contentType(ContentType.JSON).post("rest/entry/star");