Skip to content
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

[SDESK-7441] Create basic async resource models and services for planning.events #2131

Merged
merged 16 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
2 changes: 2 additions & 0 deletions server/planning/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
from planning.planning_locks import init_app as init_planning_locks_app
from planning.search.planning_autocomplete import init_app as init_planning_autocomplete_app

from .module import module # noqa

__version__ = "2.8.2"

_SERVER_PATH = os.path.dirname(os.path.realpath(__file__))
Expand Down
25 changes: 16 additions & 9 deletions server/planning/assignments/assignments.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ def send_assignment_notification(self, updates, original=None, force=False):
event["CLASS"] = "PUBLIC"

# Use Event start and End time based on Config
app = get_current_app()
if app.config.get("ASSIGNMENT_MAIL_ICAL_USE_EVENT_DATES") and event_item:
event_dates = event_item["dates"]
event["DTSTART"] = event_dates["start"].strftime("%Y%m%dT%H%M%SZ")
Expand Down Expand Up @@ -585,9 +586,11 @@ def send_assignment_notification(self, updates, original=None, force=False):
# it is being reassigned by someone else so notify both the new assignee and the old
PlanningNotifications().notify_assignment(
target_user=original.get("assigned_to").get("user"),
target_desk=original.get("assigned_to").get("desk")
if original.get("assigned_to").get("user") is None
else None,
target_desk=(
original.get("assigned_to").get("desk")
if original.get("assigned_to").get("user") is None
else None
),
message="assignment_reassigned_3_msg",
meta_message=meta_msg,
coverage_type=get_coverage_type_name(coverage_type),
Expand Down Expand Up @@ -643,9 +646,11 @@ def send_assignment_notification(self, updates, original=None, force=False):
slugline=slugline,
client_url=client_url,
assignment_id=assignment_id,
assignor="by " + user.get("display_name", "")
if str(user.get(ID_FIELD, None)) != assigned_to.get("user", "")
else "to yourself",
assignor=(
"by " + user.get("display_name", "")
if str(user.get(ID_FIELD, None)) != assigned_to.get("user", "")
else "to yourself"
),
assignment=assignment,
event=event_item,
omit_user=True,
Expand Down Expand Up @@ -768,9 +773,11 @@ def send_assignment_cancellation_notification(
target_user=assigned_to.get("user"),
target_desk=assigned_to.get("desk") if not assigned_to.get("user") else None,
message="assignment_cancelled_desk_msg",
user=user.get("display_name", "Unknown")
if str(user.get(ID_FIELD, None)) != assigned_to.get("user")
else "You",
user=(
user.get("display_name", "Unknown")
if str(user.get(ID_FIELD, None)) != assigned_to.get("user")
else "You"
),
omit_user=True,
slugline=slugline,
desk=desk.get("name"),
Expand Down
4 changes: 2 additions & 2 deletions server/planning/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from collections import namedtuple
from datetime import timedelta, datetime

from superdesk.core import get_app_config
from superdesk.core import get_app_config, get_current_app
from superdesk.resource_fields import ID_FIELD, VERSION
from superdesk.resource import not_analyzed, build_custom_hateoas
from superdesk import get_resource_service, logger
Expand Down Expand Up @@ -248,7 +248,7 @@ def get_default_coverage_status_qcode_on_ingest():


def get_config_planning_duplicate_retain_assignee_details(current_app=None):
return (current_app or app).config.get("PLANNING_DUPLICATE_RETAIN_ASSIGNEE_DETAILS", False)
return (current_app or get_current_app()).config.get("PLANNING_DUPLICATE_RETAIN_ASSIGNEE_DETAILS", False)


def get_coverage_status_from_cv(qcode: str):
Expand Down
3 changes: 3 additions & 0 deletions server/planning/core/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .service import PlanningAsyncResourceService

__all__ = ["PlanningAsyncResourceService"]
12 changes: 12 additions & 0 deletions server/planning/core/service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from typing import Generic, TypeVar

from superdesk.core.resources.service import AsyncResourceService

from planning.types import PlanningResourceModel


PlanningResourceModelType = TypeVar("PlanningResourceModelType", bound=PlanningResourceModel)


class PlanningAsyncResourceService(AsyncResourceService[Generic[PlanningResourceModelType]]):
pass
8 changes: 8 additions & 0 deletions server/planning/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@
)
from planning.autosave import AutosaveService

from .service import EventsAsyncService
from .module import events_resource_config

__all__ = [
"EventsAsyncService",
"events_resource_config",
]


def init_app(app):
"""Initialize events
Expand Down
26 changes: 26 additions & 0 deletions server/planning/events/module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from superdesk.core.resources import (
ResourceConfig,
MongoIndexOptions,
MongoResourceConfig,
ElasticResourceConfig,
)

from planning.events import EventsAsyncService
from planning.types import EventResourceModel

events_resource_config = ResourceConfig(
name="events",
data_class=EventResourceModel,
service=EventsAsyncService,
default_sort=[("dates.start", 1)],
mongo=MongoResourceConfig(
indexes=[
MongoIndexOptions(name="recurrence_id_1", keys=[("recurrence_id", 1)]),
eos87 marked this conversation as resolved.
Show resolved Hide resolved
MongoIndexOptions(name="state", keys=[("state", 1)]),
MongoIndexOptions(name="dates_start_1", keys=[("dates.start", 1)]),
MongoIndexOptions(name="dates_end_1", keys=[("dates.end", 1)]),
MongoIndexOptions(name="template", keys=[("template", 1)]),
],
),
elastic=ElasticResourceConfig(),
)
6 changes: 6 additions & 0 deletions server/planning/events/service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from planning.types import EventResourceModel
from planning.core.service import PlanningAsyncResourceService


class EventsAsyncService(PlanningAsyncResourceService[EventResourceModel]):
resource_name = "events"
8 changes: 8 additions & 0 deletions server/planning/module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from superdesk.core.module import Module
from planning.events import events_resource_config


module = Module(
"planning",
resources=[events_resource_config],
)
4 changes: 4 additions & 0 deletions server/planning/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
from datetime import datetime

from .content_profiles import ContentFieldSchema, ContentFieldEditor, ContentProfile # noqa
from .base import PlanningResourceModel
from .event import EventResourceModel

__all__ = ["PlanningResourceModel", "EventResourceModel"]


UPDATE_METHOD = Literal["single", "future", "all"]
Expand Down
9 changes: 9 additions & 0 deletions server/planning/types/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from typing import Annotated
from superdesk.core.resources import ResourceModel
from superdesk.core.resources.fields import ObjectId
from superdesk.core.resources.validators import validate_data_relation_async


class PlanningResourceModel(ResourceModel):
original_creator: Annotated[ObjectId, validate_data_relation_async("users")] = None
version_creator: Annotated[ObjectId, validate_data_relation_async("users")] = None
Loading
Loading