mirror of https://github.com/jumpserver/jumpserver
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.2 KiB
40 lines
1.2 KiB
from django.db import models
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
from common.db.utils import Encryptor
|
|
from common.utils import get_logger
|
|
|
|
logger = get_logger(__name__)
|
|
|
|
|
|
class Preference(models.Model):
|
|
name = models.CharField(max_length=128, verbose_name=_("Name"))
|
|
category = models.CharField(max_length=128, verbose_name=_('Category'))
|
|
value = models.TextField(verbose_name=_("Value"), null=True, blank=True)
|
|
encrypted = models.BooleanField(default=False, verbose_name=_('Encrypted'))
|
|
user = models.ForeignKey(
|
|
'users.User', verbose_name=_("Users"), related_name='preferences', on_delete=models.CASCADE
|
|
)
|
|
|
|
def __str__(self):
|
|
return f'{self.name}({self.user.username})'
|
|
|
|
@classmethod
|
|
def encrypt(cls, value):
|
|
return Encryptor(value).encrypt()
|
|
|
|
@classmethod
|
|
def decrypt(cls, value):
|
|
return Encryptor(value).decrypt()
|
|
|
|
@property
|
|
def decrypt_value(self):
|
|
if self.encrypted:
|
|
return self.decrypt(self.value)
|
|
return self.value
|
|
|
|
class Meta:
|
|
db_table = "users_preference"
|
|
verbose_name = _("Preference")
|
|
unique_together = [('name', 'user_id')]
|