mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-02-26 01:09:34 -06:00
Breaking: Removes API v1 and the related serializer (#12166)
This commit is contained in:
@@ -549,28 +549,6 @@ class ColorField(serializers.Field):
|
|||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
class TagSerializerVersion1(MatchingModelSerializer, OwnedObjectSerializer):
|
|
||||||
colour = ColorField(source="color", default="#a6cee3")
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Tag
|
|
||||||
fields = (
|
|
||||||
"id",
|
|
||||||
"slug",
|
|
||||||
"name",
|
|
||||||
"colour",
|
|
||||||
"match",
|
|
||||||
"matching_algorithm",
|
|
||||||
"is_insensitive",
|
|
||||||
"is_inbox_tag",
|
|
||||||
"document_count",
|
|
||||||
"owner",
|
|
||||||
"permissions",
|
|
||||||
"user_can_change",
|
|
||||||
"set_permissions",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class TagSerializer(MatchingModelSerializer, OwnedObjectSerializer):
|
class TagSerializer(MatchingModelSerializer, OwnedObjectSerializer):
|
||||||
def get_text_color(self, obj) -> str:
|
def get_text_color(self, obj) -> str:
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -2419,57 +2419,6 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
|
|||||||
)
|
)
|
||||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED, endpoint)
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED, endpoint)
|
||||||
|
|
||||||
def test_tag_color_default(self) -> None:
|
|
||||||
response = self.client.post("/api/tags/", {"name": "tag"}, format="json")
|
|
||||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
|
||||||
self.assertEqual(Tag.objects.get(id=response.data["id"]).color, "#a6cee3")
|
|
||||||
self.assertEqual(
|
|
||||||
self.client.get(
|
|
||||||
f"/api/tags/{response.data['id']}/",
|
|
||||||
headers={"Accept": "application/json; version=1"},
|
|
||||||
format="json",
|
|
||||||
).data["colour"],
|
|
||||||
1,
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_tag_color(self) -> None:
|
|
||||||
response = self.client.post(
|
|
||||||
"/api/tags/",
|
|
||||||
data={"name": "tag", "colour": 3},
|
|
||||||
headers={"Accept": "application/json; version=1"},
|
|
||||||
format="json",
|
|
||||||
)
|
|
||||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
|
||||||
self.assertEqual(Tag.objects.get(id=response.data["id"]).color, "#b2df8a")
|
|
||||||
self.assertEqual(
|
|
||||||
self.client.get(
|
|
||||||
f"/api/tags/{response.data['id']}/",
|
|
||||||
headers={"Accept": "application/json; version=1"},
|
|
||||||
format="json",
|
|
||||||
).data["colour"],
|
|
||||||
3,
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_tag_color_invalid(self) -> None:
|
|
||||||
response = self.client.post(
|
|
||||||
"/api/tags/",
|
|
||||||
data={"name": "tag", "colour": 34},
|
|
||||||
headers={"Accept": "application/json; version=1"},
|
|
||||||
format="json",
|
|
||||||
)
|
|
||||||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
|
||||||
|
|
||||||
def test_tag_color_custom(self) -> None:
|
|
||||||
tag = Tag.objects.create(name="test", color="#abcdef")
|
|
||||||
self.assertEqual(
|
|
||||||
self.client.get(
|
|
||||||
f"/api/tags/{tag.id}/",
|
|
||||||
headers={"Accept": "application/json; version=1"},
|
|
||||||
format="json",
|
|
||||||
).data["colour"],
|
|
||||||
1,
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_get_existing_notes(self) -> None:
|
def test_get_existing_notes(self) -> None:
|
||||||
"""
|
"""
|
||||||
GIVEN:
|
GIVEN:
|
||||||
|
|||||||
@@ -181,7 +181,6 @@ from documents.serialisers import ShareLinkSerializer
|
|||||||
from documents.serialisers import StoragePathSerializer
|
from documents.serialisers import StoragePathSerializer
|
||||||
from documents.serialisers import StoragePathTestSerializer
|
from documents.serialisers import StoragePathTestSerializer
|
||||||
from documents.serialisers import TagSerializer
|
from documents.serialisers import TagSerializer
|
||||||
from documents.serialisers import TagSerializerVersion1
|
|
||||||
from documents.serialisers import TasksViewSerializer
|
from documents.serialisers import TasksViewSerializer
|
||||||
from documents.serialisers import TrashSerializer
|
from documents.serialisers import TrashSerializer
|
||||||
from documents.serialisers import UiSettingsViewSerializer
|
from documents.serialisers import UiSettingsViewSerializer
|
||||||
@@ -472,6 +471,7 @@ class CorrespondentViewSet(PermissionsAwareDocumentCountMixin, ModelViewSet):
|
|||||||
@extend_schema_view(**generate_object_with_permissions_schema(TagSerializer))
|
@extend_schema_view(**generate_object_with_permissions_schema(TagSerializer))
|
||||||
class TagViewSet(PermissionsAwareDocumentCountMixin, ModelViewSet):
|
class TagViewSet(PermissionsAwareDocumentCountMixin, ModelViewSet):
|
||||||
model = Tag
|
model = Tag
|
||||||
|
serializer_class = TagSerializer
|
||||||
document_count_through = Document.tags.through
|
document_count_through = Document.tags.through
|
||||||
document_count_source_field = "tag_id"
|
document_count_source_field = "tag_id"
|
||||||
|
|
||||||
@@ -479,12 +479,6 @@ class TagViewSet(PermissionsAwareDocumentCountMixin, ModelViewSet):
|
|||||||
Lower("name"),
|
Lower("name"),
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_serializer_class(self, *args, **kwargs):
|
|
||||||
if int(self.request.version) == 1:
|
|
||||||
return TagSerializerVersion1
|
|
||||||
else:
|
|
||||||
return TagSerializer
|
|
||||||
|
|
||||||
pagination_class = StandardPagination
|
pagination_class = StandardPagination
|
||||||
permission_classes = (IsAuthenticated, PaperlessObjectPermissions)
|
permission_classes = (IsAuthenticated, PaperlessObjectPermissions)
|
||||||
filter_backends = (
|
filter_backends = (
|
||||||
|
|||||||
@@ -377,7 +377,7 @@ REST_FRAMEWORK = {
|
|||||||
"DEFAULT_VERSION": "9", # match src-ui/src/environments/environment.prod.ts
|
"DEFAULT_VERSION": "9", # match src-ui/src/environments/environment.prod.ts
|
||||||
# Make sure these are ordered and that the most recent version appears
|
# Make sure these are ordered and that the most recent version appears
|
||||||
# last. See api.md#api-versioning when adding new versions.
|
# last. See api.md#api-versioning when adding new versions.
|
||||||
"ALLOWED_VERSIONS": ["1", "2", "3", "4", "5", "6", "7", "8", "9"],
|
"ALLOWED_VERSIONS": ["2", "3", "4", "5", "6", "7", "8", "9"],
|
||||||
# DRF Spectacular default schema
|
# DRF Spectacular default schema
|
||||||
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
|
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user