1
0
Fork 0
forked from sr2/cloud-api
cloud-api/src/organisation/service.py

39 lines
834 B
Python
Raw Normal View History

2026-04-06 12:41:49 +01:00
"""
2026-05-28 14:23:36 +01:00
Reusable business logic functions for the organisation module
"""
2026-06-17 09:32:12 +01:00
from sqlalchemy.orm import Session
from src.organisation.models import Organisation as Org
from src.iam.models import Permission as Perm
async def add_default_org_permissions(
db: Session,
org_id: int,
):
default_org_permissions = [
1, # test_service res_one read
2, # test_service res_one create
10, # tor-bridge-service collector read
13, # tor-bridge-service samples read
]
org_model = db.get(Org, org_id)
if org_model is None:
print("Org not found while adding defaults")
return
for permission in default_org_permissions:
perm_model = db.get(Perm, permission)
if perm_model is None:
continue
if perm_model in org_model.permission_rel:
continue
org_model.permission_rel.append(perm_model)
db.flush()
db.commit()