Initialize configurable Quick Access module
Module Package Release / publish-packages (push) Successful in 12s

This commit is contained in:
2026-08-06 19:02:54 +02:00
parent f3cf91b898
commit 3fbbb84267
34 changed files with 3086 additions and 1 deletions
+65
View File
@@ -0,0 +1,65 @@
from __future__ import annotations
import tempfile
import unittest
from pathlib import Path
from alembic.runtime.migration import MigrationContext
from sqlalchemy import create_engine, inspect
from govoplan_core.db.migrations import migrate_database
from govoplan_quick_access.backend.manifest import get_manifest
class QuickAccessMigrationTests(unittest.TestCase):
def test_migration_creates_profile_table_and_head(self) -> None:
with tempfile.TemporaryDirectory(
prefix="govoplan-quick-access-migration-"
) as directory:
url = f"sqlite:///{Path(directory) / 'quick-access.db'}"
migrate_database(
database_url=url,
enabled_modules=("quick_access",),
manifest_factories=(get_manifest,),
)
engine = create_engine(url)
try:
with engine.connect() as connection:
self.assertIn(
"9a4e6c2d8f10",
set(MigrationContext.configure(connection).get_current_heads()),
)
self.assertIn(
"quick_access_profiles",
inspect(connection).get_table_names(),
)
self.assertEqual(
{
"category_preferences",
"revision",
"scope_id",
"scope_key",
"scope_type",
"tenant_id",
"tool_preferences",
},
{
column["name"]
for column in inspect(connection).get_columns(
"quick_access_profiles"
)
if column["name"] not in {
"created_at",
"created_by",
"id",
"updated_at",
"updated_by",
}
},
)
finally:
engine.dispose()
if __name__ == "__main__":
unittest.main()
+142
View File
@@ -0,0 +1,142 @@
from __future__ import annotations
import unittest
from sqlalchemy import create_engine
from sqlalchemy.orm import Session
from govoplan_core.core.modules import (
FrontendModule,
ModuleManifest,
QuickAccessTool,
)
from govoplan_core.core.registry import PlatformRegistry
from govoplan_quick_access.backend.db.models import QuickAccessProfile
from govoplan_quick_access.backend.service import build_catalogue, resolve_effective
def registry_with_tools() -> PlatformRegistry:
registry = PlatformRegistry()
registry.register(
ModuleManifest(
id="example",
name="Example",
version="test",
frontend=FrontendModule(
module_id="example",
quick_access_tools=(
QuickAccessTool(
id="example.work",
module_id="example",
category_id="work",
label="Example work",
surface_id="example.module",
icon="list-checks",
required_any=("example:item:read",),
),
),
),
)
)
return registry
class QuickAccessTests(unittest.TestCase):
def setUp(self) -> None:
self.engine = create_engine("sqlite+pysqlite:///:memory:")
QuickAccessProfile.__table__.create(self.engine)
def tearDown(self) -> None:
self.engine.dispose()
def test_catalogue_is_derived_from_manifest_tools(self) -> None:
catalogue = build_catalogue(registry_with_tools())
self.assertEqual(["work", "calendar", "messages", "files"], [item.id for item in catalogue.categories])
self.assertEqual("example.work", catalogue.tools[0].id)
def test_personal_catalogue_excludes_tools_without_permission(self) -> None:
catalogue = build_catalogue(
registry_with_tools(), permission_checker=lambda _scope: False
)
self.assertEqual([], catalogue.tools)
def test_catalogue_excludes_modules_outside_the_tenant_graph(self) -> None:
catalogue = build_catalogue(
registry_with_tools(),
allowed_module_ids=(),
)
self.assertEqual([], catalogue.tools)
def test_upper_scope_block_cannot_be_overridden_by_user(self) -> None:
with Session(self.engine) as session:
session.add_all(
(
QuickAccessProfile(
scope_type="system",
tenant_id=None,
scope_id=None,
scope_key="system:*",
category_preferences={},
tool_preferences={"example.work": {"enabled": False}},
revision=2,
),
QuickAccessProfile(
scope_type="user",
tenant_id="tenant-1",
scope_id="account-1",
scope_key="user:tenant-1:account-1",
category_preferences={},
tool_preferences={"example.work": {"enabled": True}},
revision=2,
),
)
)
session.commit()
effective = resolve_effective(
session,
registry=registry_with_tools(),
tenant_id="tenant-1",
account_id="account-1",
permission_checker=lambda _scope: True,
)
work = next(item for item in effective.categories if item.id == "work")
self.assertFalse(work.enabled)
self.assertFalse(work.tools[0].enabled)
self.assertEqual("system", work.tools[0].locked_by)
def test_forced_tenant_category_remains_visible(self) -> None:
with Session(self.engine) as session:
session.add(
QuickAccessProfile(
scope_type="tenant",
tenant_id="tenant-1",
scope_id="tenant-1",
scope_key="tenant:tenant-1",
category_preferences={"work": {"enabled": True, "forced": True}},
tool_preferences={},
revision=2,
)
)
session.commit()
effective = resolve_effective(
session,
registry=registry_with_tools(),
tenant_id="tenant-1",
account_id="account-1",
permission_checker=lambda _scope: True,
)
work = next(item for item in effective.categories if item.id == "work")
self.assertTrue(work.enabled)
self.assertTrue(work.forced)
self.assertEqual("tenant", work.locked_by)
if __name__ == "__main__":
unittest.main()