-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SDESK-7470] - Create new async Agenda resource, service & REST API (#…
…2172) * Create resource model for agenda resource * Create new async resource service for agendas * Create resource config for agenda with REST API * Register the resource config with the planning module * Disable web endpoints in old agenda resource * Suggested fixes * Suggested fixes * Black reformat
- Loading branch information
1 parent
45668fb
commit f7d2619
Showing
8 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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,4 @@ | ||
from .agendas_async_service import AgendasAsyncService | ||
from .module import agendas_resource_config | ||
|
||
__all__ = ["AgendasAsyncService", "agendas_resource_config"] |
This file contains 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,51 @@ | ||
from typing import Any | ||
from planning.core.service import BasePlanningAsyncService | ||
from planning.types import AgendasResourceModel | ||
from apps.auth import get_user_id | ||
from superdesk import get_resource_service | ||
from superdesk.errors import SuperdeskApiError | ||
from superdesk.notification import push_notification | ||
|
||
|
||
class AgendasAsyncService(BasePlanningAsyncService[AgendasResourceModel]): | ||
# TODO-ASYNC: on_fetched mechanism to be added to the base REST API class | ||
# async def _generate_planning_info(self, docs): | ||
# # TODO-ASYNC: Change this when get_planning_by_agenda_id is added to utils | ||
# planning_service = get_resource_service("planning") | ||
# for doc in docs: | ||
# doc["plannings"] = planning_service.get_planning_by_agenda_id(doc.get(ID_FIELD)).docs | ||
# | ||
# async def on_fetched(self, docs): | ||
# await self._generate_planning_info(docs.get(ITEMS)) | ||
# | ||
# async def on_fetched_item(self, doc): | ||
# await self._generate_planning_info([doc]) | ||
|
||
async def on_created(self, docs: list[AgendasResourceModel]) -> None: | ||
for doc in docs: | ||
push_notification( | ||
"agenda:created", item=str(doc.id), user=str(doc.original_creator) if doc.original_creator else None | ||
) | ||
|
||
async def on_update(self, updates: dict[str, Any], original: AgendasResourceModel) -> None: | ||
user_id = get_user_id() | ||
if user_id: | ||
updates["version_creator"] = get_user_id() | ||
|
||
async def on_updated(self, updates: dict[str, Any], original: AgendasResourceModel) -> None: | ||
# await self._generate_planning_info([updates]) | ||
push_notification( | ||
"agenda:updated", | ||
item=str(original.id), | ||
user=str(updates.get("version_creator", "")), | ||
) | ||
|
||
async def on_delete(self, doc: AgendasResourceModel): | ||
# TODO-ASYNC: Change this when get_planning_by_agenda_id is added to utils | ||
if get_resource_service("planning").get_planning_by_agenda_id(doc.id).count() > 0: | ||
raise SuperdeskApiError.badRequestError( | ||
message="Agenda is referenced by Planning items. " "Cannot delete Agenda" | ||
) | ||
|
||
async def on_deleted(self, doc: AgendasResourceModel): | ||
push_notification("agenda:deleted", item=str(doc.id)) |
This file contains 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,14 @@ | ||
from superdesk.core.resources import ( | ||
ResourceConfig, | ||
RestEndpointConfig, | ||
) | ||
|
||
from .agendas_async_service import AgendasAsyncService | ||
from planning.types import AgendasResourceModel | ||
|
||
agendas_resource_config = ResourceConfig( | ||
name="agenda", | ||
data_class=AgendasResourceModel, | ||
service=AgendasAsyncService, | ||
rest_endpoints=RestEndpointConfig(resource_methods=["GET", "POST"], item_methods=["GET", "PATCH", "DELETE"]), | ||
) |
This file contains 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 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 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 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,10 @@ | ||
from typing import Annotated | ||
|
||
from .base import BasePlanningModel | ||
from superdesk.core.resources import fields | ||
from superdesk.core.resources.validators import validate_iunique_value_async | ||
|
||
|
||
class AgendasResourceModel(BasePlanningModel): | ||
name: Annotated[fields.Keyword, validate_iunique_value_async("agendas", "name")] | ||
is_enabled: bool = True |