Skip to content

Commit

Permalink
Exclude pending friends from within-friends search (#1483)
Browse files Browse the repository at this point in the history
Fixes #1482

Reviewed-by: Charmander <[email protected]>
  • Loading branch information
charmander authored Dec 3, 2024
2 parents de3e03c + f3b3151 commit 2b1ce02
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
5 changes: 3 additions & 2 deletions weasyl/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,9 @@ def _find_without_media(userid, rating, limit,
elif within == "friend":
# Search within friends content
statement_from.append(
"INNER JOIN frienduser ON (frienduser.userid, frienduser.otherid) = (%(userid)s, content.userid)"
" OR (frienduser.userid, frienduser.otherid) = (content.userid, %(userid)s)")
"INNER JOIN frienduser ON ((frienduser.userid, frienduser.otherid) = (%(userid)s, content.userid)"
" OR (frienduser.userid, frienduser.otherid) = (content.userid, %(userid)s))"
" AND frienduser.settings !~ 'p'")
elif within == "follow":
# Search within following content
statement_from.append(
Expand Down
38 changes: 38 additions & 0 deletions weasyl/test/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,41 @@ def test_user_search_ordering(db):

results = search.select_users("user")
assert [user["title"] for user in results] == ["user_aa", "user_Ab", "user_ba", "user_Bb"]


def test_search_within_friends(db):
def _select(userid: int):
results, _, _ = search.select(
search=search.Query.parse("ferret", "submit"),
userid=userid, rating=ratings.GENERAL.code, limit=100,
cat=None, subcat=None, within="friend", backid=None, nextid=None,
)

return results

config = CharSettings({}, {}, {})
config_pending = CharSettings({"pending"}, {}, {})

user1_id = db_utils.create_user("user1", username="user1", config=config)
user2_id = db_utils.create_user("user2", username="user2", config=config)

tag_id = db_utils.create_tag("ferret")

submission1_id = db_utils.create_submission(user1_id, rating=ratings.GENERAL.code)
db_utils.create_submission_tag(tag_id, submission1_id)

submission2_id = db_utils.create_submission(user2_id, rating=ratings.GENERAL.code)
db_utils.create_submission_tag(tag_id, submission2_id)

assert len(_select(user1_id)) == 0
assert len(_select(user2_id)) == 0

db_utils.create_friendship(user1_id, user2_id, config_pending)

assert len(_select(user1_id)) == 0
assert len(_select(user2_id)) == 0

db_utils.create_friendship(user2_id, user1_id, config)

assert len(_select(user1_id)) == 1
assert len(_select(user1_id)) == 1

0 comments on commit 2b1ce02

Please sign in to comment.