Browse Source

Fix user topic tag filters ignoring descendants

Previously, user topic tag filters weren't also filtering out any
"descendant" tags when they were hierarchical. For example, setting a
filter on "ask" wouldn't also filter out "ask.survey". This fixes that
behavior, though it's a bit awkward and maybe could be done better
somehow.
merge-requests/37/head
Deimos 6 years ago
parent
commit
c06016536c
  1. 8
      tildes/tildes/views/topic.py

8
tildes/tildes/views/topic.py

@ -11,7 +11,8 @@ from marshmallow.fields import String
from pyramid.httpexceptions import HTTPFound from pyramid.httpexceptions import HTTPFound
from pyramid.request import Request from pyramid.request import Request
from pyramid.view import view_config from pyramid.view import view_config
from sqlalchemy.sql.expression import desc
from sqlalchemy import cast
from sqlalchemy.sql.expression import any_, desc
from sqlalchemy_utils import Ltree from sqlalchemy_utils import Ltree
from webargs.pyramidparser import use_kwargs from webargs.pyramidparser import use_kwargs
from zope.sqlalchemy import mark_changed from zope.sqlalchemy import mark_changed
@ -23,6 +24,7 @@ from tildes.enums import (
LogEventType, LogEventType,
TopicSortOption, TopicSortOption,
) )
from tildes.lib.database import ArrayOfLtree
from tildes.lib.datetime import SimpleHoursPeriod from tildes.lib.datetime import SimpleHoursPeriod
from tildes.models.comment import Comment, CommentNotification, CommentTree from tildes.models.comment import Comment, CommentNotification, CommentTree
from tildes.models.group import Group from tildes.models.group import Group
@ -142,7 +144,9 @@ def get_group_topics(
if not (tag or unfiltered): if not (tag or unfiltered):
# pylint: disable=protected-access # pylint: disable=protected-access
query = query.filter( query = query.filter(
~Topic._tags.overlap(request.user._filtered_topic_tags) # type: ignore
~Topic._tags.descendant_of( # type: ignore
any_(cast(request.user._filtered_topic_tags, ArrayOfLtree))
)
) )
topics = query.get_page(per_page) topics = query.get_page(per_page)

Loading…
Cancel
Save