Skip to content

Commit

Permalink
Merge pull request #497 from nannan00/ft_sync_org_without_del
Browse files Browse the repository at this point in the history
feat(sync org): not delete backend user and department
  • Loading branch information
nannan00 authored Dec 8, 2021
2 parents 7347d33 + 8e6093b commit 88260b5
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 28 deletions.
8 changes: 8 additions & 0 deletions release.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# V1.5.16

### 功能优化
* 组织架构同步时不删除后台用户和部门

### 缺陷修复
* 锁定依赖包typing-extensions版本,避免自动更新最新版导致部署失败

# V1.5.15

### 缺陷修复
Expand Down
2 changes: 1 addition & 1 deletion saas/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.5.15
1.5.16
2 changes: 1 addition & 1 deletion saas/backend/apps/role/audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def object_id(self):
def object_name(self):
username = self.request.user.username
user = User.objects.filter(username=username).only("display_name").first()
return user.display_name if user else ""
return user.display_name if user else username


class RoleMemberUpdateAuditProvider(BaseRoleDataProvider):
Expand Down
2 changes: 1 addition & 1 deletion saas/backend/apps/subject/audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def object_name(self):

if self.subject.type == SubjectType.USER.value:
user = User.objects.filter(username=self.subject.id).first()
return user.display_name if user else ""
return user.display_name if user else self.subject.id

return ""

Expand Down
30 changes: 17 additions & 13 deletions saas/backend/biz/org_sync/iam_department.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,24 @@ def created_handler(self):

def deleted_handler(self):
"""后台需要删除的部门处理"""
db_dept_set = {str(i.id) for i in self.db_departments}
deleted_depts = [
{"type": "department", "id": i["id"]} for i in self.backend_departments if i["id"] not in db_dept_set
]

if not deleted_depts:
return
# db_dept_set = {str(i.id) for i in self.db_departments}
# deleted_depts = [
# {"type": "department", "id": i["id"]} for i in self.backend_departments if i["id"] not in db_dept_set
# ]
#
# if not deleted_depts:
# return
#
# iam.delete_subjects_by_auto_paging(deleted_depts)
#
# organization_logger.info(
# f"delete departments by sync task, the length of departments: {len(deleted_depts)} "
# f"the detail of departments: {deleted_depts}"
# )

iam.delete_subjects_by_auto_paging(deleted_depts)

organization_logger.info(
f"delete departments by sync task, the length of departments: {len(deleted_depts)} "
f"the detail of departments: {deleted_depts}"
)
# Note: 对于SaaS已删除部门,由于不确定是用户管理本身有bug导致的还是部门真实不存在了,所以为了避免影响部门权限,这里将不删除后端部门
# 后续将会通过SaaS标记已删除部门,然后发起审批流程等方式再进行后端用户权限的删除
pass

def sync_to_iam_backend(self):
"""同步IAM后台 相关变更"""
Expand Down
27 changes: 15 additions & 12 deletions saas/backend/biz/org_sync/iam_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,21 @@ def created_handler(self):

def deleted_handler(self):
"""后台需要删除的用户处理"""
db_user_set = {i.username for i in self.db_users}
deleted_users = [{"type": "user", "id": i["id"]} for i in self.backend_users if i["id"] not in db_user_set]

if not deleted_users:
return

iam.delete_subjects_by_auto_paging(deleted_users)

organization_logger.info(
f"delete users by sync task, the length of users: {len(deleted_users)} "
f"the detail of users: {deleted_users}"
)
# db_user_set = {i.username for i in self.db_users}
# deleted_users = [{"type": "user", "id": i["id"]} for i in self.backend_users if i["id"] not in db_user_set]
#
# if not deleted_users:
# return
#
# iam.delete_subjects_by_auto_paging(deleted_users)
#
# organization_logger.info(
# f"delete users by sync task, the length of users: {len(deleted_users)} "
# f"the detail of users: {deleted_users}"
# )
# Note: 对于SaaS已删除用户,由于不确定是用户管理本身有bug导致的还是用户真实不存在了,所以为了避免影响用户权限,这里将不删除后端用户
# 后续将会通过SaaS标记已删除用户,然后发起审批流程等方式再进行后端用户权限的删除
pass

def sync_to_iam_backend(self):
"""同步IAM后台 相关变更"""
Expand Down
2 changes: 2 additions & 0 deletions saas/backend/biz/subject.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ def _to_subject_infos(self, subjects: List[Subject]) -> List[SubjectInfo]:
# 遍历填充相关字段
for subject in subjects:
subject_info = SubjectInfo.parse_obj(subject)
# 默认值
subject_info.name = subject.id
subject_info.full_name = subject.id

obj = object_dict.get((subject.type, subject.id), None)
if not obj:
Expand Down
7 changes: 7 additions & 0 deletions saas/resources/version_log/V1.5.16_2021-12-08.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# V1.5.16 版本更新日志

### 功能优化
* 组织架构同步时不删除后台用户和部门

### 缺陷修复
* 锁定依赖包typing-extensions版本,避免自动更新最新版导致部署失败
7 changes: 7 additions & 0 deletions saas/resources/version_log/V1.5.16_2021-12-08_en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# V1.5.16 ChangeLog

### Optimization Updates
* Do not delete back-end users and departments when the organizational structure is synchronized

### Bug Fixes
* Lock the dependency package typing-extensions version to avoid deployment failure caused by automatic update to the latest version

0 comments on commit 88260b5

Please sign in to comment.