Files
Django/jituan/management/commands/seed_gvsdsdk_permissions.py

50 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""补齐 gvsdsdk 权限码(可重复执行)。"""
import uuid
from django.core.management.base import BaseCommand
from django.utils import timezone
from gvsdsdk.models import Permission
# (PermCode, PermName, PermDesc, PermCategory)
EXTRA_PERMISSIONS = [
(
'dsks666',
'打手接单考试管理',
'配置各俱乐部考试开关、抽题规则与题库(小程序配置-打手接单考试)',
'小程序配置',
),
(
'sfbq666',
'身份装饰标签管理',
'管理小程序身份装饰标签(与用户管理-身份装饰标签菜单对应)',
'用户管理',
),
]
class Command(BaseCommand):
help = '写入 gvsdsdk Permission 表缺失的权限码(如 sfbq666'
def handle(self, *args, **options):
sample = Permission.objects.filter(PermStatus=1).first()
tenant_uuid = sample.TenantUUID if sample else uuid.UUID('00000000-0000-0000-0000-000000000001').bytes
created = 0
for code, name, desc, category in EXTRA_PERMISSIONS:
if Permission.objects.filter(PermCode=code).exists():
self.stdout.write(f' 已存在: {code}')
continue
Permission.objects.create(
PermUUID=uuid.uuid4().bytes,
TenantUUID=tenant_uuid,
PermCode=code,
PermName=name,
PermDesc=desc,
PermCategory=category,
PermStatus=1,
CreateTime=timezone.now(),
)
created += 1
self.stdout.write(self.style.SUCCESS(f' 新增权限: {code} - {name}'))
self.stdout.write(self.style.SUCCESS(f'完成,新增 {created} 条权限'))