Skip to content

Commit

Permalink
Merge pull request #234 from zhu327/hotfix_update_template_auth
Browse files Browse the repository at this point in the history
Hotfix update template auth
  • Loading branch information
zhu327 authored Oct 8, 2021
2 parents c9bf979 + 641e9d2 commit 2e84ccf
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion saas/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.5.4
1.5.5
12 changes: 11 additions & 1 deletion saas/backend/service/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from backend.apps.template.models import PermTemplate, PermTemplatePolicyAuthorized, PermTemplatePreGroupSync
from backend.common.error_codes import error_codes
from backend.common.time import PERMANENT_SECONDS
from backend.component import iam

from .models import Policy, Subject, SystemCounter
Expand Down Expand Up @@ -117,7 +118,7 @@ def update_template_auth(self, subject: Subject, template_id: int, policies: Lis
"""
authorized_template = PermTemplatePolicyAuthorized.objects.get_by_subject_template(subject, template_id)
system_id = authorized_template.system_id
policy_list = PolicyList(parse_obj_as(List[Policy], authorized_template.data["actions"]))
policy_list = self._convert_template_actions_to_policy_list(authorized_template.data["actions"])

# 查询subject的后端权限信息
backend_policy_list = new_backend_policy_list_by_subject(system_id, subject, template_id)
Expand All @@ -140,6 +141,15 @@ def update_template_auth(self, subject: Subject, template_id: int, policies: Lis
system_id, subject.type, subject.id, template_id, [p.to_backend_dict() for p in policies]
)

def _convert_template_actions_to_policy_list(self, actions: List[Dict]) -> PolicyList:
"""转换模板的授权的actions到PolicyList, 兼容过期时间为空的情况"""
policies = []
for action in actions:
if "expired_at" not in action or not action["expired_at"]:
action["expired_at"] = PERMANENT_SECONDS
policies.append(Policy.parse_obj(action))
return PolicyList(policies)

def list_system_counter_by_subject(self, subject: Subject) -> List[SystemCounter]:
"""
查询subject有权限的系统-模板数量信息
Expand Down
4 changes: 4 additions & 0 deletions saas/resources/version_log/V1.5.5_2021-10-08.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# V1.5.5 版本更新日志

### 缺陷修复
* 用户组更新模板授权报错
4 changes: 4 additions & 0 deletions saas/resources/version_log/V1.5.5_2021-10-08_en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# V1.5.5 ChangeLog

### Bug Fixes
* User group update template authorization error

0 comments on commit 2e84ccf

Please sign in to comment.