Skip to content

Commit

Permalink
Fix get_active_users query
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasjuhrich committed Oct 20, 2023
1 parent 4b9173e commit 821f635
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions pycroft/lib/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from typing import Iterable

from sqlalchemy import func, select, Boolean, String, ColumnElement
from sqlalchemy.orm import Session

from pycroft import config, property
from pycroft.helpers import user as user_helper, utc
Expand Down Expand Up @@ -53,9 +54,15 @@
UserMoveInParams
from pycroft.model.traffic import TrafficHistoryEntry
from pycroft.model.traffic import traffic_history as func_traffic_history
from pycroft.model.user import User, UnixAccount, PreMember, BaseUser, \
RoomHistoryEntry, \
PropertyGroup
from pycroft.model.user import (
User,
UnixAccount,
PreMember,
BaseUser,
RoomHistoryEntry,
PropertyGroup,
Membership,
)
from pycroft.model.webstorage import WebStorage
from pycroft.task import send_mails_async

Expand Down Expand Up @@ -1087,11 +1094,13 @@ def user_send_mail(
user_send_mails([user], template, soft_fail, use_internal, **kwargs)


def get_active_users(session, group):
active_memberships = User.active_memberships()
users = User.q.join(active_memberships)\
.filter(active_memberships.c.group_id == group.id).distinct().all()
return users
def get_active_users(session: Session, group) -> list[User]:

Check failure on line 1097 in pycroft/lib/user.py

View workflow job for this annotation

GitHub Actions / python-lint

Error

Function is missing a type annotation for one or more arguments [no-untyped-def]
return session.scalars(

Check failure on line 1098 in pycroft/lib/user.py

View workflow job for this annotation

GitHub Actions / python-lint

Error

Incompatible return value type (got "ScalarResult[User]", expected "list[User]") [return-value]
select(User)
.join(User.current_memberships)
.where(Membership.group == group)
.distinct()
)


def group_send_mail(group: PropertyGroup, subject: str, body_plain: str) -> None:
Expand Down

0 comments on commit 821f635

Please sign in to comment.