aggiunti trasferte, export excel, miglioramenti generali
This commit is contained in:
@@ -18,7 +18,15 @@ security = HTTPBearer(auto_error=False)
|
||||
|
||||
def is_admin_from_groups(groups: list[str]) -> bool:
|
||||
"""Check if user is admin based on Authelia groups"""
|
||||
return config.AUTHELIA_ADMIN_GROUP in groups
|
||||
admin_group = config.AUTHELIA_ADMIN_GROUP
|
||||
is_admin = admin_group in groups
|
||||
|
||||
# Case-insensitive check fallback (just in case)
|
||||
if not is_admin:
|
||||
is_admin = admin_group.lower() in [g.lower() for g in groups]
|
||||
|
||||
print(f"[Authelia] Admin Check: User Groups={groups}, Configured Admin Group='{admin_group}' -> Is Admin? {is_admin}")
|
||||
return is_admin
|
||||
|
||||
|
||||
def get_or_create_authelia_user(
|
||||
@@ -43,19 +51,19 @@ def get_or_create_authelia_user(
|
||||
# Only sync admin status from LLDAP, other roles managed by app admin
|
||||
if is_admin and user.role != "admin":
|
||||
user.role = "admin"
|
||||
user.updated_at = datetime.utcnow().isoformat()
|
||||
user.updated_at = datetime.utcnow()
|
||||
db.commit()
|
||||
db.refresh(user)
|
||||
elif not is_admin and user.role == "admin":
|
||||
# Removed from parking_admins group -> demote to employee
|
||||
user.role = "employee"
|
||||
user.updated_at = datetime.utcnow().isoformat()
|
||||
user.updated_at = datetime.utcnow()
|
||||
db.commit()
|
||||
db.refresh(user)
|
||||
# Update name if changed
|
||||
if user.name != name and name:
|
||||
user.name = name
|
||||
user.updated_at = datetime.utcnow().isoformat()
|
||||
user.updated_at = datetime.utcnow()
|
||||
db.commit()
|
||||
db.refresh(user)
|
||||
return user
|
||||
@@ -67,8 +75,8 @@ def get_or_create_authelia_user(
|
||||
name=name or email.split("@")[0],
|
||||
role="admin" if is_admin else "employee",
|
||||
password_hash=None, # No password for Authelia users
|
||||
created_at=datetime.utcnow().isoformat(),
|
||||
updated_at=datetime.utcnow().isoformat()
|
||||
created_at=datetime.utcnow(),
|
||||
updated_at=datetime.utcnow()
|
||||
)
|
||||
db.add(user)
|
||||
db.commit()
|
||||
|
||||
Reference in New Issue
Block a user