From e6c5e89f09637b8d9ebca6895d781663f12646d6 Mon Sep 17 00:00:00 2001 From: zhaoqingang <zhaoqg0118@163.com> Date: 星期二, 17 十二月 2024 16:43:55 +0800 Subject: [PATCH] dify 文档智能 --- app/models/user_model.py | 42 ++++++++++++++++++++++++++++++++---------- 1 files changed, 32 insertions(+), 10 deletions(-) diff --git a/app/models/user_model.py b/app/models/user_model.py index a1d61dd..dcbb612 100644 --- a/app/models/user_model.py +++ b/app/models/user_model.py @@ -39,6 +39,7 @@ sex = Column(String(1)) permission = Column(String(16), default="general") age = Column(Integer) + sync_flag = Column(String(36)) created_at = Column(DateTime, default=datetime.now()) updated_at = Column(DateTime, default=datetime.now(), onupdate=datetime.now()) @@ -102,22 +103,36 @@ # '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 + print(ogt.id) + 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 parent_ogt.roles: + roles[role.id] = role.to_dict() + parent_ogt = parent_ogt.parent + else: + break + + json['roles'] = list(roles.values()) return json + def to_login_json(self): json = { @@ -210,3 +225,10 @@ "app_type": self.app_type, 'status': self.status, } + @staticmethod + def encrypted_password(password): + return cipher_suite.encrypt(password.encode("utf-8")).decode("utf-8") + + @staticmethod + def decrypted_password(password): + return cipher_suite.decrypt(password).decode("utf-8") \ No newline at end of file -- Gitblit v1.8.0