120 lines
2.5 KiB
Python
120 lines
2.5 KiB
Python
import enum
|
|
from based.columns import (
|
|
PrimarySerialColumnDefinition,
|
|
TextColumnDefinition,
|
|
IntegerColumnDefinition,
|
|
)
|
|
from pydantic import BaseModel
|
|
|
|
from db_addendum import UserRefColumnDefinition
|
|
|
|
|
|
class AccessType(enum.Enum):
|
|
READ = "read"
|
|
WRITE = "write"
|
|
READ_WRITE = "read_write"
|
|
NONE = "none"
|
|
|
|
|
|
META_INFO_TABLE_NAME = "meta_info"
|
|
META_INFO_TABLE_SCHEMA = [
|
|
PrimarySerialColumnDefinition("id"),
|
|
TextColumnDefinition("name", unique=True),
|
|
TextColumnDefinition("value"),
|
|
]
|
|
|
|
|
|
class MetaInfo(BaseModel):
|
|
id: int
|
|
name: str
|
|
value: str
|
|
|
|
|
|
USER_GROUP_TABLE_NAME = "user_group"
|
|
USER_GROUP_TABLE_SCHEMA = [
|
|
PrimarySerialColumnDefinition("id"),
|
|
TextColumnDefinition("name", unique=True),
|
|
TextColumnDefinition("description", default=""),
|
|
]
|
|
|
|
|
|
class UserGroup(BaseModel):
|
|
id: int
|
|
name: str
|
|
description: str
|
|
|
|
|
|
USERS_TABLE_NAME = "users"
|
|
USERS_TABLE_SCHEMA = [
|
|
PrimarySerialColumnDefinition("id"),
|
|
TextColumnDefinition("username", unique=True),
|
|
TextColumnDefinition("password"),
|
|
TextColumnDefinition("access_token"),
|
|
]
|
|
|
|
|
|
class User(BaseModel):
|
|
id: int
|
|
username: str
|
|
password: str
|
|
access_token: str
|
|
|
|
def to_dict(self, safe=True):
|
|
d = {
|
|
"id": self.id,
|
|
"username": self.username,
|
|
}
|
|
if not safe:
|
|
d["access_token"] = self.access_token
|
|
d["password"] = self.password
|
|
return d
|
|
|
|
|
|
USER_IN_USER_GROUP_JOIN_TABLE_NAME = "user_in_user_group"
|
|
USER_IN_USER_GROUP_JOIN_TABLE_SCHEMA = [
|
|
PrimarySerialColumnDefinition("id"),
|
|
UserRefColumnDefinition("user_id"),
|
|
IntegerColumnDefinition("user_group_id"),
|
|
]
|
|
|
|
|
|
class UserInUserGroup(BaseModel):
|
|
id: int
|
|
user_id: int
|
|
user_group_id: int
|
|
|
|
|
|
TABLE_ACCESS_TABLE_NAME = "table_access"
|
|
TABLE_ACCESS_TABLE_SCHEMA = [
|
|
PrimarySerialColumnDefinition("id"),
|
|
IntegerColumnDefinition("user_group_id"),
|
|
TextColumnDefinition("table_name"),
|
|
TextColumnDefinition("access_type"),
|
|
TextColumnDefinition("allowed_columns", default="*"),
|
|
]
|
|
|
|
|
|
class TableAccess(BaseModel):
|
|
id: int
|
|
user_group_id: int
|
|
table_name: str
|
|
access_type: str
|
|
allowed_columns: str
|
|
|
|
|
|
ASSETS_TABLE_NAME = "assets"
|
|
ASSETS_TABLE_SCHEMA = [
|
|
PrimarySerialColumnDefinition("id"),
|
|
TextColumnDefinition("name"),
|
|
TextColumnDefinition("description", default=""),
|
|
TextColumnDefinition("fid"),
|
|
TextColumnDefinition("tags", default=""),
|
|
]
|
|
|
|
|
|
class Asset(BaseModel):
|
|
id: int
|
|
name: str
|
|
description: str
|
|
fid: str
|
|
tags: str
|