Skip to content

Pengguna

Keizinan

Bases: BaseStrictDataTable

Role model for controlling access types

Fields

  • peranan (TextField): name of role
    • null: False
    • unique: True
  • tambah (BooleanField): can create
    • null: False
  • baca (BooleanField): can read
    • null: False
  • ubah (BooleanField): can update
    • null: False
  • buang (BooleanField): can delete
    • null: False
Source code in samudra/models/auth/pengguna.py
class Keizinan(BaseStrictDataTable):
    """Role model for controlling access types

    ## Fields
    - `peranan` (TextField): name of role
        * null: False
        * unique: True
    - `tambah` (BooleanField): can create
        * null: False
    - `baca` (BooleanField): can read
        * null: False
    - `ubah` (BooleanField): can update
        * null: False
    - `buang` (BooleanField): can delete
        * null: False
    """

    peranan = TextField(null=False, unique=True)
    tambah = BooleanField(null=False)
    baca = BooleanField(null=False)
    ubah = BooleanField(null=False)
    buang = BooleanField(null=False)

Pengguna

Bases: BaseDataTable

User model to store users.

Fields

  • nama (TextField): username
    • null: False
  • kunci (TextField): hashed password
    • null: False
  • peranan (ForeignKeyField): foreign key to Keizinan
    • field: Keizinan.peranan
    • backref: Keizinan.pengguna
    • on delete: set default
    • default: RoleEnum.DEFAULT
Source code in samudra/models/auth/pengguna.py
class Pengguna(BaseDataTable):
    """User model to store users.

    ## Fields
    - `nama` (TextField): username
        * null: False
    - `kunci` (TextField): hashed password
        * null: False
    - `peranan` (ForeignKeyField): foreign key to [`Keizinan`][samudra.models.auth.pengguna.Keizinan]
        * field: Keizinan.peranan
        * backref: Keizinan.pengguna
        * on delete: set default
        * default: [`RoleEnum.DEFAULT`][samudra.models.auth.pengguna.RoleEnum]
    """

    nama = TextField(null=False)
    kunci = TextField(null=False)
    peranan = ForeignKeyField(
        model=Keizinan,
        field=Keizinan.peranan,
        backref="pengguna",
        on_delete="set default",
        default=RoleEnum.DEFAULT.value,
    )

    def __repr__(self) -> str:
        return f"<model.{self.__class__.__name__}: id={self.id} nama={self.nama} kunci={self.kunci}>"

RoleEnum

Bases: enum.Enum

List of Roles

Values

  • DEFAULT = 'BIASA'
  • ADMIN = 'ADMIN'
Source code in samudra/models/auth/pengguna.py
class RoleEnum(enum.Enum):
    """List of Roles

    ## Values
    - `DEFAULT` = 'BIASA'
    - `ADMIN` = 'ADMIN'
    """

    DEFAULT = "BIASA"
    ADMIN = "ADMIN"