Skip to content

Commit

Permalink
Add /unskip/by-uuid endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
duogenesis committed Jan 25, 2025
1 parent f123273 commit ec6b875
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 263 deletions.
7 changes: 6 additions & 1 deletion service/application/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def get_prospect_profile(s: t.SessionInfo, prospect_uuid: int):
@apost('/skip/by-uuid/<prospect_uuid>')
@validate(t.PostSkip)
def post_skip_by_uuid(req: t.PostSkip, s: t.SessionInfo, prospect_uuid: int):
limit = "1 per 30 seconds"
limit = "1 per 5 seconds; 30 per day"
scope = "report"

if req.report_reason:
Expand All @@ -299,10 +299,15 @@ def post_skip_by_uuid(req: t.PostSkip, s: t.SessionInfo, prospect_uuid: int):
else:
return person.post_skip_by_uuid(req, s, prospect_uuid)

# TODO: Delete
@apost('/unskip/<int:prospect_person_id>')
def post_unskip(s: t.SessionInfo, prospect_person_id: int):
return person.post_unskip(s, prospect_person_id)

@apost('/unskip/by-uuid/<prospect_uuid>')
def post_unskip(s: t.SessionInfo, prospect_person_id: int):
return person.post_unskip_by_uuid(s, prospect_person_id)

@aget(
'/compare-personalities'
'/<int:prospect_person_id>'
Expand Down
9 changes: 9 additions & 0 deletions service/person/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,15 @@ def post_unskip(s: t.SessionInfo, prospect_person_id: int):
with api_tx() as tx:
tx.execute(Q_DELETE_SKIPPED, params)

def post_unskip_by_uuid(s: t.SessionInfo, prospect_uuid: str):
params = dict(
subject_person_id=s.person_id,
prospect_uuid=prospect_uuid,
)

with api_tx() as tx:
tx.execute(Q_DELETE_SKIPPED_BY_UUID, params)

def get_compare_personalities(
s: t.SessionInfo,
prospect_person_id: int,
Expand Down
13 changes: 13 additions & 0 deletions service/person/sql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,19 @@
object_person_id = %(object_person_id)s
"""

Q_DELETE_SKIPPED_BY_UUID = """
DELETE FROM
skipped
USING
person
WHERE
person.id = skipped.object_person_id
AND
person.uuid = uuid_or_null(%(prospect_uuid)s)
AND
subject_person_id = %(subject_person_id)s
"""

Q_ANSWER_COMPARISON = """
WITH prospect_name AS(
SELECT name FROM person WHERE id = %(prospect_person_id)s
Expand Down
8 changes: 4 additions & 4 deletions test/functionality1/search.sh
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ test_quiz_search () {
[[ "$response3" != "${user2_id}" ]]

echo "Reset searcher's search cache"
c POST "/unskip/${user2_id}"
c POST "/unskip/by-uuid/${user2_uuid}"
c GET '/search?n=1&o=0'

echo user2 has the highest match percentage but searcher is skipped by user2
Expand All @@ -253,7 +253,7 @@ test_quiz_search () {

echo "Reset searcher's search cache"
assume_role user2
c POST "/unskip/${searcher_id}"
c POST "/unskip/by-uuid/${searcher_uuid}"
assume_role searcher
c GET '/search?n=1&o=0'

Expand Down Expand Up @@ -471,7 +471,7 @@ test_interaction_in_standard_search_skipped () {

assert_search_names 'user2'

c POST "/unskip/${user1_id}"
c POST "/unskip/by-uuid/${user1_uuid}"

assert_search_names 'user1 user2'
}
Expand Down Expand Up @@ -881,7 +881,7 @@ test_quiz_search
test_hide_me_from_strangers
test_verified_privacy

test_interaction_in_standard_search_skipped /skip/by-uuid /unskip
test_interaction_in_standard_search_skipped
test_interaction_in_standard_search_skipped_symmetry

test_quiz_filters
Expand Down
6 changes: 3 additions & 3 deletions test/functionality3/rate-limiting.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ printf 1 > ../../test/input/disable-account-rate-limit

echo Only the global rate limit should apply for regular skips
c POST "/skip/by-uuid/${user2uuid}"
c POST "/unskip/${user2id}"
c POST "/unskip/by-uuid/${user2uuid}"
c POST "/skip/by-uuid/${user2uuid}"

echo The stricter rate limit should apply for reports
jc POST "/skip/by-uuid/${user2uuid}" -d '{ "report_reason": "smells bad" }'
c POST "/unskip/${user2id}"
c POST "/unskip/by-uuid/${user2uuid}"
! jc POST "/skip/by-uuid/${user2uuid}" -d '{ "report_reason": "bad hair" }'

echo Uncached search should be heavily rate-limited
Expand Down Expand Up @@ -61,7 +61,7 @@ done
echo Account-based rate limit should apply even if the IP address changes
printf 1 > ../../test/input/disable-ip-rate-limit
printf 0 > ../../test/input/disable-account-rate-limit
for x in {1..10}
for x in {1..5}
do
printf "256.256.256.${x}" > ../../test/input/mock-ip-address
c GET '/search?n=1&o=0'
Expand Down
255 changes: 0 additions & 255 deletions todo-endpoints.txt

This file was deleted.

0 comments on commit ec6b875

Please sign in to comment.