Merge branch 'feat/permissions' of gitea.aldon.fr:Mop/amap into feature/export-recap

This commit is contained in:
2026-03-05 20:58:05 +01:00
8 changed files with 164 additions and 59 deletions

View File

@@ -92,3 +92,19 @@ def delete_one(session: Session, _id: int) -> models.ProductorPublic:
session.delete(productor)
session.commit()
return result
def is_allowed(
session: Session,
user: models.User,
_id: int,
productor: models.ProductorCreate
) -> bool:
if not _id:
return productor.type in [r.name for r in user.roles]
statement = (
select(models.Productor)
.where(models.Productor.id == _id)
.where(models.Productor.type.in_([r.name for r in user.roles]))
.distinct()
)
return len(session.exec(statement).all()) > 0