jumpserver/apps/assets/models/account.py

30 lines
1.2 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-15 10:31:57 +00:00
from common.db import fields
2022-08-16 03:09:30 +00:00
from .base import BaseAccount, AbsConnectivity
2022-07-12 02:54:23 +00:00
__all__ = ['Account']
2022-08-16 03:09:30 +00:00
class Account(BaseAccount, AbsConnectivity):
2022-08-15 10:31:57 +00:00
token = fields.EncryptTextField(blank=True, null=True, verbose_name=_('Token'))
privileged = models.BooleanField(verbose_name=_("Privileged account"), default=False)
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 07:45:03 +00:00
return '{}@{}'.format(self.username, self.asset.name)