From 9932e7eaddaf4fc6645904575a437b097e919a4b Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 25 May 2023 18:42:54 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E8=B5=84=E4=BA=A7=E6=8E=88=E6=9D=83?= =?UTF-8?q?=E6=94=AF=E6=8C=81=20delete=20=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/acls/models/base.py | 25 +++++++++++++++++++ apps/authentication/api/connection_token.py | 2 +- apps/locale/zh/LC_MESSAGES/django.po | 4 +-- apps/perms/const.py | 5 ++-- .../migrations/0034_auto_20230525_1734.py | 18 +++++++++++++ 5 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 apps/perms/migrations/0034_auto_20230525_1734.py diff --git a/apps/acls/models/base.py b/apps/acls/models/base.py index 80f0affe6..4b05f887c 100644 --- a/apps/acls/models/base.py +++ b/apps/acls/models/base.py @@ -61,3 +61,28 @@ class UserAssetAccountBaseACL(BaseACL, OrgModelMixin): class Meta(BaseACL.Meta): unique_together = ('name', 'org_id') abstract = True + + @classmethod + def filter_queryset(cls, user=None, asset=None, account=None, account_username=None, **kwargs): + queryset = cls.objects.all() + org_id = None + + if user: + q = cls.users.get_filter_q(user) + queryset = queryset.filter(q) + if asset: + org_id = asset.org_id + q = cls.assets.get_filter_q(asset) + queryset = queryset.filter(q) + if account and not account_username: + account_username = account.username + if account_username: + q = models.Q(accounts__contains=account_username) | \ + models.Q(accounts__contains='*') | \ + models.Q(accounts__contains='@ALL') + queryset = queryset.filter(q) + if org_id: + kwargs['org_id'] = org_id + if kwargs: + queryset = queryset.filter(**kwargs) + return queryset.distinct() diff --git a/apps/authentication/api/connection_token.py b/apps/authentication/api/connection_token.py index 0bc69b025..7c1bbb3f8 100644 --- a/apps/authentication/api/connection_token.py +++ b/apps/authentication/api/connection_token.py @@ -317,7 +317,7 @@ class ConnectionTokenViewSet(ExtraActionApiMixin, RootOrgViewMixin, JMSModelView if acl.is_action(acl.ActionChoices.accept): return if acl.is_action(acl.ActionChoices.reject): - msg = _('ACL action is reject') + msg = _('ACL action is reject: {}({})'.format(acl.name, acl.id)) raise JMSException(code='acl_reject', detail=msg) if acl.is_action(acl.ActionChoices.review): if not self.request.query_params.get('create_ticket'): diff --git a/apps/locale/zh/LC_MESSAGES/django.po b/apps/locale/zh/LC_MESSAGES/django.po index d6ba4d94f..217772011 100644 --- a/apps/locale/zh/LC_MESSAGES/django.po +++ b/apps/locale/zh/LC_MESSAGES/django.po @@ -1856,7 +1856,7 @@ msgstr "删除" #: audits/const.py:15 perms/const.py:13 msgid "Upload" -msgstr "上传文件" +msgstr "上传" #: audits/const.py:16 msgid "Rename" @@ -1868,7 +1868,7 @@ msgstr "建立软链接" #: audits/const.py:18 perms/const.py:14 msgid "Download" -msgstr "下载文件" +msgstr "下载" #: audits/const.py:22 rbac/tree.py:228 msgid "View" diff --git a/apps/perms/const.py b/apps/perms/const.py index 21fe2d763..70006053e 100644 --- a/apps/perms/const.py +++ b/apps/perms/const.py @@ -14,6 +14,7 @@ class ActionChoices(BitChoices): download = bit(3), _("Download") copy = bit(4), _("Copy") paste = bit(5), _("Paste") + delete = bit(6), _("Delete") @classmethod def is_tree(cls): @@ -23,13 +24,13 @@ class ActionChoices(BitChoices): def branches(cls): return ( cls.connect, - (_("Transfer"), [cls.upload, cls.download]), + (_("Transfer"), [cls.upload, cls.download, cls.delete]), (_("Clipboard"), [cls.copy, cls.paste]), ) @classmethod def transfer(cls): - return cls.upload | cls.download + return cls.upload | cls.download | cls.delete @classmethod def clipboard(cls): diff --git a/apps/perms/migrations/0034_auto_20230525_1734.py b/apps/perms/migrations/0034_auto_20230525_1734.py new file mode 100644 index 000000000..f1e842315 --- /dev/null +++ b/apps/perms/migrations/0034_auto_20230525_1734.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.17 on 2023-05-25 09:34 + +from django.db import migrations + + +def migrate_asset_permission_delete_perm(apps, *args): + asset_permission_cls = apps.get_model('perms', 'AssetPermission') + asset_permission_cls.objects.filter(actions__gte=31).update(actions=63) + + +class Migration(migrations.Migration): + dependencies = [ + ('perms', '0033_auto_20221220_1956'), + ] + + operations = [ + migrations.RunPython(migrate_asset_permission_delete_perm) + ]