Skip to content

Commit d6f4c24

Browse files
committed
Merge remote-tracking branch 'origin/async' into hg/SDESK-7484-content-api-token-auth
2 parents eb24905 + c39fc7c commit d6f4c24

File tree

7 files changed

+567
-3
lines changed

7 files changed

+567
-3
lines changed

superdesk/default_settings.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,12 @@ def local_to_utc_hour(hour):
418418
#:
419419
#: ..versionadded: 3.0.0
420420
#:
421-
MODULES = ["superdesk.users", "apps.desks_async", "superdesk.publish.subscriber_token"]
421+
MODULES = [
422+
"superdesk.users",
423+
"apps.desks_async",
424+
"superdesk.vocabularies_async",
425+
"superdesk.publish.subscriber_token"
426+
]
422427

423428
ASYNC_AUTH_CLASS = "superdesk.core.auth.token_auth:TokenAuthorization"
424429

superdesk/types/__init__.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
from typing import TypedDict, Dict, Any, List
1+
from typing import Any, Dict, List, TypedDict
2+
23
from .desks import DesksResourceModel
34
from .users import UsersResourceModel
5+
from .vocabularies import VocabulariesResourceModel
46

5-
__all__ = ["UsersResourceModel", "DesksResourceModel"]
7+
__all__ = ["UsersResourceModel", "DesksResourceModel", "VocabulariesResourceModel"]
68

79

810
class WebsocketMessageFilterConditions(TypedDict, total=False):

superdesk/types/vocabularies.py

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# -*- coding: utf-8; -*-
2+
#
3+
# This file is part of Superdesk.
4+
#
5+
# Copyright 2013, 2025 Sourcefabric z.u. and contributors.
6+
#
7+
# For the full copyright and license information, please see the
8+
# AUTHORS and LICENSE files distributed with this source code, or
9+
# at https://www.sourcefabric.org/superdesk/license
10+
11+
12+
from enum import Enum, unique
13+
import logging
14+
from typing import Annotated, Any
15+
16+
from pydantic import BaseModel, ConfigDict, Field
17+
from quart_babel import gettext as _
18+
19+
from superdesk.core.resources import ResourceModel
20+
from superdesk.core.resources.model import Dataclass, ResourceModel
21+
from superdesk.core.resources.validators import validate_maxlength
22+
23+
logger = logging.getLogger(__name__)
24+
25+
26+
class Tag(Dataclass):
27+
text: str
28+
29+
30+
class Item(BaseModel):
31+
name: str
32+
qcode: str
33+
is_active: bool = True
34+
35+
36+
class DateShortcut(Dataclass):
37+
value: int
38+
term: str
39+
label: str
40+
41+
42+
class CustomFieldConfig(Dataclass):
43+
increment_steps: list[int]
44+
initial_offset_minutes: int
45+
46+
47+
@unique
48+
class CVAccessType(str, Enum):
49+
MANAGEABLE = "manageable"
50+
UNMANAGEABLE = "unmanageable"
51+
52+
53+
@unique
54+
class SelectionType(str, Enum):
55+
SINGLE_SELECTION = "single selection"
56+
MULTI_SELECTION = "multi selection"
57+
DO_NOT_SHOW = "do not show"
58+
59+
60+
class VocabulariesResourceModel(ResourceModel):
61+
display_name: str
62+
description: str | None = None
63+
helper_text: Annotated[str | None, validate_maxlength(120)] = None
64+
tags: list[Tag] | None = None
65+
popup_width: int | None = None
66+
management_type: Annotated[CVAccessType, Field(alias="type")]
67+
items: list[Item]
68+
selection_type: SelectionType | None = None
69+
read_only: bool | None = None
70+
schema_field: str | None = None
71+
dependent: bool = False
72+
service: dict[str, int] = Field(default_factory=dict)
73+
priority: int = 0
74+
unique_field: str | None = None
75+
schema: dict[str, dict]
76+
field_type_: str | None = None
77+
field_options_: dict[str, Any] = Field(default_factory=dict)
78+
init_version: int = 0
79+
preffered_items: bool = False
80+
disable_entire_category_selection: bool = False
81+
date_shortcuts: list[DateShortcut] | None = None
82+
custom_field_type: str | None = None
83+
custom_field_config: CustomFieldConfig | None = None
84+
translations: dict[str, dict[str, Any]] = Field(default_factory=dict)

superdesk/vocabularies/vocabularies.py

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151

5252

5353
class VocabulariesResource(Resource):
54+
internal_resource = True
5455
schema = {
5556
"_id": {
5657
"type": "string",
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from superdesk.core.module import Module
2+
from .service import VocabulariesService
3+
from .module import vocabularies_resource_config
4+
5+
__all__ = ["VocabulariesService"]
6+
7+
module = Module(name="superdesk.vocabularies_async", resources=[vocabularies_resource_config])
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# -*- coding: utf-8; -*-
2+
#
3+
# This file is part of Superdesk.
4+
#
5+
# Copyright 2013, 2025 Sourcefabric z.u. and contributors.
6+
#
7+
# For the full copyright and license information, please see the
8+
# AUTHORS and LICENSE files distributed with this source code, or
9+
# at https://www.sourcefabric.org/superdesk/license
10+
11+
from superdesk.core.resources import ResourceConfig, MongoResourceConfig, MongoIndexOptions
12+
from superdesk.core.resources.resource_rest_endpoints import RestEndpointConfig
13+
from superdesk.types import VocabulariesResourceModel
14+
from .service import VocabulariesService
15+
16+
17+
vocabularies_resource_config = ResourceConfig(
18+
name="vocabularies",
19+
data_class=VocabulariesResourceModel,
20+
service=VocabulariesService,
21+
mongo=MongoResourceConfig(
22+
indexes=[
23+
MongoIndexOptions(
24+
name="field_type",
25+
keys=[("field_type", 1)],
26+
),
27+
],
28+
),
29+
rest_endpoints=RestEndpointConfig(
30+
item_methods=["GET", "PATCH", "DELETE"],
31+
resource_methods=["GET", "POST"],
32+
enable_cors=True,
33+
),
34+
)

0 commit comments

Comments
 (0)