perf: 优化Migration,删掉原来的 content type (#7835)

Co-authored-by: ibuler <ibuler@qq.com>
Co-authored-by: Jiangjie.Bai <32935519+BaiJiangJie@users.noreply.github.com>
pull/7838/head
fit2bot 2022-03-14 17:10:34 +08:00 committed by GitHub
parent e9deb6fc7a
commit df51c82cfd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 364 additions and 411 deletions

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:a885732955761c2942989a3e93751709e2be4ec75504bd009406671b93e0bfda
size 107544
oid sha256:675f93d2cc6b2049fdafc7f6b70edb8f73bbe132de9b91e98f2ec7acb2e89620
size 104134

File diff suppressed because it is too large Load Diff

View File

@ -11,7 +11,6 @@ exclude_permissions = (
# ('App', 'Model', 'Action', 'Resource') Model 和 Resource 可能不同
# users.add_user
('auth', '*', '*', '*'),
('authentication', 'loginconfirmsetting', '*', '*'),
('captcha', '*', '*', '*'),
('contenttypes', '*', '*', '*'),
('django_cas_ng', '*', '*', '*'),
@ -40,9 +39,6 @@ exclude_permissions = (
('assets', 'gathereduser', 'add,delete,change', 'gathereduser'),
('assets', 'accountbackupplanexecution', 'delete,change', 'accountbackupplanexecution'),
('assets', 'authbook', 'add', 'authbook'),
('perms', 'databaseapppermission', '*', '*'),
('perms', 'k8sapppermission', '*', '*'),
('perms', 'remoteapppermission', '*', '*'),
('perms', 'userassetgrantedtreenoderelation', '*', '*'),
('perms', 'usergrantedmappingnode', '*', '*'),
('perms', 'permnode', '*', '*'),

View File

@ -0,0 +1,30 @@
# Generated by Django 3.1.14 on 2022-03-14 07:25
from django.db import migrations
def migrate_old_permissions(apps, *args):
ContentType = apps.get_model('rbac', 'ContentType')
content_type_delete_required = [
('common', 'permission'),
('applications', 'databaseapp'),
('applications', 'k8sapp'),
('applications', 'remoteapp'),
('perms', 'databaseapppermission'),
('perms', 'k8sapppermission'),
('perms', 'remoteapppermission'),
('authentication', 'loginconfirmsetting'),
]
for app, model in content_type_delete_required:
ContentType.objects.filter(app_label=app, model=model).delete()
class Migration(migrations.Migration):
dependencies = [
('rbac', '0006_auto_20220310_0616'),
]
operations = [
migrations.RunPython(migrate_old_permissions)
]

View File

@ -123,28 +123,30 @@ xpack_nodes = [
def _sort_action(node):
value = 0
if node.isParent:
return ['zz', 0]
if 'view' in node.title:
value += 2
elif 'add' in node.title:
value += 4
elif 'change' in node.title:
value += 6
elif 'delete' in node.title:
value += 8
else:
value += 10
return value
action_resource = node.title.split('.')[-1]
action, resource = action_resource.split('_', 2)
action_value_mapper = {
'view': 2,
'add': 4,
'change': 6,
'delete': 8
}
v = action_value_mapper.get(action, 10)
return [resource, v]
def sort_nodes(node):
value = 0
value = []
if node.isParent:
value += 50
value.append(50)
else:
value += _sort_action(node)
value.append(0)
value.extend(_sort_action(node))
return value

View File

@ -12,6 +12,6 @@ class Migration(migrations.Migration):
operations = [
migrations.AlterModelOptions(
name='setting',
options={'permissions': [('change_email', 'Can change email setting'), ('change_auth', 'Can change auth setting'), ('change_systemmsgsubscription', 'Can sys msg sub setting'), ('change_sms', 'Can change sms setting'), ('change_security', 'Can change security setting'), ('change_clean', 'Can change clean setting'), ('change_interface', 'Can change interface setting'), ('change_license', 'Can change license setting'), ('change_terminal', 'Can change terminal setting'), ('change_other', 'Can change other setting')], 'verbose_name': 'System setting'},
options={'permissions': [('change_email', 'Can change email setting'), ('change_auth', 'Can change auth setting'), ('change_systemmsgsubscription', 'Can change system msg sub setting'), ('change_sms', 'Can change sms setting'), ('change_security', 'Can change security setting'), ('change_clean', 'Can change clean setting'), ('change_interface', 'Can change interface setting'), ('change_license', 'Can change license setting'), ('change_terminal', 'Can change terminal setting'), ('change_other', 'Can change other setting')], 'verbose_name': 'System setting'},
),
]

View File

@ -141,7 +141,7 @@ class Setting(models.Model):
permissions = [
('change_email', _('Can change email setting')),
('change_auth', _('Can change auth setting')),
('change_systemmsgsubscription', _('Can sys msg sub setting')),
('change_systemmsgsubscription', _('Can change system msg sub setting')),
('change_sms', _('Can change sms setting')),
('change_security', _('Can change security setting')),
('change_clean', _('Can change clean setting')),