Explorar el Código

refactor(orm): add __str__ for Moderator model

Librellium hace 14 horas
padre
commit
fe3d952971
Se han modificado 1 ficheros con 17 adiciones y 0 borrados
  1. 17 0
      anonflow/database/orm.py

+ 17 - 0
anonflow/database/orm.py

@@ -45,6 +45,23 @@ class Moderator(Base):
 
     user = relationship("User", back_populates="moderator")
 
+    def __str__(self):
+        permissions = []
+        if bool(self.is_root):
+            permissions.append("root")
+        else:
+            for permission in dir(self):
+                if (
+                    permission.startswith("can_")
+                    and getattr(self, permission, False)
+                ):
+                    permissions.append(permission)
+
+        return (
+            f"Moderator user_id={self.user_id} "
+            f"permissions={','.join(permissions)}"
+        )
+
 
 class User(Base):
     __tablename__ = "users"