Private
Public Access
Make Starred and Saved-for-later pre-configured system tags
UserArticleState.is_starred/is_saved_for_later/starred_at are gone — starring and saving now add/remove an ArticleTag against a per-user "Starred" / "Saved for later" Tag, created lazily on first use and marked Tag.is_system=True. is_read/is_hidden stay on UserArticleState since they're genuine reading state, not categorization, which is what made these two candidates for unifying into the general tag mechanism. System tags are excluded from the Manage Tags page and from delete_tag (get_object_or_404 now requires is_system=False, so attempting to delete one 404s) and from the subscription-tag autocomplete, since they categorize articles, not feeds. The star/save icons are still exactly where they were — this only changes what powers them. apps.rules.engine's star action now does get_system_tag + ArticleTag. get_or_create instead of setting a boolean field. A data migration converts every existing is_starred=True/is_saved_for_later=True row into its ArticleTag equivalent before the fields are dropped — verified by seeding the pre-removal schema directly (including a row with both flags set) and confirming the migration produces the right tags. apps.articles.queries.with_user_state gained one more query (tag lookup for the current page's articles) to stay in the same "fixed number of queries regardless of article count" shape it already had. Verified end to end against a running dev server: toggling star/saved, the starred/saved filters, the sidebar's Favourites count, and that the Starred tag doesn't appear on the Manage Tags page. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0e132e9ab9
commit
753ae9efc7
15 files changed
+267
-82
No files matched your search
@@ -4,12 +4,18 @@ from django.contrib.auth import get_user_model
|
||||
from apps.feeds.models import Feed, Subscription
|
||||
from apps.rules.models import FilterRule
|
||||
|
||||
from .models import Article, SubscriptionTag, Tag, UserArticleState
|
||||
from .models import STARRED_TAG_NAME, Article, ArticleTag, SubscriptionTag, Tag, UserArticleState
|
||||
from .tasks import apply_filter_rules_for_feed
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
|
||||
def is_starred(user, article):
|
||||
return ArticleTag.objects.filter(
|
||||
user=user, article=article, tag__is_system=True, tag__name=STARRED_TAG_NAME
|
||||
).exists()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def feed(db):
|
||||
return Feed.objects.create(feed_url="https://example.com/feed.xml", title="Example Feed")
|
||||
@@ -40,7 +46,7 @@ def test_dispatch_applies_rules_only_for_subscribers_with_matching_rules(feed, a
|
||||
|
||||
apply_filter_rules_for_feed(feed.id, [article.pk])
|
||||
|
||||
assert UserArticleState.objects.get(user=alice, article=article).is_starred is True
|
||||
assert is_starred(alice, article) is True
|
||||
# Bob has no rules, so he should get no state row at all.
|
||||
assert not UserArticleState.objects.filter(user=bob, article=article).exists()
|
||||
|
||||
@@ -67,7 +73,7 @@ def test_feed_scoped_rule_does_not_apply_to_other_feeds(alice):
|
||||
apply_filter_rules_for_feed(feed_a.id, [article_a.pk])
|
||||
apply_filter_rules_for_feed(feed_b.id, [article_b.pk])
|
||||
|
||||
assert UserArticleState.objects.get(user=alice, article=article_a).is_starred is True
|
||||
assert is_starred(alice, article_a) is True
|
||||
assert not UserArticleState.objects.filter(user=alice, article=article_b).exists()
|
||||
|
||||
|
||||
@@ -96,7 +102,7 @@ def test_tag_scoped_rule_only_applies_to_feeds_carrying_that_tag(alice, feed):
|
||||
apply_filter_rules_for_feed(feed.id, [tagged_article.pk])
|
||||
apply_filter_rules_for_feed(other_feed.id, [untagged_article.pk])
|
||||
|
||||
assert UserArticleState.objects.get(user=alice, article=tagged_article).is_starred is True
|
||||
assert is_starred(alice, tagged_article) is True
|
||||
assert not UserArticleState.objects.filter(user=alice, article=untagged_article).exists()
|
||||
|
||||
|
||||
@@ -120,7 +126,7 @@ def test_rule_scoped_to_one_tag_still_applies_to_a_feed_with_multiple_tags(alice
|
||||
|
||||
apply_filter_rules_for_feed(feed.id, [article.pk])
|
||||
|
||||
assert UserArticleState.objects.get(user=alice, article=article).is_starred is True
|
||||
assert is_starred(alice, article) is True
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
|
||||
Reference in new issue
Block a user