Skip to content
Snippets Groups Projects
Select Git revision
  • d403aeba80cba79faa55c5c764440ca99fff6bad
  • master default protected
  • md-export
  • th/mail
  • 179-einladungen-zum-aushaengen-drucken
5 results

decorators.py

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    user.py 2.04 KiB
    from datetime import datetime
    from typing import Any
    
    from videoag_common.database import *
    from videoag_common.api_object import *
    from .course import Course, responsible_table
    
    
    class User(ApiObject, Base):
        
        handle: Mapped[str] = api_mapped(
            mapped_column(String(32, STRING_COLLATION), nullable=False),
            ApiStringField(
                include_in_data=True, data_only_mod=True
            )
        )
        display_name: Mapped[str] = api_mapped(
            mapped_column(Text(collation=STRING_COLLATION), nullable=False),
            ApiStringField(
                include_in_data=True, data_only_mod=True
            )
        )
        full_name: Mapped[str] = api_mapped(
            mapped_column(Text(collation=STRING_COLLATION), nullable=False),
            ApiStringField(
                include_in_data=True, data_only_mod=True
            )
        )
        email: Mapped[str] = api_mapped(
            mapped_column(Text(collation=STRING_COLLATION), nullable=False),
            ApiStringField(
                include_in_data=True, data_only_mod=True,
                # One can only see their own email
                data_if=lambda user, args: user.id == args.current_user_id if hasattr(args, "current_user_id") else False,
                data_notes="Only included for own user in the authentication status"
            )
        )
        
        last_login: Mapped[datetime] = mapped_column(UTCTimestamp(), nullable=True)
        
        enable_mail_notifications: Mapped[bool] = mapped_column(nullable=False, default=True)
        notify_new_video: Mapped[bool] = mapped_column(nullable=False, default=True)
        notify_edit: Mapped[bool] = mapped_column(nullable=False, default=True)
        notify_chapter_suggested: Mapped[bool] = mapped_column(nullable=False, default=True)
        
        responsible_courses: Mapped[list[Course]] = relationship(
            secondary=responsible_table,
            back_populates="responsible_users",
            lazy="raise_on_sql"
        )
        
        @hybrid_method
        def has_access(self, context: dict[AccessContextKey, Any]):
            cond = super().has_access(context)
            cond &= AC_IS_MOD.get(context)
            return cond