jumpserver/apps/assets/models/account.py

38 lines
1.3 KiB
Python
Raw Normal View History

2022-07-12 02:54:23 +00:00
from django.db import models
from django.utils.translation import gettext_lazy as _
from simple_history.models import HistoricalRecords
2022-08-05 10:31:57 +00:00
from common.db.models import JMSBaseModel
2022-07-14 02:56:09 +00:00
from .base import BaseUser, AbsConnectivity
2022-07-12 02:54:23 +00:00
__all__ = ['Account']
2022-08-11 06:05:45 +00:00
class Account(BaseUser, AbsConnectivity):
2022-07-14 02:56:09 +00:00
class Type(models.TextChoices):
common = 'common', _('Common user')
admin = 'admin', _('Admin user')
type = models.CharField(max_length=16, choices=Type.choices, default=Type.common, verbose_name=_("Type"))
2022-07-12 02:54:23 +00:00
asset = models.ForeignKey('assets.Asset', on_delete=models.CASCADE, verbose_name=_('Asset'))
2022-07-15 10:57:52 +00:00
version = models.IntegerField(default=0, verbose_name=_('Version'))
2022-07-12 02:54:23 +00:00
history = HistoricalRecords()
class Meta:
verbose_name = _('Account')
unique_together = [('username', 'asset')]
permissions = [
2022-07-27 08:51:39 +00:00
('view_accountsecret', _('Can view asset account secret')),
('change_accountsecret', _('Can change asset account secret')),
('view_historyaccount', _('Can view asset history account')),
('view_historyaccountsecret', _('Can view asset history account secret')),
2022-07-12 02:54:23 +00:00
]
2022-07-13 08:36:49 +00:00
def __str__(self):
2022-08-11 06:05:45 +00:00
return '{}@{}'.format(self.username, self.asset.hostname)
2022-08-05 10:31:57 +00:00
class AccountTemplate(JMSBaseModel):
pass