Skip to content
Merged
Show file tree
Hide file tree
Changes from 97 commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
855a17e
Introduced infra for the mod. events pipeline
vladsha-dev Oct 21, 2024
d18c3cd
Updated clear_opensearch.sh.tpl file
vladsha-dev Oct 21, 2024
ab7e818
Create index mapping and SQL script for the moderation events pipeline
vladsha-dev Oct 25, 2024
af8c7ad
Create empty contributor_name Ruby filter
vladsha-dev Oct 28, 2024
2b66ba6
Merge branch 'main' into OSDEV-1335-deploy-new-moderation-events-logs…
vladsha-dev Oct 28, 2024
43d2105
Create Ruby filters for particular fields, update mapping
vladsha-dev Oct 29, 2024
b867ed8
Delete mock generator
vladsha-dev Oct 29, 2024
6ee98cf
Add moderation-event GET endpoint
VadimKovalenkoSNF Oct 25, 2024
e91fd51
Change moderation_status to status
VadimKovalenkoSNF Oct 25, 2024
78c0b55
Create index mapping and SQL script for the moderation events pipeline
vladsha-dev Oct 25, 2024
3c386a2
Connect moderation-event logstash pipeline
VadimKovalenkoSNF Oct 28, 2024
8a67860
Add moderation-events fixture
VadimKovalenkoSNF Oct 30, 2024
89ec4d2
Merge branch 'main' into OSDEV-1346-implement-get-moderation-events
VadimKovalenkoSNF Oct 30, 2024
868118f
Remove redundant code
VadimKovalenkoSNF Oct 30, 2024
03a4970
Temp commit message
VadimKovalenkoSNF Oct 30, 2024
9837cc8
Add boilerplate for moderation events and production locations query …
VadimKovalenkoSNF Nov 1, 2024
7cccd84
Make query builder methods as protected
VadimKovalenkoSNF Nov 1, 2024
be6e624
Refactor modration-event and producion-locations query builder
VadimKovalenkoSNF Nov 1, 2024
89f0090
Merge branch 'main' into OSDEV-1346-implement-get-moderation-events
VadimKovalenkoSNF Nov 1, 2024
5c2340a
added basic functionality to retrieve method (GET)
roman-stolar Nov 4, 2024
973f048
include url path
roman-stolar Nov 4, 2024
648aa82
add interim changes
VadimKovalenkoSNF Nov 2, 2024
16533fb
Add sorting
VadimKovalenkoSNF Nov 4, 2024
f830242
Merge branch 'OSDEV-1346-implement-get-moderation-events' into OSDEV-…
roman-stolar Nov 4, 2024
f10eb81
Add pagination using from property
VadimKovalenkoSNF Nov 5, 2024
7f393c0
Update moderation status
VadimKovalenkoSNF Nov 5, 2024
90f7fa3
Merge branch 'OSDEV-1346-implement-get-moderation-events' into OSDEV-…
roman-stolar Nov 5, 2024
b73e120
update 401 error response
roman-stolar Nov 5, 2024
0f9f500
More refactoring of moderation status
VadimKovalenkoSNF Nov 5, 2024
fca9271
Update fixture for moderation events
VadimKovalenkoSNF Nov 5, 2024
42c92af
add possibility to query search by moderation_id in opensearch
roman-stolar Nov 5, 2024
2aad50b
Merge branch 'OSDEV-1346-implement-get-moderation-events' into OSDEV-…
roman-stolar Nov 5, 2024
e809df4
Inherit _add_terms method to production locations and moderation-events
VadimKovalenkoSNF Nov 5, 2024
f53f009
Merge branch 'OSDEV-1346-implement-get-moderation-events' into OSDEV-…
roman-stolar Nov 6, 2024
3e07cd8
added uuid validation
roman-stolar Nov 6, 2024
3bae43d
fix linter
roman-stolar Nov 6, 2024
8995a5b
Refactor validators, update index mapping
VadimKovalenkoSNF Nov 6, 2024
bf76754
Merge branch 'main' into OSDEV-1346-implement-get-moderation-events
VadimKovalenkoSNF Nov 6, 2024
4360935
remove useless code
roman-stolar Nov 6, 2024
df6f4d1
Merge branch 'OSDEV-1346-implement-get-moderation-events' into OSDEV-…
roman-stolar Nov 6, 2024
e9bc749
fix
roman-stolar Nov 6, 2024
de66be7
fix
roman-stolar Nov 6, 2024
d47fe6d
fix
roman-stolar Nov 6, 2024
b630f47
Add sorting for cleaned name, address and country
VadimKovalenkoSNF Nov 6, 2024
5bb2ab7
Minor fix
VadimKovalenkoSNF Nov 6, 2024
2a12ae5
add integration test for /api/v1/moderation-events/{moderation_id}
roman-stolar Nov 6, 2024
46bdccc
Merge branch 'OSDEV-1346-implement-get-moderation-events' into OSDEV-…
roman-stolar Nov 6, 2024
aeda7aa
Merge branch 'main' into OSDEV-1346-implement-get-moderation-events
VadimKovalenkoSNF Nov 7, 2024
775ea01
Merge branch 'OSDEV-1346-implement-get-moderation-events' into OSDEV-…
roman-stolar Nov 7, 2024
e0a1e03
fix import path
roman-stolar Nov 7, 2024
0da071e
fix import path
roman-stolar Nov 7, 2024
cf7f528
Minor lint fixes
VadimKovalenkoSNF Nov 8, 2024
55a3365
Merge branch 'OSDEV-1346-implement-get-moderation-events' into OSDEV-…
roman-stolar Nov 8, 2024
f32a0ea
fix linter
roman-stolar Nov 8, 2024
f8e52b8
Remove serializers for os_id and contributor_id
VadimKovalenkoSNF Nov 8, 2024
0fab438
Merge branch 'OSDEV-1346-implement-get-moderation-events' into OSDEV-…
roman-stolar Nov 11, 2024
ae4f0f6
Add integration tests (partial impl)
VadimKovalenkoSNF Nov 11, 2024
0b60f49
Add base integration tests
VadimKovalenkoSNF Nov 11, 2024
2034e0c
Add integration tests and auth check
VadimKovalenkoSNF Nov 12, 2024
d1d63d9
Merge branch 'main' into OSDEV-1346-implement-get-moderation-events
VadimKovalenkoSNF Nov 12, 2024
3e6a83f
Update release notes
VadimKovalenkoSNF Nov 12, 2024
69301d0
Create new migration for moderation event table
VadimKovalenkoSNF Nov 12, 2024
b93efc6
Update release notes
VadimKovalenkoSNF Nov 12, 2024
227aa5f
Fix minor reivew issues
VadimKovalenkoSNF Nov 12, 2024
0c63b0f
Minor lint fix
VadimKovalenkoSNF Nov 12, 2024
271ebde
Merge branch 'OSDEV-1346-implement-get-moderation-events' into OSDEV-…
roman-stolar Nov 12, 2024
66ff008
Update types
VadimKovalenkoSNF Nov 12, 2024
40a3023
Minor lint fixes
VadimKovalenkoSNF Nov 12, 2024
86bc01c
Integration test fix
VadimKovalenkoSNF Nov 12, 2024
4cbd2c2
Minor fix of integration test
VadimKovalenkoSNF Nov 12, 2024
11129de
Remove TODOs and link them to OSDEV-1441
VadimKovalenkoSNF Nov 12, 2024
150e988
Revert recent changes
VadimKovalenkoSNF Nov 12, 2024
e42a443
Minor fixes to check pipeline
VadimKovalenkoSNF Nov 12, 2024
86c01ca
Rename test for opensearch query builder
VadimKovalenkoSNF Nov 12, 2024
bf896a6
Fix django import
VadimKovalenkoSNF Nov 12, 2024
ffdeeca
Remove django model import from integrational test
VadimKovalenkoSNF Nov 12, 2024
69c9474
Merge branch 'main' into OSDEV-1346-implement-get-moderation-events
VadimKovalenkoSNF Nov 12, 2024
a5d6963
Rename TestOpenSearchQueryBuilder to TestProductionLocationsQueryBuilder
VadimKovalenkoSNF Nov 12, 2024
b46ae8a
Add unit tests for moderation-events query builder
VadimKovalenkoSNF Nov 13, 2024
ca99fda
Refactor track_total_hits property
VadimKovalenkoSNF Nov 13, 2024
2f92ac3
Update moderation_id validation
VadimKovalenkoSNF Nov 13, 2024
0aeaab3
Fix lint issues
VadimKovalenkoSNF Nov 13, 2024
ad2e941
Update error msg for moderation ids validation
VadimKovalenkoSNF Nov 13, 2024
65354d7
Merge branch 'OSDEV-1346-implement-get-moderation-events' into OSDEV-…
roman-stolar Nov 13, 2024
1f057e2
Minor fix for integration test
VadimKovalenkoSNF Nov 13, 2024
aa8203b
Minor improve for integration test
VadimKovalenkoSNF Nov 13, 2024
bfa05d2
Merge branch 'OSDEV-1346-implement-get-moderation-events' into OSDEV-…
roman-stolar Nov 13, 2024
d48b8b6
Fix version in release notes
VadimKovalenkoSNF Nov 14, 2024
17ff064
Refactor _build_date_range method
VadimKovalenkoSNF Nov 14, 2024
87da165
Make __build_number_of_workers as private in ProductionLocationsQuery…
VadimKovalenkoSNF Nov 14, 2024
9adb9c9
Refactor OpenSearch query builder inheritance
VadimKovalenkoSNF Nov 14, 2024
c22e1fb
Inherit OpenSearchValidationInterface fron ABC
VadimKovalenkoSNF Nov 14, 2024
ec3b9c0
Merge branch 'OSDEV-1346-implement-get-moderation-events' into OSDEV-…
roman-stolar Nov 14, 2024
73ab54a
updated Release Notes
roman-stolar Nov 14, 2024
32bb09c
Merge branch 'main' into OSDEV-1347-implement-get-moderation-event-by-id
roman-stolar Nov 14, 2024
5e9da3a
addressed Vadim comment
roman-stolar Nov 14, 2024
d009821
refactored
roman-stolar Nov 14, 2024
f7d65c1
fix linter
roman-stolar Nov 14, 2024
0551943
Merge branch 'main' into OSDEV-1347-implement-get-moderation-event-by-id
roman-stolar Nov 15, 2024
f287ed1
fix patch request and prepared same naming
roman-stolar Nov 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/release/RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html

