mirror of
https://github.com/Athou/commafeed.git
synced 2026-09-22 12:04:16 +00:00
prevent users from starring/tagging entries that are not theirs
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user