Move working documents to its own area, rename dashboard
This commit is contained in:
+31
-14
@@ -4,20 +4,11 @@ from sqlalchemy import select
|
||||
|
||||
from app.db.session import Base, SessionLocal, engine
|
||||
from app.models.assumption import FreightCostRule, PackagingCostRule, ProcessCostRule
|
||||
from app.models.client_access import ClientAccount, ClientFeatureAccess, ClientUser
|
||||
from app.models.client_access import ClientAccessAuditEvent, ClientAccount, ClientFeatureAccess, ClientUser, ClientUserModulePermission
|
||||
from app.models.mix import Mix, MixIngredient
|
||||
from app.models.product import Product
|
||||
from app.models.raw_material import RawMaterial, RawMaterialPriceVersion
|
||||
|
||||
|
||||
CLIENT_FEATURES = [
|
||||
("dashboard", "Dashboard", "workspace", "Top-level operational dashboard"),
|
||||
("raw_materials", "Raw Materials", "costing", "Maintain live material costs and versions"),
|
||||
("mix_master", "Mix Master", "costing", "Create and maintain mix worksheets"),
|
||||
("products", "Products", "pricing", "Review finished product pricing"),
|
||||
("scenarios", "Scenarios", "planning", "Run scenario overrides and comparisons"),
|
||||
("powerbi_export", "Power BI Export", "reporting", "Expose client access data to BI consumers"),
|
||||
]
|
||||
from app.services.client_access_service import MODULE_CATALOG, default_access_level_for_role
|
||||
|
||||
|
||||
def seed_client_access(db):
|
||||
@@ -51,7 +42,7 @@ def seed_client_access(db):
|
||||
tenant_id=specialty.tenant_id,
|
||||
full_name="Amelia Hart",
|
||||
email="operator@example.com",
|
||||
role="admin",
|
||||
role="superadmin",
|
||||
status="active",
|
||||
is_new_user=False,
|
||||
last_login_at=datetime(2026, 4, 24, 11, 30),
|
||||
@@ -81,13 +72,13 @@ def seed_client_access(db):
|
||||
)
|
||||
|
||||
enabled_feature_map = {
|
||||
"hunter-premium-produce": {"dashboard", "raw_materials", "mix_master", "products", "scenarios", "powerbi_export"},
|
||||
"hunter-premium-produce": {"dashboard", "raw_materials", "mix_master", "products", "scenarios", "powerbi_export", "client_access"},
|
||||
"loft-grains": {"dashboard", "products", "powerbi_export"},
|
||||
}
|
||||
|
||||
for client in (specialty, loft):
|
||||
enabled_keys = enabled_feature_map[client.tenant_id]
|
||||
for feature_key, feature_name, feature_group, description in CLIENT_FEATURES:
|
||||
for feature_key, feature_name, feature_group, description in MODULE_CATALOG:
|
||||
client.features.append(
|
||||
ClientFeatureAccess(
|
||||
tenant_id=client.tenant_id,
|
||||
@@ -99,6 +90,32 @@ def seed_client_access(db):
|
||||
)
|
||||
)
|
||||
|
||||
for user in client.users:
|
||||
for module_key, _, _, _ in MODULE_CATALOG:
|
||||
user.module_permissions.append(
|
||||
ClientUserModulePermission(
|
||||
tenant_id=client.tenant_id,
|
||||
client_account_id=client.id,
|
||||
module_key=module_key,
|
||||
access_level=default_access_level_for_role(user.role, module_key),
|
||||
)
|
||||
)
|
||||
|
||||
specialty.audit_events.append(
|
||||
ClientAccessAuditEvent(
|
||||
tenant_id=specialty.tenant_id,
|
||||
actor_type="seed",
|
||||
actor_name="Lean 101 Seeder",
|
||||
actor_email="system@lean101.local",
|
||||
actor_role="system",
|
||||
action="client_access.seeded",
|
||||
target_type="client_account",
|
||||
target_id=specialty.id,
|
||||
module_key="client_access",
|
||||
summary="Initial client access controls, module permissions, and feature flags were seeded.",
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def seed_costing_workspace(db):
|
||||
existing = db.scalar(select(RawMaterial.id))
|
||||
|
||||
Reference in New Issue
Block a user