### Code/API changes
* [OSDEV-1346](https://opensupplyhub.atlassian.net/browse/OSDEV-1346) - Create GET request for `v1/moderation-events` endpoint.
* [OSDEV-1347](https://opensupplyhub.atlassian.net/browse/OSDEV-1347) - Create GET request for `v1/moderation-events/{moderation_id}` endpoint.

### Architecture/Environment changes
* *Describe architecture/environment changes here.*
Expand Down
26 changes: 25 additions & 1 deletion src/django/api/views/v1/moderation_events.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from django.http import QueryDict
from rest_framework import status
from rest_framework.viewsets import ViewSet
from rest_framework.response import Response
from api.views.v1.utils import (
serialize_params,
handle_errors_decorator
handle_errors_decorator,
handle_path_error
)
from api.permissions import IsRegisteredAndConfirmed
from api.services.opensearch.search import OpenSearchService
Expand All @@ -13,6 +15,8 @@
import OpenSearchQueryDirector
from api.serializers.v1.moderation_events_serializer \
import ModerationEventsSerializer
from api.serializers.v1.opensearch_common_validators.moderation_id_validator \
import ModerationIdValidator
from api.views.v1.index_names import OpenSearchIndexNames


Expand Down Expand Up @@ -49,3 +53,23 @@ def list(self, request):
query_body
)
return Response(response)

@handle_errors_decorator
def retrieve(self, _, pk=None):
if not ModerationIdValidator.is_valid_uuid(pk):
return handle_path_error(
field="moderation_id",
message="Invalid UUID format.",
status_code=status.HTTP_400_BAD_REQUEST
)

query_params = QueryDict('', mutable=True)
query_params.update({'moderation_id': pk})
query_body = self.opensearch_query_director.build_query(
query_params
)
response = self.opensearch_service.search_index(
OpenSearchIndexNames.MODERATION_EVENTS_INDEX,
query_body
)
return Response(response)
16 changes: 16 additions & 0 deletions src/django/api/views/v1/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import uuid
import logging
from functools import wraps
from rest_framework.response import Response
Expand Down Expand Up @@ -108,3 +109,18 @@ def _wrapped_view(self, request, *args, **kwargs):
except OpenSearchServiceException as e:
return handle_opensearch_exception(e)
return _wrapped_view


def handle_path_error(field, message, status_code):
return Response(
{
"message": "The request path parameter is invalid.",
"errors": [
{
"field": field,
"message": message
}
]
},
status=status_code
)
5 changes: 5 additions & 0 deletions src/django/oar/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@
ProductionLocations.as_view({'get': 'retrieve'}),
name='production-locations-details'
),
path(
'api/v1/moderation-events/<str:moderation_id>/',
ModerationEvents.as_view({'get': 'retrieve'}),
name='moderation-events-details'
),
]

schema_view = get_schema_view(
Expand Down
20 changes: 20 additions & 0 deletions src/tests/v1/test_moderation_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@

class ModerationEventsTest(BaseAPITest):

def test_moderation_events_exact(self):
moderation_id_wrong = '0f35a90f-70a0-4c3e-8e06-2ed8e1fc6800'
response = requests.get(
f"{self.root_url}/api/v1/moderation-events/{moderation_id_wrong}",
headers=self.basic_headers,
)

result = response.json()
self.assertEqual(result['count'], 0)

moderation_id = '1f35a90f-70a0-4c3e-8e06-2ed8e1fc6800'
response = requests.get(
f"{self.root_url}/api/v1/moderation-events/{moderation_id}",
headers=self.basic_headers,
)

result = response.json()
self.assertEqual(result['count'], 1)
self.assertEqual(result['data'][0]['moderation_id'], moderation_id)

def test_moderation_events_status(self):
response = requests.get(
f"{self.root_url}/api/v1/moderation-events/",
Expand Down