Skip to content

Commit

Permalink
♻️ [#2269] Do not show completed items in userfeed
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenbal committed Mar 26, 2024
1 parent 2b59330 commit 6013720
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/open_inwoner/cms/plugins/cms_plugins/userfeed.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class UserFeedPlugin(CMSPluginBase):

def render(self, context, instance, placeholder):
request = context["request"]
feed = get_feed(request.user, with_history=True)
feed = get_feed(request.user)
context.update(
{
"instance": instance,
Expand Down
10 changes: 1 addition & 9 deletions src/open_inwoner/userfeed/feed.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import dataclasses
from collections.abc import Iterable
from datetime import timedelta

from django.db.models import Q
from django.utils import timezone
from django.utils.html import escape, format_html

from open_inwoner.accounts.models import User
Expand All @@ -17,8 +15,6 @@
from open_inwoner.userfeed.models import FeedItemData
from open_inwoner.userfeed.summarize import SUMMARIES

ACTION_COMPLETED_HISTORY_RANGE = timedelta(minutes=10)


@dataclasses.dataclass()
class Feed:
Expand All @@ -44,7 +40,7 @@ def wrap_items(items: Iterable[FeedItemData]) -> Iterable[FeedItem]:
yield get_item_adapter_class(item.type)(item)


def get_feed(user: User, with_history: bool = False) -> Feed:
def get_feed(user: User) -> Feed:
if not user or user.is_anonymous:
# empty feed
return Feed()
Expand All @@ -53,10 +49,6 @@ def get_feed(user: User, with_history: bool = False) -> Feed:

# core filters
display_filter = Q(completed_at__isnull=True)
if with_history:
display_filter |= Q(
completed_at__gt=timezone.now() - ACTION_COMPLETED_HISTORY_RANGE
)

data_items = FeedItemData.objects.filter(
display_filter,
Expand Down
17 changes: 2 additions & 15 deletions src/open_inwoner/userfeed/tests/test_feed.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
from django.test import TestCase
from django.utils import timezone
from django.utils.html import strip_tags
from django.utils.translation import ngettext

from freezegun import freeze_time

from open_inwoner.accounts.tests.factories import UserFactory
from open_inwoner.openzaak.constants import StatusIndicators
from open_inwoner.userfeed.choices import FeedItemType
from open_inwoner.userfeed.feed import ACTION_COMPLETED_HISTORY_RANGE, get_feed
from open_inwoner.userfeed.feed import get_feed
from open_inwoner.userfeed.hooks.common import simple_message
from open_inwoner.userfeed.models import FeedItemData
from open_inwoner.userfeed.tests.factories import FeedItemDataFactory
Expand Down Expand Up @@ -52,20 +49,10 @@ def test_get_feed__and__simple_message(self):
).format(count=1)
self.assertEqual(strip_tags(summary), expected)

# forward in time past range
with freeze_time(timezone.now() + ACTION_COMPLETED_HISTORY_RANGE):
# not completed so still visible in the future
feed = get_feed(self.user, with_history=True)
self.assertEqual(feed.total_items, 1)

# mark as completed
item.mark_completed()
self.assertEqual(item.is_completed, True)

# not visible, neither now nor in the future
# not visible anymore
feed = get_feed(self.user)
self.assertEqual(feed.total_items, 0)

with freeze_time(timezone.now() + ACTION_COMPLETED_HISTORY_RANGE):
feed = get_feed(self.user, with_history=True)
self.assertEqual(feed.total_items, 0)

0 comments on commit 6013720

Please sign in to comment.