Skip to content
Snippets Groups Projects
Select Git revision
  • 743df080a14f362e70908271b99c533a5ee4f184
  • main default protected
  • ci_test
  • v2.0.27 protected
  • v2.0.26 protected
  • v2.0.25 protected
  • v2.0.24 protected
  • v2.0.23 protected
  • v2.0.22 protected
  • v2.0.21 protected
  • v2.0.20 protected
  • v2.0.19 protected
  • v2.0.18 protected
  • v2.0.17 protected
  • v2.0.16 protected
  • v2.0.15 protected
  • v2.0.14 protected
  • v2.0.13 protected
  • v2.0.12 protected
  • v2.0.11 protected
  • v2.0.10 protected
  • v2.0.9 protected
  • v2.0.8 protected
23 results

user.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