Adding sub-parts
This commit is contained in:
1 parent
45bc5bf8f6
commit
c8696e67b5
14 files changed
+436
-2
No files matched your search
+17
-1
@@ -13,10 +13,15 @@ from app.core.config import settings
|
||||
from app.core.database import AsyncSessionLocal, init_db
|
||||
from app.crud import part_type as part_type_crud
|
||||
from app.crud import role as role_crud
|
||||
from app.crud import sub_part_type as sub_part_type_crud
|
||||
from app.crud import user as user_crud
|
||||
|
||||
PART_TYPES = ["Flip Cover", "ARD", "Polarizer", "Adapter Ring", "Scope"]
|
||||
|
||||
SUB_PART_TYPES = {
|
||||
"Scope": ["Riflescope", "Binoculars", "Combat Optic", "Red Dot", "Spotter"],
|
||||
}
|
||||
|
||||
# Default permission catalogue: "<resource>:<action>".
|
||||
PERMISSIONS = [
|
||||
("users:read", "View users"),
|
||||
@@ -39,13 +44,16 @@ PERMISSIONS = [
|
||||
("part_types:read", "View part types"),
|
||||
("part_types:write", "Create and update part types"),
|
||||
("part_types:delete", "Delete part types"),
|
||||
("sub_part_types:read", "View sub part types"),
|
||||
("sub_part_types:write", "Create and update sub part types"),
|
||||
("sub_part_types:delete", "Delete sub part types"),
|
||||
("audit_log:read", "View audit log"),
|
||||
]
|
||||
|
||||
# Default roles -> permission names. "admin" gets everything.
|
||||
ROLES = {
|
||||
"admin": [name for name, _ in PERMISSIONS], # includes audit_log:read
|
||||
"user": ["users:read", "iso_threads:read", "unc_threads:read", "manufacturers:read", "scope_models:read", "part_types:read"],
|
||||
"user": ["users:read", "iso_threads:read", "unc_threads:read", "manufacturers:read", "scope_models:read", "part_types:read", "sub_part_types:read"],
|
||||
}
|
||||
|
||||
|
||||
@@ -81,6 +89,14 @@ async def seed() -> None:
|
||||
if await part_type_crud.get_by_name(db, pt_name) is None:
|
||||
await part_type_crud.create(db, name=pt_name)
|
||||
|
||||
# Sub part types
|
||||
for pt_name, spt_names in SUB_PART_TYPES.items():
|
||||
pt = await part_type_crud.get_by_name(db, pt_name)
|
||||
if pt is not None:
|
||||
for spt_name in spt_names:
|
||||
if await sub_part_type_crud.get_by_name_and_part_type(db, spt_name, pt.id) is None:
|
||||
await sub_part_type_crud.create(db, name=spt_name, part_type_id=pt.id)
|
||||
|
||||
# Superuser
|
||||
existing = await user_crud.get_by_email(db, settings.first_superuser_email)
|
||||
if existing is None:
|
||||
|
||||
Reference in new issue
Block a user