Coverage for polar/models/oauth2_grant.py: 95%
22 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 uuid import UUID 1ab
3from sqlalchemy import ForeignKey, String, Text, UniqueConstraint, Uuid 1ab
4from sqlalchemy.orm import Mapped, declared_attr, mapped_column, relationship 1ab
6from polar.kit.db.models import RecordModel 1ab
7from polar.models.organization import Organization 1ab
8from polar.models.user import User 1ab
11class OAuth2Grant(RecordModel): 1ab
12 __tablename__ = "oauth2_grants" 1ab
13 __table_args__ = ( 1ab
14 UniqueConstraint("client_id", "user_id"),
15 UniqueConstraint("client_id", "organization_id"),
16 )
18 client_id: Mapped[str] = mapped_column(String(52), nullable=False, index=True) 1ab
19 scope: Mapped[str] = mapped_column(Text, default="", nullable=False) 1ab
20 user_id: Mapped[UUID | None] = mapped_column( 1ab
21 Uuid,
22 ForeignKey("users.id", ondelete="cascade"),
23 nullable=True,
24 index=True,
25 )
26 organization_id: Mapped[UUID | None] = mapped_column( 1ab
27 Uuid,
28 ForeignKey("organizations.id", ondelete="cascade"),
29 nullable=True,
30 index=True,
31 )
33 @declared_attr 1ab
34 def user(cls) -> Mapped[User | None]: 1ab
35 return relationship(User, lazy="joined") 1ab
37 @declared_attr 1ab
38 def organization(cls) -> Mapped[Organization | None]: 1ab
39 return relationship(Organization, lazy="joined") 1ab
41 @property 1ab
42 def scopes(self) -> list[str]: 1ab
43 return self.scope.strip().split()