-
Notifications
You must be signed in to change notification settings - Fork 9
[OSDEV-1332] Moderation. Implement PATCH api/v1/moderation-events/{moderation_id} #393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
roman-stolar
merged 128 commits into
main
from
OSDEV-1332-implement-patch-moderation-event
Nov 15, 2024
Merged
Changes from all commits
Commits
Show all changes
128 commits
Select commit
Hold shift + click to select a range
855a17e
Introduced infra for the mod. events pipeline
vladsha-dev d18c3cd
Updated clear_opensearch.sh.tpl file
vladsha-dev 5d7461a
Add moderation-event GET endpoint
VadimKovalenkoSNF b74225e
Change moderation_status to status
VadimKovalenkoSNF ab7e818
Create index mapping and SQL script for the moderation events pipeline
vladsha-dev 3dd3929
Create index mapping and SQL script for the moderation events pipeline
vladsha-dev af8c7ad
Create empty contributor_name Ruby filter
vladsha-dev 2cdb941
Create empty contributor_name Ruby filter
vladsha-dev 2b66ba6
Merge branch 'main' into OSDEV-1335-deploy-new-moderation-events-logs…
vladsha-dev ca574c5
Connect moderation-event logstash pipeline
VadimKovalenkoSNF d7ed97a
WIP
roman-stolar 2bfd293
WIP
roman-stolar f10edfd
WIP
roman-stolar 43d2105
Create Ruby filters for particular fields, update mapping
vladsha-dev b867ed8
Delete mock generator
vladsha-dev 6ee98cf
Add moderation-event GET endpoint
VadimKovalenkoSNF e91fd51
Change moderation_status to status
VadimKovalenkoSNF 78c0b55
Create index mapping and SQL script for the moderation events pipeline
vladsha-dev 3c386a2
Connect moderation-event logstash pipeline
VadimKovalenkoSNF 0105c91
update error handling and provide 202 response data
roman-stolar 378fa7e
Merge branch 'OSDEV-1346-implement-get-moderation-events' into OSDEV-…
roman-stolar 2491919
fix
roman-stolar 048db32
fix linter errors
roman-stolar b281e82
fix
roman-stolar c781d48
fix
roman-stolar e4db5c2
add custom fields to serializer
roman-stolar d370a2c
fix status code
roman-stolar 8b48814
allow null in response for few fields
roman-stolar 34ba7ce
update errors response format
roman-stolar 8a67860
Add moderation-events fixture
VadimKovalenkoSNF 89ec4d2
Merge branch 'main' into OSDEV-1346-implement-get-moderation-events
VadimKovalenkoSNF 868118f
Remove redundant code
VadimKovalenkoSNF ff68d9b
Merge branch 'OSDEV-1346-implement-get-moderation-events' into OSDEV-…
roman-stolar 03a4970
Temp commit message
VadimKovalenkoSNF 22b3caa
Wrote initial test
roman-stolar 7507867
covered different test cases for endpoint
roman-stolar f07ae4f
fix linter
roman-stolar 359758c
fix
roman-stolar 33f54c7
update error message
roman-stolar e5fd105
removed redundant comments
roman-stolar b8bd00f
prepare method as private
roman-stolar 473fafb
Updated RELEASE-NOTES
roman-stolar 1d71cd9
fix linter
roman-stolar 9472bc4
fix linter error
roman-stolar 9837cc8
Add boilerplate for moderation events and production locations query …
VadimKovalenkoSNF 7cccd84
Make query builder methods as protected
VadimKovalenkoSNF e329437
Merge branch 'OSDEV-1346-implement-get-moderation-events' into OSDEV-…
roman-stolar be6e624
Refactor modration-event and producion-locations query builder
VadimKovalenkoSNF b8a7b00
addressed coderabbit comments
roman-stolar 950dae6
one more fix
roman-stolar cd771cf
remove logger
roman-stolar 89f0090
Merge branch 'main' into OSDEV-1346-implement-get-moderation-events
VadimKovalenkoSNF 0493dff
fix
roman-stolar f57c5b8
Merge branch 'OSDEV-1346-implement-get-moderation-events' into OSDEV-…
roman-stolar 3b87e91
addressed Vlad comment
roman-stolar 5fce52c
update error message
roman-stolar e95cc6b
addressed Olek comment
roman-stolar 648aa82
add interim changes
VadimKovalenkoSNF 16533fb
Add sorting
VadimKovalenkoSNF bbf9c90
updated status choices
roman-stolar df87af2
Merge branch 'OSDEV-1346-implement-get-moderation-events' into OSDEV-…
roman-stolar f10eb81
Add pagination using from property
VadimKovalenkoSNF 7f393c0
Update moderation status
VadimKovalenkoSNF 2942919
fix tests
roman-stolar d5b21c1
Merge branch 'OSDEV-1346-implement-get-moderation-events' into OSDEV-…
roman-stolar 5ae88c1
fix tests
roman-stolar 0f9f500
More refactoring of moderation status
VadimKovalenkoSNF fca9271
Update fixture for moderation events
VadimKovalenkoSNF 0003c80
Merge branch 'OSDEV-1346-implement-get-moderation-events' into OSDEV-…
roman-stolar e809df4
Inherit _add_terms method to production locations and moderation-events
VadimKovalenkoSNF 1e797e7
Merge branch 'OSDEV-1346-implement-get-moderation-events' into OSDEV-…
roman-stolar 31aceaf
linter fix
roman-stolar 8995a5b
Refactor validators, update index mapping
VadimKovalenkoSNF bf76754
Merge branch 'main' into OSDEV-1346-implement-get-moderation-events
VadimKovalenkoSNF 00c7dd6
Merge branch 'OSDEV-1346-implement-get-moderation-events' into OSDEV-…
roman-stolar b630f47
Add sorting for cleaned name, address and country
VadimKovalenkoSNF 5bb2ab7
Minor fix
VadimKovalenkoSNF 5f4ea0d
Merge branch 'OSDEV-1346-implement-get-moderation-events' into OSDEV-…
roman-stolar aeda7aa
Merge branch 'main' into OSDEV-1346-implement-get-moderation-events
VadimKovalenkoSNF bfe2759
Merge branch 'OSDEV-1346-implement-get-moderation-events' into OSDEV-…
roman-stolar 00ac5fa
fix import path
roman-stolar 28f5518
fix import path
roman-stolar cf7f528
Minor lint fixes
VadimKovalenkoSNF 94e6bf4
Merge branch 'OSDEV-1346-implement-get-moderation-events' into OSDEV-…
roman-stolar c45c39a
fix linter
roman-stolar f8e52b8
Remove serializers for os_id and contributor_id
VadimKovalenkoSNF 0a26b2e
Merge branch 'OSDEV-1346-implement-get-moderation-events' into OSDEV-…
roman-stolar ae4f0f6
Add integration tests (partial impl)
VadimKovalenkoSNF 0b60f49
Add base integration tests
VadimKovalenkoSNF 2034e0c
Add integration tests and auth check
VadimKovalenkoSNF d1d63d9
Merge branch 'main' into OSDEV-1346-implement-get-moderation-events
VadimKovalenkoSNF 3e6a83f
Update release notes
VadimKovalenkoSNF 69301d0
Create new migration for moderation event table
VadimKovalenkoSNF b93efc6
Update release notes
VadimKovalenkoSNF 227aa5f
Fix minor reivew issues
VadimKovalenkoSNF 0c63b0f
Minor lint fix
VadimKovalenkoSNF 31f9979
Merge branch 'OSDEV-1346-implement-get-moderation-events' into OSDEV-…
roman-stolar 66ff008
Update types
VadimKovalenkoSNF 40a3023
Minor lint fixes
VadimKovalenkoSNF 86bc01c
Integration test fix
VadimKovalenkoSNF 4cbd2c2
Minor fix of integration test
VadimKovalenkoSNF 11129de
Remove TODOs and link them to OSDEV-1441
VadimKovalenkoSNF 150e988
Revert recent changes
VadimKovalenkoSNF e42a443
Minor fixes to check pipeline
VadimKovalenkoSNF 86c01ca
Rename test for opensearch query builder
VadimKovalenkoSNF bf896a6
Fix django import
VadimKovalenkoSNF ffdeeca
Remove django model import from integrational test
VadimKovalenkoSNF 69c9474
Merge branch 'main' into OSDEV-1346-implement-get-moderation-events
VadimKovalenkoSNF a5d6963
Rename TestOpenSearchQueryBuilder to TestProductionLocationsQueryBuilder
VadimKovalenkoSNF b46ae8a
Add unit tests for moderation-events query builder
VadimKovalenkoSNF ca99fda
Refactor track_total_hits property
VadimKovalenkoSNF 2f92ac3
Update moderation_id validation
VadimKovalenkoSNF 0aeaab3
Fix lint issues
VadimKovalenkoSNF ad2e941
Update error msg for moderation ids validation
VadimKovalenkoSNF 5e58354
Merge branch 'OSDEV-1346-implement-get-moderation-events' into OSDEV-…
roman-stolar 1f057e2
Minor fix for integration test
VadimKovalenkoSNF aa8203b
Minor improve for integration test
VadimKovalenkoSNF 254e1bc
Merge branch 'OSDEV-1346-implement-get-moderation-events' into OSDEV-…
roman-stolar d48b8b6
Fix version in release notes
VadimKovalenkoSNF 17ff064
Refactor _build_date_range method
VadimKovalenkoSNF 87da165
Make __build_number_of_workers as private in ProductionLocationsQuery…
VadimKovalenkoSNF 9adb9c9
Refactor OpenSearch query builder inheritance
VadimKovalenkoSNF c22e1fb
Inherit OpenSearchValidationInterface fron ABC
VadimKovalenkoSNF f3347cf
Merge branch 'OSDEV-1346-implement-get-moderation-events' into OSDEV-…
roman-stolar d6a577d
move the task to release 1.25.0
roman-stolar 5660a23
Merge branch 'main' into OSDEV-1332-implement-patch-moderation-event
roman-stolar 0b64e17
refactor
roman-stolar 1b32dd7
fix linter
roman-stolar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/django/api/serializers/v1/moderation_event_update_serializer.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| from rest_framework.serializers import ( | ||
| ModelSerializer, | ||
| ValidationError, | ||
| CharField, | ||
| IntegerField | ||
| ) | ||
| from api.models.moderation_event \ | ||
| import ModerationEvent | ||
| from django.utils.timezone import now | ||
|
|
||
|
|
||
| class ModerationEventUpdateSerializer(ModelSerializer): | ||
|
|
||
| contributor_id = IntegerField(source='contributor.id', read_only=True) | ||
| contributor_name = CharField(source='contributor.name', read_only=True) | ||
| os_id = IntegerField(source='os.id', read_only=True, allow_null=True) | ||
| claim_id = IntegerField(source='claim.id', read_only=True, allow_null=True) | ||
|
|
||
| class Meta: | ||
| model = ModerationEvent | ||
| fields = [ | ||
| 'uuid', | ||
| 'created_at', | ||
| 'updated_at', | ||
| 'os_id', | ||
| 'contributor_id', | ||
| 'contributor_name', | ||
| 'cleaned_data', | ||
| 'request_type', | ||
| 'source', | ||
| 'status', | ||
| 'status_change_date', | ||
| 'claim_id' | ||
| ] | ||
|
|
||
| def to_internal_value(self, data): | ||
| status = data.get('status') | ||
|
|
||
| if status is None: | ||
| raise ValidationError({ | ||
| "field": "status", | ||
| "message": "This field is required." | ||
| }) | ||
|
|
||
| self.__validate_status(status) | ||
| return super().to_internal_value(data) | ||
|
|
||
| def __validate_status(self, value): | ||
| if value not in [ | ||
| ModerationEvent.Status.PENDING, | ||
| ModerationEvent.Status.APPROVED, | ||
| ModerationEvent.Status.REJECTED | ||
| ]: | ||
| raise ValidationError({ | ||
| "field": "status", | ||
| "message": ( | ||
| "Moderation status must be one of " | ||
| "PENDING, APPROVED or REJECTED." | ||
| ) | ||
| }) | ||
| return value | ||
roman-stolar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def update(self, instance, validated_data): | ||
| if 'status' in validated_data: | ||
| value = validated_data['status'] | ||
| instance.status = value | ||
| instance.status_change_date = now() | ||
|
|
||
| instance.save() | ||
| return instance | ||
roman-stolar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| import json | ||
| from django.test import override_settings | ||
| from api.models import ( | ||
| ModerationEvent, | ||
| User, | ||
| Contributor | ||
| ) | ||
| from django.utils.timezone import now | ||
| from rest_framework.test import APITestCase | ||
|
|
||
|
|
||
| @override_settings(DEBUG=True) | ||
| class ModerationEventsUpdateTest(APITestCase): | ||
| def setUp(self): | ||
| super().setUp() | ||
|
|
||
| self.email = "test@example.com" | ||
| self.password = "example123" | ||
| self.user = User.objects.create(email=self.email) | ||
| self.user.set_password(self.password) | ||
| self.user.save() | ||
|
|
||
| self.contributor = Contributor.objects.create( | ||
| admin=self.user, | ||
| name="test contributor", | ||
| contrib_type=Contributor.OTHER_CONTRIB_TYPE, | ||
| ) | ||
|
|
||
| self.superemail = "admin@example.com" | ||
| self.superpassword = "example123" | ||
| self.superuser = User.objects.create_superuser( | ||
| email=self.superemail, | ||
| password=self.superpassword | ||
| ) | ||
|
|
||
| self.moderation_event = ModerationEvent.objects.create( | ||
| uuid='f65ec710-f7b9-4f50-b960-135a7ab24ee6', | ||
| created_at=now(), | ||
| updated_at=now(), | ||
| request_type='UPDATE', | ||
| raw_data={"name": "raw_name", "country_code": "UK"}, | ||
| cleaned_data={"name": "cleaned_name", "country_code": "UK"}, | ||
| geocode_result={"latitude": -53, "longitude": 142}, | ||
| status='PENDING', | ||
| source='API', | ||
| contributor=self.contributor | ||
| ) | ||
|
|
||
| def test_moderation_event_permission(self): | ||
| self.client.login( | ||
| email=self.email, | ||
| password=self.password | ||
| ) | ||
| response = self.client.patch( | ||
| "/api/v1/moderation-events/{}/" | ||
| .format("f65ec710-f7b9-4f50-b960-135a7ab24ee6"), | ||
| data=json.dumps({"status": "APPROVED"}), | ||
| content_type="application/json" | ||
| ) | ||
| self.assertEqual(403, response.status_code) | ||
|
|
||
| self.client.login( | ||
| email=self.superemail, | ||
| password=self.superpassword | ||
| ) | ||
| response = self.client.patch( | ||
| "/api/v1/moderation-events/{}/" | ||
| .format("f65ec710-f7b9-4f50-b960-135a7ab24ee6"), | ||
| data=json.dumps({"status": "APPROVED"}), | ||
| content_type="application/json" | ||
| ) | ||
| print(response.json()) | ||
| self.assertEqual(200, response.status_code) | ||
|
|
||
| def test_moderation_event_not_found(self): | ||
| self.client.login( | ||
| email=self.superemail, | ||
| password=self.superpassword | ||
| ) | ||
| response = self.client.patch( | ||
| "/api/v1/moderation-events/{}/" | ||
| .format("f65ec710-f7b9-4f50-b960-135a7ab24ee1"), | ||
| data=json.dumps({"status": "APPROVED"}), | ||
| content_type="application/json" | ||
| ) | ||
|
|
||
| self.assertEqual(404, response.status_code) | ||
|
|
||
| def test_moderation_event_invalid_status(self): | ||
| self.client.login( | ||
| email=self.superemail, | ||
| password=self.superpassword | ||
| ) | ||
| response = self.client.patch( | ||
| "/api/v1/moderation-events/{}/" | ||
| .format("f65ec710-f7b9-4f50-b960-135a7ab24ee6"), | ||
| data=json.dumps({"status": "NEW"}), | ||
| content_type="application/json" | ||
| ) | ||
|
|
||
| self.assertEqual(400, response.status_code) | ||
|
|
||
| def test_moderation_event_status_changed(self): | ||
| self.client.login( | ||
| email=self.superemail, | ||
| password=self.superpassword | ||
| ) | ||
| response = self.client.patch( | ||
| "/api/v1/moderation-events/{}/" | ||
| .format("f65ec710-f7b9-4f50-b960-135a7ab24ee6"), | ||
| data=json.dumps({"status": "APPROVED"}), | ||
| content_type="application/json" | ||
| ) | ||
|
|
||
| self.assertEqual(200, response.status_code) | ||
| self.moderation_event.refresh_from_db() | ||
| self.assertEqual(self.moderation_event.status, "APPROVED") | ||
| self.assertIsNotNone(self.moderation_event.status_change_date) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.