Skip to content

Class tigrbl.orm.tables.rbac.RolePerm

tigrbl.orm.tables.rbac.RolePerm

Bases: Base, GUIDPk, Timestamped, TenantBound, RelationEdge, MaskableEdge

role_id class-attribute instance-attribute

role_id = acol(
    storage=S(PgUUID, fk=ForeignKeySpec("roles.id")),
    field=F(),
    io=IO(),
)

target_table class-attribute instance-attribute

target_table = acol(storage=S(String), field=F(), io=IO())

target_id class-attribute instance-attribute

target_id = acol(storage=S(String), field=F(), io=IO())

mask class-attribute instance-attribute

mask = acol(
    spec=ColumnSpec(
        storage=S(type_=Integer, nullable=False),
        field=F(py_type=int),
        io=CRUD_IO,
    )
)

created_at class-attribute instance-attribute

created_at = acol(
    spec=ColumnSpec(
        storage=S(
            type_=TZDateTime,
            default=tzutcnow,
            nullable=False,
        ),
        field=F(py_type=datetime),
        io=RO_IO,
    )
)

updated_at class-attribute instance-attribute

updated_at = acol(
    spec=ColumnSpec(
        storage=S(
            type_=TZDateTime,
            default=tzutcnow,
            onupdate=tzutcnow,
            nullable=False,
        ),
        field=F(py_type=datetime),
        io=RO_IO,
    )
)

id class-attribute instance-attribute

id = acol(
    spec=ColumnSpec(
        storage=S(
            type_=PgUUID(as_uuid=True),
            primary_key=True,
            default=uuid4,
        ),
        field=F(
            py_type=UUID,
            constraints={"examples": [uuid_example]},
        ),
        io=RO_IO,
    )
)

metadata class-attribute instance-attribute

metadata = MetaData(
    naming_convention={
        "pk": "pk_%(table_name)s",
        "fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
        "ix": "ix_%(table_name)s_%(column_0_name)s",
        "uq": "uq_%(table_name)s_%(column_0_name)s",
        "ck": "ck_%(table_name)s_%(column_0_name)s_%(constraint_type)s",
    }
)

is_visible staticmethod

is_visible(obj, ctx)
Source code in tigrbl/orm/mixins/tenant_bound.py
110
111
112
@staticmethod
def is_visible(obj, ctx) -> bool:
    return getattr(obj, "tenant_id", None) == _ctx_tenant_id(ctx)

tenant_id

tenant_id()
Source code in tigrbl/orm/mixins/tenant_bound.py
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
@declared_attr
def tenant_id(cls) -> Mapped[UUID]:
    pol = getattr(cls, TIGRBL_TENANT_POLICY_ATTR, TenantPolicy.CLIENT_SET)
    schema = _infer_schema(cls, default="public")

    in_verbs = (
        ("create", "update", "replace")
        if pol == TenantPolicy.CLIENT_SET
        else ("create",)
    )
    io = IO(
        in_verbs=in_verbs,
        out_verbs=("read", "list"),
        mutable_verbs=in_verbs,
    )

    spec = ColumnSpec(
        storage=S(
            type_=PgUUID(as_uuid=True),
            fk=ForeignKeySpec(target=f"{schema}.tenants.id"),
            nullable=False,
            index=True,
        ),
        field=F(py_type=UUID),
        io=io,
    )
    return acol(spec=spec)