diff --git a/requirements.txt b/requirements.txt index cb448e22dfbc13d7249411d6d00bb177ebe88078..503b5822388b8a898f664c6fed855a14178f1289 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -r requirements_base.txt -nacsos_data[utils,scripts] @ git+ssh://git@gitlab.pik-potsdam.de/mcc-apsis/nacsos/nacsos-data.git@v0.17.0 \ No newline at end of file +nacsos_data[utils,scripts] @ git+ssh://git@gitlab.pik-potsdam.de/mcc-apsis/nacsos/nacsos-data.git@v0.17.1 \ No newline at end of file diff --git a/server/api/routes/mailing.py b/server/api/routes/mailing.py index db33ed65e265e2cbecebaa1571364bed4aec8a1c..81405458984727a6a38937549d34ac9da8df17bc 100644 --- a/server/api/routes/mailing.py +++ b/server/api/routes/mailing.py @@ -1,4 +1,4 @@ -from fastapi import APIRouter, Depends, BackgroundTasks +from fastapi import APIRouter, Depends, BackgroundTasks, Body from fastapi.responses import PlainTextResponse from nacsos_data.util.errors import NotFoundError @@ -135,7 +135,7 @@ async def remind_users_assigment(assignment_scope_id: str, reminded_users = [] for res in result: if res['num_open'] > 0: - logger.debug(f'Trying to remind {res}') + logger.info(f'Trying to remind {res}') background_tasks.add_task( send_message, sender=None, @@ -163,21 +163,27 @@ async def remind_users_assigment(assignment_scope_id: str, @router.post('/news') -async def news_mail(subject: str, - body: str, - background_tasks: BackgroundTasks, +async def news_mail(background_tasks: BackgroundTasks, + subject: str = Body(), + body: str = Body(), + is_active: bool | None = None, + is_subscribed: bool | None = None, superuser: UserModel = Depends(get_current_active_superuser)) -> list[str]: reminded_users: list[str] = [] session: AsyncSession async with db_engine.session() as session: - users = (await session.execute(select(User.email, User.full_name, User.username) - .where(User.setting_newsletter is True, # type: ignore[arg-type] - User.is_active is True))).mappings().all() # type: ignore[arg-type] + stmt = select(User.email, User.full_name, User.username) + if is_active is not None: + stmt = stmt.where(User.is_active == is_active) + if is_subscribed: + stmt = stmt.where(User.setting_newsletter == is_subscribed) + + users = (await session.execute(stmt)).mappings().all() # type: ignore[arg-type] for user in users: try: - logger.debug(f'Trying to remind {user["username"]}') + logger.info(f'Trying to send news to {user["username"]}') background_tasks.add_task( send_message, sender=None,