From a748f5d57d2ae6e489d18c90a2eb996e84cd96fa Mon Sep 17 00:00:00 2001 From: feng626 <1304903146@qq.com> Date: Thu, 11 Aug 2022 17:39:44 +0800 Subject: [PATCH] account template model --- .../migrations/0107_delete_accounttemplate.py | 16 ++++++++ .../assets/migrations/0108_accounttemplate.py | 39 +++++++++++++++++++ apps/assets/models/account.py | 13 +++++-- 3 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 apps/assets/migrations/0107_delete_accounttemplate.py create mode 100644 apps/assets/migrations/0108_accounttemplate.py diff --git a/apps/assets/migrations/0107_delete_accounttemplate.py b/apps/assets/migrations/0107_delete_accounttemplate.py new file mode 100644 index 000000000..a322dc421 --- /dev/null +++ b/apps/assets/migrations/0107_delete_accounttemplate.py @@ -0,0 +1,16 @@ +# Generated by Django 3.2.13 on 2022-08-11 09:34 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('assets', '0106_auto_20220811_1358'), + ] + + operations = [ + migrations.DeleteModel( + name='AccountTemplate', + ), + ] diff --git a/apps/assets/migrations/0108_accounttemplate.py b/apps/assets/migrations/0108_accounttemplate.py new file mode 100644 index 000000000..ede37eb1b --- /dev/null +++ b/apps/assets/migrations/0108_accounttemplate.py @@ -0,0 +1,39 @@ +# Generated by Django 3.2.13 on 2022-08-11 09:34 + +import assets.models.base +import common.db.fields +from django.db import migrations, models +import uuid + + +class Migration(migrations.Migration): + + dependencies = [ + ('assets', '0107_delete_accounttemplate'), + ] + + operations = [ + migrations.CreateModel( + name='AccountTemplate', + fields=[ + ('org_id', models.CharField(blank=True, db_index=True, default='', max_length=36, verbose_name='Organization')), + ('connectivity', models.CharField(choices=[('unknown', 'Unknown'), ('ok', 'Ok'), ('failed', 'Failed')], default='unknown', max_length=16, verbose_name='Connectivity')), + ('date_verified', models.DateTimeField(null=True, verbose_name='Date verified')), + ('id', models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False)), + ('name', models.CharField(max_length=128, verbose_name='Name')), + ('username', models.CharField(blank=True, db_index=True, max_length=128, verbose_name='Username')), + ('password', common.db.fields.EncryptCharField(blank=True, max_length=256, null=True, verbose_name='Password')), + ('private_key', common.db.fields.EncryptTextField(blank=True, null=True, verbose_name='SSH private key')), + ('public_key', common.db.fields.EncryptTextField(blank=True, null=True, verbose_name='SSH public key')), + ('comment', models.TextField(blank=True, verbose_name='Comment')), + ('date_created', models.DateTimeField(auto_now_add=True, verbose_name='Date created')), + ('date_updated', models.DateTimeField(auto_now=True, verbose_name='Date updated')), + ('created_by', models.CharField(max_length=128, null=True, verbose_name='Created by')), + ('type', models.CharField(choices=[('common', 'Common user'), ('admin', 'Admin user')], default='common', max_length=16, verbose_name='Type')), + ], + options={ + 'verbose_name': 'Account Template', + }, + bases=(models.Model, assets.models.base.AuthMixin), + ), + ] diff --git a/apps/assets/models/account.py b/apps/assets/models/account.py index 654ce2cf5..ef2531fb2 100644 --- a/apps/assets/models/account.py +++ b/apps/assets/models/account.py @@ -5,7 +5,6 @@ from simple_history.models import HistoricalRecords from common.db.models import JMSBaseModel from .base import BaseUser, AbsConnectivity - __all__ = ['Account'] @@ -33,5 +32,13 @@ class Account(BaseUser, AbsConnectivity): return '{}@{}'.format(self.username, self.asset.hostname) -class AccountTemplate(JMSBaseModel): - pass +class AccountTemplate(BaseUser, AbsConnectivity): + type = models.CharField( + max_length=16, choices=Account.Type.choices, default=Account.Type.common, verbose_name=_("Type") + ) + + class Meta: + verbose_name = _('Account Template') + + def __str__(self): + return '{}'.format(self.username)