From a69b762f131547a91f78ec78f8c7961b77d713f9 Mon Sep 17 00:00:00 2001 From: Bai Date: Sun, 4 Dec 2022 12:08:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=20ACL=20ActionChoices?= =?UTF-8?q?=20review,=20accept,=20reject=20=20=E5=BC=95=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/acls/migrations/0002_auto_20210926_1047.py | 5 +++-- apps/acls/models/login_acl.py | 2 +- apps/authentication/mixins.py | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/apps/acls/migrations/0002_auto_20210926_1047.py b/apps/acls/migrations/0002_auto_20210926_1047.py index 53ab54711..2429b7cea 100644 --- a/apps/acls/migrations/0002_auto_20210926_1047.py +++ b/apps/acls/migrations/0002_auto_20210926_1047.py @@ -30,10 +30,11 @@ def migrate_login_confirm(apps, schema_editor): if reviewers.count() == 0: continue data = { + 'user': user, 'name': f'{user.name}-{login_confirm} ({date_created})', 'created_by': instance.created_by, - 'action': LoginACL.ActionChoices.confirm, + 'action': 'confirm', 'rules': {'ip_group': ['*'], 'time_period': DEFAULT_TIME_PERIODS} } instance = login_acl_model.objects.create(**data) @@ -44,7 +45,7 @@ def migrate_ip_group(apps, schema_editor): login_acl_model = apps.get_model("acls", "LoginACL") updates = list() with transaction.atomic(): - for instance in login_acl_model.objects.exclude(action=LoginACL.ActionChoices.confirm): + for instance in login_acl_model.objects.exclude(action='confirm'): instance.rules = {'ip_group': instance.ip_group, 'time_period': DEFAULT_TIME_PERIODS} updates.append(instance) login_acl_model.objects.bulk_update(updates, ['rules', ]) diff --git a/apps/acls/models/login_acl.py b/apps/acls/models/login_acl.py index 1bc4a05a1..de6a73d1b 100644 --- a/apps/acls/models/login_acl.py +++ b/apps/acls/models/login_acl.py @@ -36,7 +36,7 @@ class LoginACL(BaseACL): return for acl in acl_qs: - if acl.is_action(LoginACL.ActionChoices.confirm) and \ + if acl.is_action(LoginACL.ActionChoices.review) and \ not acl.reviewers.exists(): continue ip_group = acl.rules.get('ip_group') diff --git a/apps/authentication/mixins.py b/apps/authentication/mixins.py index ec6d2e98d..f381edecf 100644 --- a/apps/authentication/mixins.py +++ b/apps/authentication/mixins.py @@ -333,13 +333,13 @@ class AuthACLMixin: return acl: LoginACL - if acl.is_action(acl.ActionChoices.allow): + if acl.is_action(acl.ActionChoices.accept): return if acl.is_action(acl.ActionChoices.reject): raise errors.LoginACLIPAndTimePeriodNotAllowed(user.username, request=self.request) - if acl.is_action(acl.ActionChoices.confirm): + if acl.is_action(acl.ActionChoices.review): self.request.session['auth_confirm_required'] = '1' self.request.session['auth_acl_id'] = str(acl.id) return @@ -354,7 +354,7 @@ class AuthACLMixin: acl = LoginACL.filter_acl(user).filter(id=acl_id).first() if not acl: return - if not acl.is_action(acl.ActionChoices.confirm): + if not acl.is_action(acl.ActionChoices.review): return self.get_ticket_or_create(acl) self.check_user_login_confirm()