Coverage for polar/models/organization_access_token.py: 95%
21 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 16:17 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 16:17 +0000
1from datetime import datetime 1ab
2from uuid import UUID 1ab
4from sqlalchemy import CHAR, TIMESTAMP, ForeignKey, String, Text, Uuid 1ab
5from sqlalchemy.orm import Mapped, declared_attr, mapped_column, relationship 1ab
7from polar.auth.scope import Scope, scope_to_set 1ab
8from polar.kit.db.models.base import RecordModel 1ab
10from .organization import Organization 1ab
13class OrganizationAccessToken(RecordModel): 1ab
14 __tablename__ = "organization_access_tokens" 1ab
16 token: Mapped[str] = mapped_column(CHAR(64), unique=True, nullable=False) 1ab
17 scope: Mapped[str] = mapped_column(Text, nullable=False) 1ab
18 expires_at: Mapped[datetime | None] = mapped_column( 1ab
19 TIMESTAMP(timezone=True), nullable=True, index=True
20 )
21 comment: Mapped[str] = mapped_column(String, nullable=False) 1ab
22 last_used_at: Mapped[datetime | None] = mapped_column( 1ab
23 TIMESTAMP(timezone=True), nullable=True, default=None
24 )
26 organization_id: Mapped[UUID] = mapped_column( 1ab
27 Uuid, ForeignKey("organizations.id"), nullable=False, index=True
28 )
30 @declared_attr 1ab
31 def organization(cls) -> Mapped["Organization"]: 1ab
32 return relationship(Organization, lazy="raise") 1ab
34 @property 1ab
35 def scopes(self) -> set[Scope]: 1ab
36 return scope_to_set(self.scope)