Skip to content

Commit

Permalink
JSFrame: Pass taskId when calling jsRunnerData
Browse files Browse the repository at this point in the history
  • Loading branch information
dezhidki committed Jul 28, 2023
1 parent a40b6d8 commit 8152f3d
Show file tree
Hide file tree
Showing 13 changed files with 308 additions and 339 deletions.
18 changes: 12 additions & 6 deletions timApp/auth/oauth2/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
from enum import Enum
from typing import TYPE_CHECKING, Optional

from authlib.oauth2.rfc6749 import ClientMixin, scope_to_list, list_to_scope, TokenMixin, AuthorizationCodeMixin
from authlib.oauth2.rfc6749 import (
ClientMixin,
scope_to_list,
list_to_scope,
TokenMixin,
AuthorizationCodeMixin,
)
from sqlalchemy.orm import mapped_column, Mapped

from timApp.timdb.sqa import db
Expand Down Expand Up @@ -107,7 +113,7 @@ class OAuth2Token(db.Model, TokenMixin):

id: Mapped[int] = mapped_column(primary_key=True)
user_id: Mapped[int] = mapped_column(db.ForeignKey("useraccount.id"))
user: Mapped["User"] = db.relationship("User")
user: Mapped["User"] = db.relationship()

client_id: Mapped[Optional[str]] = mapped_column(db.String(48))
token_type: Mapped[Optional[str]] = mapped_column(db.String(40))
Expand Down Expand Up @@ -144,13 +150,13 @@ class OAuth2AuthorizationCode(db.Model, AuthorizationCodeMixin):

id: Mapped[int] = mapped_column(primary_key=True)
user_id: Mapped[int] = mapped_column(db.ForeignKey("useraccount.id"))
user: Mapped["User"] = db.relationship("User")
user: Mapped["User"] = db.relationship()

code: Mapped[str] = mapped_column(db.String(120), unique=True)
client_id: Mapped[str] = mapped_column(db.String(48))
redirect_uri: Mapped[str] = mapped_column(default='')
response_type: Mapped[str] = mapped_column(default='')
scope: Mapped[str] = mapped_column(default='')
redirect_uri: Mapped[str] = mapped_column(default="")
response_type: Mapped[str] = mapped_column(default="")
scope: Mapped[str] = mapped_column(default="")
nonce: Mapped[Optional[str]]
auth_time: Mapped[int] = mapped_column(default=lambda: int(time.time()))

Expand Down
7 changes: 3 additions & 4 deletions timApp/lecture/runningquestion.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@
from timApp.lecture.askedquestion import AskedQuestion
from timApp.lecture.lecture import Lecture


class Runningquestion(db.Model):

asked_id: Mapped[int] = mapped_column(
db.ForeignKey("askedquestion.asked_id"), primary_key=True
)
lecture_id: Mapped[int] = mapped_column(
db.ForeignKey("lecture.lecture_id"), primary_key=True
) # TODO should not be part of primary key (asked_id is enough)
ask_time: Mapped[datetime_tz] = mapped_column(default=datetime.utcnow
)
ask_time: Mapped[datetime_tz] = mapped_column(default=datetime.utcnow)
end_time: Mapped[Optional[datetime_tz]]

