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

[NHUB-566] Migrate public Blueprint to an EndpointGroup #1126

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 8 additions & 5 deletions newsroom/public/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
from superdesk.flask import Blueprint, render_template
from superdesk.core.app import SuperdeskAsyncApp
from superdesk.core.module import Module
from superdesk.flask import render_template
from newsroom.gettext import get_session_locale
from newsroom.email import get_language_template_name

blueprint = Blueprint("public", __name__)
from .views import public_endpoints

from . import views # noqa

def init_module(app: SuperdeskAsyncApp):
app.wsgi.add_template_global(render_restricted_action_modal_body)

def init_app(app):
app.add_template_global(render_restricted_action_modal_body)

module = Module(name="newsroom.public", init=init_module, endpoints=[public_endpoints])


async def render_restricted_action_modal_body():
Expand Down
20 changes: 14 additions & 6 deletions newsroom/public/views.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from typing import List, Dict

from pydantic import BaseModel
from werkzeug.utils import secure_filename

from superdesk.core import get_current_app, get_app_config
from superdesk.flask import render_template
from superdesk.core.web import EndpointGroup
from superdesk.core import get_current_app, get_app_config

from newsroom.auth.utils import is_valid_session
from newsroom.types import Article, DashboardCardDict
from newsroom.public import blueprint
from newsroom.wire.items import get_items_for_dashboard
from newsroom.ui_config_async import UiConfigResourceService
from newsroom.users import get_user_profile_data
Expand All @@ -17,6 +18,8 @@
PUBLIC_DASHBOARD_CARDS_CACHE_KEY = "public-dashboard-cards"
PUBLIC_DASHBOARD_ITEMS_CACHE_KEY = "public-dashboard-items"

public_endpoints = EndpointGroup("public", __name__)


async def get_public_dashboard_config():
app = get_current_app().as_any()
Expand Down Expand Up @@ -54,9 +57,14 @@ async def get_public_cards() -> List[DashboardCardDict]:
return cards


@blueprint.route("/page/<path:template>")
async def page(template):
return await render_template("page-{template}.html".format(template=secure_filename(template)))
class PageArgs(BaseModel):
template: str


@public_endpoints.endpoint("/page/<path:template>")
async def page(args: PageArgs, _p: None, _r: None):
template = secure_filename(args.template)
return await render_template(f"page-{template}.html")


async def render_public_dashboard():
Expand All @@ -73,7 +81,7 @@ async def render_public_dashboard():
)


@blueprint.route("/public/card_items")
@public_endpoints.endpoint("/public/card_items")
async def public_card_items():
if not await is_valid_session() and not get_app_config("PUBLIC_DASHBOARD"):
return {"_items": []}
Expand Down
3 changes: 1 addition & 2 deletions newsroom/web/default_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@
"newsroom.design",
"newsroom.products",
"newsroom.reports",
"newsroom.public",
"newsroom.agenda",
"newsroom.news_api.api_tokens",
"newsroom.monitoring",
Expand All @@ -143,7 +142,6 @@
"newsroom.products",
"newsroom.section_filters",
"newsroom.reports",
"newsroom.public",
"newsroom.agenda",
"newsroom.photos",
"newsroom.media_utils",
Expand Down Expand Up @@ -178,6 +176,7 @@
"newsroom.topics_folders",
"newsroom.push",
"newsroom.history_async",
"newsroom.public",
]

SITE_NAME = "Newshub"
Expand Down
Loading