Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5c452f325a | ||
|
|
e9b6bc7a3d | ||
|
|
f5545b48f0 |
@@ -71,10 +71,6 @@ function onUserChange(evt, targetRoleUuid) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function permissionDisplayName(scope) {
|
|
||||||
return props.permissions.find(p => p.scope === scope)?.display_name || scope
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleRolePermission(role, pid, checked) {
|
function toggleRolePermission(role, pid, checked) {
|
||||||
emit('toggleRolePermission', role, pid, checked)
|
emit('toggleRolePermission', role, pid, checked)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,14 +15,11 @@ const props = defineProps({
|
|||||||
const emit = defineEmits(['createOrg', 'openOrg', 'updateOrg', 'deleteOrg', 'toggleOrgPermission', 'openDialog', 'deletePermission', 'renamePermissionDisplay', 'createOidcClient', 'openOidcClient', 'deleteOidcClient', 'openServerConfig', 'navigateOut'])
|
const emit = defineEmits(['createOrg', 'openOrg', 'updateOrg', 'deleteOrg', 'toggleOrgPermission', 'openDialog', 'deletePermission', 'renamePermissionDisplay', 'createOidcClient', 'openOidcClient', 'deleteOidcClient', 'openServerConfig', 'navigateOut'])
|
||||||
|
|
||||||
// Template refs for navigation
|
// Template refs for navigation
|
||||||
const orgSection = ref(null)
|
|
||||||
const orgActionsRef = ref(null)
|
const orgActionsRef = ref(null)
|
||||||
const orgTableRef = ref(null)
|
const orgTableRef = ref(null)
|
||||||
const permMatrixRef = ref(null)
|
const permMatrixRef = ref(null)
|
||||||
const permActionsRef = ref(null)
|
const permActionsRef = ref(null)
|
||||||
const permTableRef = ref(null)
|
const permTableRef = ref(null)
|
||||||
const oidcActionsRef = ref(null)
|
|
||||||
const oidcTableRef = ref(null)
|
|
||||||
|
|
||||||
const sortedOrgs = computed(() => [...props.orgs].sort((a,b)=> {
|
const sortedOrgs = computed(() => [...props.orgs].sort((a,b)=> {
|
||||||
const nameCompare = a.org.display_name.localeCompare(b.org.display_name)
|
const nameCompare = a.org.display_name.localeCompare(b.org.display_name)
|
||||||
@@ -62,10 +59,6 @@ const sortedPermissions = computed(() => [...props.permissions].sort((a,b)=> a.s
|
|||||||
const isMasterAdmin = computed(() => props.info?.ctx.permissions.includes('auth:admin'))
|
const isMasterAdmin = computed(() => props.info?.ctx.permissions.includes('auth:admin'))
|
||||||
const isOrgAdmin = computed(() => props.info?.ctx.permissions.includes('auth:org:admin'))
|
const isOrgAdmin = computed(() => props.info?.ctx.permissions.includes('auth:org:admin'))
|
||||||
|
|
||||||
function permissionDisplayName(scope) {
|
|
||||||
return props.permissions.find(p => p.scope === scope)?.display_name || scope
|
|
||||||
}
|
|
||||||
|
|
||||||
function getRoleNames(org) {
|
function getRoleNames(org) {
|
||||||
// org.roles is dict[UUID, Role]
|
// org.roles is dict[UUID, Role]
|
||||||
return Object.values(org.roles)
|
return Object.values(org.roles)
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
import msgspec
|
import msgspec
|
||||||
from fastapi_vue import server
|
from fastapi_vue import server
|
||||||
from fastapi_vue.hostutil import parse_endpoints
|
from fastapi_vue.hostutil import parse_endpoints
|
||||||
|
|
||||||
|
from paskia._version import __version__
|
||||||
from paskia.db.jsonl import load_readonly
|
from paskia.db.jsonl import load_readonly
|
||||||
from paskia.util import startupbox
|
from paskia.util import startupbox
|
||||||
from paskia.util.hostutil import (
|
from paskia.util.hostutil import (
|
||||||
@@ -74,7 +76,11 @@ def main():
|
|||||||
|
|
||||||
# Load stored config (read-only, no writes, no global state)
|
# Load stored config (read-only, no writes, no global state)
|
||||||
db_path = os.environ.get("PASKIA_DB", f"{args.rp_id}.paskiadb")
|
db_path = os.environ.get("PASKIA_DB", f"{args.rp_id}.paskiadb")
|
||||||
|
try:
|
||||||
config = load_readonly(db_path, rp_id=args.rp_id).config
|
config = load_readonly(db_path, rp_id=args.rp_id).config
|
||||||
|
except SystemExit as e:
|
||||||
|
print(f"🛑 Paskia {__version__} could not load")
|
||||||
|
sys.exit(str(e))
|
||||||
|
|
||||||
# Override stored config with CLI args, or clear with empty string
|
# Override stored config with CLI args, or clear with empty string
|
||||||
if args.rp_name is not None:
|
if args.rp_name is not None:
|
||||||
|
|||||||
+18
-17
@@ -41,11 +41,9 @@ class ReplayResult(msgspec.Struct, frozen=False):
|
|||||||
changes: int = 0
|
changes: int = 0
|
||||||
|
|
||||||
|
|
||||||
class DatabaseError(Exception):
|
class DatabaseError(ValueError):
|
||||||
"""Exception raised for database loading errors."""
|
"""Exception raised for database loading errors."""
|
||||||
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def _replay_from_data(data: bytes, db_path: str) -> ReplayResult:
|
def _replay_from_data(data: bytes, db_path: str) -> ReplayResult:
|
||||||
"""Replay database state from file data, using the last snapshot if available."""
|
"""Replay database state from file data, using the last snapshot if available."""
|
||||||
@@ -61,14 +59,16 @@ def _replay_from_data(data: bytes, db_path: str) -> ReplayResult:
|
|||||||
|
|
||||||
# Replay change records after the snapshot
|
# Replay change records after the snapshot
|
||||||
lines = data[start_offset:].split(b"\n")
|
lines = data[start_offset:].split(b"\n")
|
||||||
for line_num, raw in enumerate(lines, start=1): # 1-based line numbering
|
for raw in lines:
|
||||||
line = raw.strip()
|
line = raw.strip()
|
||||||
if not line:
|
if not line:
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
change = msgspec.json.decode(line, type=ChangeRecord)
|
change = msgspec.json.decode(line, type=ChangeRecord)
|
||||||
except msgspec.DecodeError as e:
|
except msgspec.DecodeError as e:
|
||||||
raise DatabaseError(f"{resolved_path}:{line_num}: {e}")
|
raise DatabaseError(
|
||||||
|
f"{resolved_path}: {e}\n{line.decode(errors='replace')}"
|
||||||
|
)
|
||||||
result.state = jsondiff.patch(result.state, change.diff, marshal=True)
|
result.state = jsondiff.patch(result.state, change.diff, marshal=True)
|
||||||
result.v = change.v
|
result.v = change.v
|
||||||
result.ts = change.ts
|
result.ts = change.ts
|
||||||
@@ -88,19 +88,10 @@ def load_readonly(db_path: str, *, rp_id: str = "localhost") -> DB:
|
|||||||
return DB(config=Config(rp_id=rp_id))
|
return DB(config=Config(rp_id=rp_id))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(path, "rb") as f:
|
content = path.read_bytes()
|
||||||
content = f.read()
|
|
||||||
r = _replay_from_data(content, str(path.resolve()))
|
r = _replay_from_data(content, str(path.resolve()))
|
||||||
data_dict = r.state
|
data_dict = r.state
|
||||||
version = r.v
|
version = r.v
|
||||||
except OSError as e:
|
|
||||||
_logger.exception("Failed to load database")
|
|
||||||
raise SystemExit(f"{e}")
|
|
||||||
except (ValueError, msgspec.DecodeError, DatabaseError) as e:
|
|
||||||
raise SystemExit(f"{e}")
|
|
||||||
except Exception as e:
|
|
||||||
_logger.exception("Unexpected error loading database")
|
|
||||||
raise SystemExit(f"{e}")
|
|
||||||
|
|
||||||
if not data_dict:
|
if not data_dict:
|
||||||
return DB(config=Config(rp_id=rp_id))
|
return DB(config=Config(rp_id=rp_id))
|
||||||
@@ -109,8 +100,18 @@ def load_readonly(db_path: str, *, rp_id: str = "localhost") -> DB:
|
|||||||
apply_migrations_readonly(data_dict, version, MigrationCtx(rp_id=rp_id))
|
apply_migrations_readonly(data_dict, version, MigrationCtx(rp_id=rp_id))
|
||||||
|
|
||||||
# Decode to msgspec struct
|
# Decode to msgspec struct
|
||||||
db = msgspec.json.decode(msgspec.json.encode(data_dict), type=DB)
|
try:
|
||||||
return db
|
return msgspec.json.decode(msgspec.json.encode(data_dict), type=DB)
|
||||||
|
except msgspec.ValidationError as e:
|
||||||
|
raise DatabaseError(f"{path.resolve()}: {e}") from None
|
||||||
|
except OSError as e:
|
||||||
|
_logger.exception("Failed to load database")
|
||||||
|
raise SystemExit(f"{e}")
|
||||||
|
except (ValueError, msgspec.DecodeError) as e:
|
||||||
|
raise SystemExit(f"{e}")
|
||||||
|
except Exception as e:
|
||||||
|
_logger.exception("Unexpected error loading database")
|
||||||
|
raise SystemExit(f"{e}")
|
||||||
|
|
||||||
|
|
||||||
class ChangeRecord(msgspec.Struct, omit_defaults=True, kw_only=True):
|
class ChangeRecord(msgspec.Struct, omit_defaults=True, kw_only=True):
|
||||||
|
|||||||
@@ -45,6 +45,13 @@ def migrate_v4(d: dict, ctx: MigrationCtx) -> None:
|
|||||||
d["oidc"] = {"clients": {}, "key": base64.standard_b64encode(secret_key()).decode()}
|
d["oidc"] = {"clients": {}, "key": base64.standard_b64encode(secret_key()).decode()}
|
||||||
|
|
||||||
|
|
||||||
|
def migrate_v5(d: dict, ctx: MigrationCtx) -> None:
|
||||||
|
"""Convert config.listen from str to list[str] if needed."""
|
||||||
|
listen = d["config"].get("listen")
|
||||||
|
if listen and isinstance(listen, str):
|
||||||
|
d["config"]["listen"] = [listen]
|
||||||
|
|
||||||
|
|
||||||
migrations = sorted(
|
migrations = sorted(
|
||||||
[f for n, f in globals().items() if n.startswith("migrate_v")],
|
[f for n, f in globals().items() if n.startswith("migrate_v")],
|
||||||
key=lambda f: int(f.__name__.removeprefix("migrate_v")),
|
key=lambda f: int(f.__name__.removeprefix("migrate_v")),
|
||||||
|
|||||||
Reference in New Issue
Block a user