137 lines
2.9 KiB
Python
137 lines
2.9 KiB
Python
import enum
|
|
from based.columns import (
|
|
PrimarySerialColumnDefinition,
|
|
TextColumnDefinition,
|
|
IntegerColumnDefinition,
|
|
make_column_unique,
|
|
)
|
|
from pydantic import BaseModel
|
|
|
|
|
|
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"),
|
|
make_column_unique(TextColumnDefinition("name")),
|
|
TextColumnDefinition("value"),
|
|
TextColumnDefinition("allowed_columns", default="*"),
|
|
]
|
|
|
|
|
|
class MetaInfo(BaseModel):
|
|
id: int
|
|
name: str
|
|
value: str
|
|
allowed_columns: str
|
|
|
|
|
|
USER_GROUP_TABLE_NAME = "user_group"
|
|
USER_GROUP_TABLE_SCHEMA = [
|
|
PrimarySerialColumnDefinition("id"),
|
|
make_column_unique(TextColumnDefinition("name")),
|
|
TextColumnDefinition("description", default=""),
|
|
]
|
|
|
|
|
|
class UserGroup(BaseModel):
|
|
id: int
|
|
name: str
|
|
description: str
|
|
|
|
|
|
USERS_TABLE_NAME = "users"
|
|
USERS_TABLE_SCHEMA = [
|
|
PrimarySerialColumnDefinition("id"),
|
|
make_column_unique(TextColumnDefinition("username")),
|
|
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"),
|
|
IntegerColumnDefinition("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("catalog", default="/root"),
|
|
]
|
|
|
|
|
|
class Asset(BaseModel):
|
|
id: int
|
|
name: str
|
|
description: str
|
|
fid: str
|
|
catalog: str
|
|
|
|
|
|
ASSET_ACCESS_TABLE_NAME = "asset_access"
|
|
ASSET_ACCESS_TABLE_SCHEMA = [
|
|
PrimarySerialColumnDefinition("id"),
|
|
IntegerColumnDefinition("user_group_id"),
|
|
IntegerColumnDefinition("asset_id"),
|
|
TextColumnDefinition("access_type"),
|
|
]
|
|
|
|
|
|
class AssetAccess(BaseModel):
|
|
id: int
|
|
user_group_id: int
|
|
asset_id: int
|
|
access_type: str
|