Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix update template auth #234

Merged
merged 2 commits into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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