From 057f034d4cd728c1bd0284e7c6b4a47739d5220d Mon Sep 17 00:00:00 2001
From: zhaoqingang <zhaoqg0118@163.com>
Date: 星期四, 12 十二月 2024 19:57:41 +0800
Subject: [PATCH] yonghu

---
 app/models/user_model.py |   36 ++++++++++++++++++++++++++----------
 1 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/app/models/user_model.py b/app/models/user_model.py
index a1d61dd..eeaf3e6 100644
--- a/app/models/user_model.py
+++ b/app/models/user_model.py
@@ -102,22 +102,32 @@
             # 'phoneNumber': self.phone_number
         }
 
-        if len(self.organizations) > 0:
-            json['dept'] = [organization.to_json() for organization in self.organizations]
+
+        # json['dept'] = [organization.to_json() for organization in self.organizations]
 
 
         json['groups'] = [group.to_dict() for group in self.groups]
 
-        roles = []
+
         # if len(self.roles) > 0:
-        roles = [role.to_json() for role in self.roles]
-        organization_roles = [role.to_json() for organization in self.organizations for role in
-                              organization.roles]
-        for role in organization_roles:
-            if role not in roles:
-                roles.append(role)
-        json['roles'] = roles
+        roles = {role.id: role.to_dict() for role in self.roles}
+        ogt_set = set()
+        for ogt in self.organizations:
+            if ogt.id in ogt_set:
+                continue
+            ogt_set.add(ogt.id)
+            for role in ogt.roles:
+                roles[role.id] = role.to_dict()
+            parent_ogt = ogt.parent
+            while parent_ogt:
+                if parent_ogt.id not in ogt_set:
+                    ogt_set.add(ogt.id)
+                    for role in ogt.roles:
+                        roles[role.id] = role.to_dict()
+                    parent_ogt = ogt.parent
+        json['roles'] = list(roles.values())
         return json
+
 
     def to_login_json(self):
         json = {
@@ -210,3 +220,9 @@
             "app_type": self.app_type,
             'status': self.status,
         }
+
+    def encrypted_password(self, password):
+        return cipher_suite.encrypt(password.encode("utf-8")).decode("utf-8")
+
+    def decrypted_password(self):
+        return cipher_suite.decrypt(self.password).decode("utf-8")
\ No newline at end of file

--
Gitblit v1.8.0