Skip to content

Commit

Permalink
Change the bulk annotation date filter to updated instead of created
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospri committed Oct 20, 2023
1 parent c263c94 commit d40a674
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
10 changes: 5 additions & 5 deletions h/services/bulk_annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def annotation_search(
self,
authority: str,
audience: dict,
updated: dict,
created: dict,
limit=100000,
) -> List[BulkAnnotation]:
"""
Expand All @@ -86,15 +86,15 @@ def annotation_search(
:param authority: The authority to search by
:param audience: A specification of how to find the users. e.g.
{"username": [...]}
:param updated: A specification of how to filter the updated date. e.g.
:param created: A specification of how to filter the created date. e.g.
{"gt": "2019-01-20", "lte": "2019-01-21"}
:param limit: A limit of results to generate
:raises BadDateFilter: For poorly specified date conditions
"""

results = self._db.execute(
self._search_query(authority, audience=audience, updated=updated).limit(
self._search_query(authority, audience=audience, created=created).limit(
limit
)
)
Expand All @@ -107,15 +107,15 @@ def annotation_search(
]

@classmethod
def _search_query(cls, authority, audience, updated) -> Select:
def _search_query(cls, authority, audience, created) -> Select:
"""Generate a query which can then be executed to find annotations."""
return (
sa.select([cls._AUTHOR.username, Group.authority_provided_id])
.select_from(AnnotationSlim)
.join(cls._AUTHOR, cls._AUTHOR.id == AnnotationSlim.user_id)
.join(Group, Group.id == AnnotationSlim.group_id)
.where(
date_match(AnnotationSlim.updated, updated),
date_match(AnnotationSlim.created, created),
AnnotationSlim.shared.is_(True),
AnnotationSlim.deleted.is_(False),
cls._AUTHOR.nipsa.is_(False),
Expand Down
4 changes: 2 additions & 2 deletions h/views/api/bulk/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ def bulk_annotation(request):
# is limited to items they have permission to request
authority=request.identity.auth_client.authority,
audience=query_filter["audience"],
updated=query_filter["updated"],
created=query_filter["created"],
limit=query_filter["limit"],
)

except BadDateFilter as err:
# We happen to know this is the updated field, because there's no other
# We happen to know this is the created field, because there's no other
# but, it could easily be something else in the future
raise ValidationError(str(err)) from err

Expand Down
6 changes: 3 additions & 3 deletions h/views/api/bulk/annotation_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"audience": {
"username": ["3a022b6c146dfd9df4ea8662178eac"]
},
"updated": {
"created": {
"gt": "2018-11-13T20:20:39+00:00",
"lte": "2018-11-13T20:20:39+00:00"
}
Expand All @@ -34,9 +34,9 @@
"properties": {
"limit": {"type": "integer", "minimum": 0, "maximum": 1000000},
"audience": {"$ref": "#/$defs/userFilter"},
"updated": {"$ref": "#/$defs/dateFilter"}
"created": {"$ref": "#/$defs/dateFilter"}
},
"required": ["limit", "audience", "updated"],
"required": ["limit", "audience", "created"],
"additionalProperties": false
},

Expand Down
4 changes: 2 additions & 2 deletions tests/functional/api/bulk/annotation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ def test_it_accepts_a_valid_request(self, make_request, factories):
group=group,
shared=True,
deleted=False,
updated="2018-11-13T20:20:39",
created="2018-11-13T20:20:39",
)

response = make_request(
{
"filter": {
"limit": 20,
"audience": {"username": [user.username]},
"updated": {
"created": {
"gt": "2018-11-12T20:20:39+00:00",
"lte": "2018-11-13T20:20:39+00:00",
},
Expand Down
16 changes: 8 additions & 8 deletions tests/h/services/bulk_annotation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ class TestBulkAnnotationService:
("deleted", True, False),
("nipsad", True, False),
("moderated", True, False),
("updated", "2020-01-01", False),
("updated", "2020-01-02", True),
("updated", "2022-01-01", True),
("updated", "2022-01-02", False),
("created", "2020-01-01", False),
("created", "2020-01-02", True),
("created", "2022-01-01", True),
("created", "2022-01-02", False),
),
)
@pytest.mark.parametrize("username", ["USERNAME", "username", "user.name"])
Expand All @@ -82,7 +82,7 @@ def test_it_with_single_annotation(
"deleted": False,
"nipsad": False,
"moderated": False,
"updated": "2021-01-01",
"created": "2021-01-01",
}
if key:
values[key] = value
Expand All @@ -97,14 +97,14 @@ def test_it_with_single_annotation(
group=group,
shared=values["shared"],
deleted=values["deleted"],
updated=values["updated"],
created=values["created"],
moderated=values["moderated"],
)

annotations = svc.annotation_search(
authority=self.AUTHORITY,
audience={"username": ["USERNAME"]},
updated={"gt": "2020-01-01", "lte": "2022-01-01"},
created={"gt": "2020-01-01", "lte": "2022-01-01"},
)

if visible:
Expand Down Expand Up @@ -140,7 +140,7 @@ def test_it_with_more_complex_grouping(self, svc, factories):
matched_annos = svc.annotation_search(
authority=self.AUTHORITY,
audience={"username": [viewer.username for viewer in viewers]},
updated={"gt": "2020-01-01", "lte": "2099-01-01"},
created={"gt": "2020-01-01", "lte": "2099-01-01"},
)

# Only the first two annotations should match
Expand Down
4 changes: 2 additions & 2 deletions tests/h/views/api/bulk/annotation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_it(
authority=pyramid_request.identity.auth_client.authority,
audience=valid_request["filter"]["audience"],
limit=valid_request["filter"]["limit"],
updated=valid_request["filter"]["updated"],
created=valid_request["filter"]["created"],
)

return_data = [
Expand Down Expand Up @@ -82,7 +82,7 @@ def valid_request(self, pyramid_request):
"filter": {
"limit": 2000,
"audience": {"username": ["3a022b6c146dfd9df4ea8662178eac"]},
"updated": {
"created": {
"gt": "2018-11-13T20:20:39+00:00",
"lte": "2018-11-13T20:20:39+00:00",
},
Expand Down

0 comments on commit d40a674

Please sign in to comment.