Adding Part Types
This commit is contained in:
1 parent
b7ad517174
commit
fe6f9cca05
14 files changed
+350
-2
No files matched your search
+12
-1
@@ -11,9 +11,12 @@ import asyncio
|
||||
|
||||
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 user as user_crud
|
||||
|
||||
PART_TYPES = ["Flip Cover", "ARD", "Polarizer", "Adapter Ring", "Scope"]
|
||||
|
||||
# Default permission catalogue: "<resource>:<action>".
|
||||
PERMISSIONS = [
|
||||
("users:read", "View users"),
|
||||
@@ -33,12 +36,15 @@ PERMISSIONS = [
|
||||
("scope_models:read", "View scope models"),
|
||||
("scope_models:write", "Create and update scope models"),
|
||||
("scope_models:delete", "Delete scope models"),
|
||||
("part_types:read", "View part types"),
|
||||
("part_types:write", "Create and update part types"),
|
||||
("part_types:delete", "Delete part types"),
|
||||
]
|
||||
|
||||
# Default roles -> permission names. "admin" gets everything.
|
||||
ROLES = {
|
||||
"admin": [name for name, _ in PERMISSIONS],
|
||||
"user": ["users:read", "iso_threads:read", "unc_threads:read", "manufacturers:read", "scope_models:read"],
|
||||
"user": ["users:read", "iso_threads:read", "unc_threads:read", "manufacturers:read", "scope_models:read", "part_types:read"],
|
||||
}
|
||||
|
||||
|
||||
@@ -69,6 +75,11 @@ async def seed() -> None:
|
||||
)
|
||||
roles[role_name] = role
|
||||
|
||||
# Part types
|
||||
for pt_name in PART_TYPES:
|
||||
if await part_type_crud.get_by_name(db, pt_name) is None:
|
||||
await part_type_crud.create(db, name=pt_name)
|
||||
|
||||
# Superuser
|
||||
existing = await user_crud.get_by_email(db, settings.first_superuser_email)
|
||||
if existing is None:
|
||||
|
||||
Reference in new issue
Block a user