asked_question: Mapped["AskedQuestion"] = db.relationship(
"AskedQuestion", back_populates="running_question", lazy="select"
back_populates="running_question", lazy="select"
)
lecture: Mapped["Lecture"] = db.relationship(
back_populates="running_questions", lazy="select"
Expand Down
32 changes: 12 additions & 20 deletions timApp/messaging/messagelist/messagelist_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

if TYPE_CHECKING:
from timApp.item.block import Block
from timApp.user.usergroup import UserGroup


class MemberJoinMethod(Enum):
Expand Down Expand Up @@ -403,26 +404,20 @@ class MessageListTimMember(MessageListMember):

__tablename__ = "messagelist_tim_member"

id = mapped_column(
db.Integer, db.ForeignKey("messagelist_member.id"), primary_key=True
id: Mapped[int] = mapped_column(
db.ForeignKey("messagelist_member.id"), primary_key=True
)

group_id = mapped_column(db.Integer, db.ForeignKey("usergroup.id"))
group_id: Mapped[int] = mapped_column(db.ForeignKey("usergroup.id"))
"""A UserGroup id for a member."""

member = db.relationship(
"MessageListMember",
member: Mapped["MessageListMember"] = db.relationship(
back_populates="tim_member",
lazy="select",
uselist=False,
post_update=True,
)

user_group = db.relationship(
"UserGroup",
user_group: Mapped["UserGroup"] = db.relationship(
back_populates="messagelist_membership",
lazy="select",
uselist=False,
post_update=True,
)

Expand Down Expand Up @@ -464,21 +459,18 @@ class MessageListExternalMember(MessageListMember):

__tablename__ = "messagelist_external_member"

id = mapped_column(
db.Integer, db.ForeignKey("messagelist_member.id"), primary_key=True
id: Mapped[int] = mapped_column(
db.ForeignKey("messagelist_member.id"), primary_key=True
)

email_address = mapped_column(db.Text)
email_address: Mapped[str]
"""Email address of message list's external member."""

display_name = mapped_column(db.Text)
display_name: Mapped[str]
"""Display name for external user, which in most cases should be the external member's address' owner's name."""

member = db.relationship(
"MessageListMember",
back_populates="external_member",
lazy="select",
uselist=False,
member: Mapped["MessageListMember"] = db.relationship(
back_populates="external_member"
)

__mapper_args__ = {"polymorphic_identity": "external_member"}
Expand Down
2 changes: 1 addition & 1 deletion timApp/plugin/calendar/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class Event(db.Model):
"""Document that was used to create the event"""

enrolled_users: Mapped[List["UserGroup"]] = relationship(
Enrollment.__table__,
secondary=Enrollment.__table__,
primaryjoin=event_id == Enrollment.event_id,
overlaps="event, usergroup",
)
Expand Down
12 changes: 6 additions & 6 deletions timApp/timdb/sqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
"""
import os
from typing import Optional

from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import func, text
from sqlalchemy.orm import mapped_column
from sqlalchemy.orm.base import instance_state
from sqlalchemy.orm.base import instance_state, Mapped

from timApp.timdb.types import add_tim_types
from timApp.timdb.types import add_tim_types, datetime_tz

session_options = {
"future": True,
Expand All @@ -38,11 +39,10 @@


class TimeStampMixin:
created = mapped_column(
db.DateTime(timezone=True), nullable=True, default=func.now()
created: Mapped[Optional[datetime_tz]] = mapped_column(
nullable=True, default=func.now()
)
modified = mapped_column(
db.DateTime(timezone=True),
modified: Mapped[Optional[datetime_tz]] = mapped_column(
nullable=True,
default=func.now(),
onupdate=func.now(),
Expand Down
78 changes: 44 additions & 34 deletions timApp/user/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from sqlalchemy.orm import (
selectinload,
defaultload,
attribute_mapped_collection,
)
from sqlalchemy.orm.interfaces import LoaderOption
from sqlalchemy.sql import Select
Expand Down Expand Up @@ -90,6 +89,12 @@
)
from timApp.user.consentchange import ConsentChange
from timApp.lecture.lecture import Lecture
from timApp.lecture.lectureanswer import LectureAnswer
from timApp.lecture.message import Message
from timApp.lecture.questionactivity import QuestionActivity
from timApp.lecture.useractivity import Useractivity
from timApp.velp.annotation_model import Annotation
from timApp.velp.velp_models import Velp


ItemOrBlock = Union[ItemBase, Block]
Expand Down Expand Up @@ -347,23 +352,23 @@ def _set_email(self, value: str) -> None:
"""Notification settings for the user. Represents what notifications the user wants to receive."""

groups: Mapped[List["UserGroup"]] = relationship(
UserGroupMember.__table__,
secondary=UserGroupMember.__table__,
primaryjoin=(id == UserGroupMember.user_id) & membership_current,
back_populates="users",
overlaps="user, current_memberships, group, memberships, memberships_sel",
)
"""Current groups of the user is a member of."""

groups_dyn: DynamicMapped["UserGroup"] = relationship(
UserGroupMember.__table__,
secondary=UserGroupMember.__table__,
primaryjoin=id == UserGroupMember.user_id,
lazy="dynamic",
overlaps="group, groups, user, users, current_memberships, memberships, memberships_sel",
)
"""All groups of the user as a dynamic query."""

groups_inactive: DynamicMapped["UserGroup"] = relationship(
UserGroupMember.__table__,
secondary=UserGroupMember.__table__,
primaryjoin=(id == UserGroupMember.user_id) & membership_deleted,
lazy="dynamic",
overlaps="group, groups, groups_dyn, user, users, current_memberships, memberships, memberships_sel",
Expand Down Expand Up @@ -396,71 +401,76 @@ def _set_email(self, value: str) -> None:
)
"""Lectures that the user is attending at the moment."""

owned_lectures = db.relationship("Lecture", back_populates="owner", lazy="dynamic")
owned_lectures: DynamicMapped["Lecture"] = relationship(
back_populates="owner", lazy="dynamic"
)
"""Lectures that the user has created."""

lectureanswers = db.relationship(
"LectureAnswer", back_populates="user", lazy="dynamic"
lectureanswers: DynamicMapped["LectureAnswer"] = relationship(
back_populates="user", lazy="dynamic"
)
"""Lecture answers that the user sent to lectures as a dynamic query."""

messages = db.relationship("Message", back_populates="user", lazy="dynamic")
messages: DynamicMapped["Message"] = relationship(
back_populates="user", lazy="dynamic"
)
"""Lecture messages that the user sent to lectures as a dynamic query."""

questionactivity = db.relationship(
"QuestionActivity", back_populates="user", lazy="select", cascade_backrefs=False
questionactivity: Mapped[List["QuestionActivity"]] = relationship(
back_populates="user"
)
"""User's activity on lecture questions."""

useractivity = db.relationship("Useractivity", back_populates="user", lazy="select")
useractivity: Mapped[List["Useractivity"]] = relationship(back_populates="user")
"""User's activity during lectures."""

answers = db.relationship(
"Answer",
answers: DynamicMapped["Answer"] = relationship(
secondary=UserAnswer.__table__,
back_populates="users",
lazy="dynamic",
overlaps="users_all",
cascade_backrefs=False,
)
"""User's answers to tasks as a dynamic query."""

annotations = db.relationship(
"Annotation", back_populates="annotator", lazy="dynamic"
annotations: DynamicMapped["Annotation"] = relationship(
back_populates="annotator", lazy="dynamic"
)
"""User's task annotations as a dynamic query."""

velps = db.relationship("Velp", back_populates="creator", lazy="dynamic")
velps: DynamicMapped["Velp"] = relationship(
back_populates="creator", lazy="dynamic"
)
"""Velps created by the user as a dynamic query."""

sessions = db.relationship(
"UserSession", back_populates="user", lazy="select", cascade_backrefs=False
) # : list[UserSession]
sessions: Mapped[List["UserSession"]] = relationship(back_populates="user")
"""All user's sessions as a dynamic query."""

active_sessions = db.relationship(
"UserSession",
active_sessions: Mapped[Dict[str, "UserSession"]] = relationship(
primaryjoin=(id == UserSession.user_id) & ~UserSession.expired,
collection_class=attribute_mapped_collection("session_id"),
collection_class=attribute_keyed_dict("session_id"),
overlaps="sessions, user",
) # : MutableMapping[str, UserSession]
)
"""Active sessions mapped by the session ID."""

# Used for copying
notifications_alt = db.relationship("Notification", overlaps="notifications, user")
owned_lectures_alt = db.relationship("Lecture", overlaps="owned_lectures, owner")
lectureanswers_alt = db.relationship(
"LectureAnswer", overlaps="lectureanswers, user"
notifications_alt: Mapped[List["Notification"]] = relationship(
overlaps="notifications, user"
)
messages_alt = db.relationship("Message", overlaps="messages, user")
answers_alt = db.relationship(
"Answer",
owned_lectures_alt: Mapped[List["Lecture"]] = relationship(
overlaps="owned_lectures, owner"
)
lectureanswers_alt: Mapped[List["LectureAnswer"]] = relationship(
overlaps="lectureanswers, user"
)
messages_alt: Mapped[List["Message"]] = relationship(overlaps="messages, user")
answers_alt: Mapped[List["Answer"]] = relationship(
secondary=UserAnswer.__table__,
overlaps="answers, users",
cascade_backrefs=False,
)
annotations_alt = db.relationship("Annotation", overlaps="annotations, annotator")
velps_alt = db.relationship("Velp", overlaps="velps, creator")
annotations_alt: Mapped[List["Annotation"]] = relationship(
overlaps="annotations, annotator"
)
velps_alt: Mapped[List["Velp"]] = relationship(overlaps="velps, creator")

def update_email(
self,
Expand Down
Loading

0 comments on commit 8152f3d

Please sign in to comment.