forked from Archives/Athou_commafeed
make sure the user owns the modified data
This commit is contained in:
@@ -100,6 +100,16 @@ public class FeedSubscriptionService extends GenericDAO<FeedSubscription> {
|
||||
return criteria.getResultList();
|
||||
}
|
||||
|
||||
public List<FeedSubscription> findByCategory(User user,
|
||||
FeedCategory category) {
|
||||
EasyCriteria<FeedSubscription> criteria = EasyCriteriaFactory
|
||||
.createQueryCriteria(em, getType());
|
||||
criteria.andEquals(MF.i(proxy().getUser()), user);
|
||||
criteria.andEquals(MF.i(proxy().getCategory()), category);
|
||||
return criteria.getResultList();
|
||||
|
||||
}
|
||||
|
||||
public List<FeedSubscription> findWithoutCategories(User user) {
|
||||
EasyCriteria<FeedSubscription> criteria = EasyCriteriaFactory
|
||||
.createQueryCriteria(em, getType());
|
||||
|
||||
@@ -81,8 +81,14 @@ public class SubscriptionsREST extends AbstractREST {
|
||||
@GET
|
||||
@Path("unsubscribe")
|
||||
public Response unsubscribe(@QueryParam("id") Long subscriptionId) {
|
||||
feedSubscriptionService.deleteById(subscriptionId);
|
||||
return Response.ok(Status.OK).build();
|
||||
FeedSubscription sub = feedSubscriptionService.findById(getUser(),
|
||||
subscriptionId);
|
||||
if (sub != null) {
|
||||
feedSubscriptionService.delete(sub);
|
||||
return Response.ok(Status.OK).build();
|
||||
} else {
|
||||
return Response.status(Status.NOT_FOUND).build();
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -137,8 +143,19 @@ public class SubscriptionsREST extends AbstractREST {
|
||||
@GET
|
||||
@Path("deleteCategory")
|
||||
public Response deleteCategory(@QueryParam("id") Long id) {
|
||||
feedCategoryService.deleteById(id);
|
||||
return Response.ok().build();
|
||||
FeedCategory cat = feedCategoryService.findById(getUser(), id);
|
||||
if (cat != null) {
|
||||
List<FeedSubscription> subs = feedSubscriptionService
|
||||
.findByCategory(getUser(), cat);
|
||||
for (FeedSubscription sub : subs) {
|
||||
sub.setCategory(null);
|
||||
}
|
||||
feedSubscriptionService.update(subs);
|
||||
feedCategoryService.delete(cat);
|
||||
return Response.ok().build();
|
||||
} else {
|
||||
return Response.status(Status.NOT_FOUND).build();
|
||||
}
|
||||
}
|
||||
|
||||
@POST
|
||||
|
||||
Reference in New Issue
Block a user