clearml-server/apiserver/database/model/company.py

39 lines
1.2 KiB
Python
Raw Normal View History

2019-12-14 21:33:04 +00:00
from mongoengine import (
Document,
EmbeddedDocument,
EmbeddedDocumentField,
StringField,
Q,
BooleanField,
DateTimeField,
)
2019-06-10 21:24:35 +00:00
2021-01-05 14:28:49 +00:00
from apiserver.database import Database, strict
from apiserver.database.fields import StrippedStringField
from apiserver.database.model import DbModelMixin
2019-06-10 21:24:35 +00:00
2019-12-14 21:33:04 +00:00
class ReportStatsOption(EmbeddedDocument):
enabled = BooleanField(default=False) # opt-in for statistics reporting
enabled_version = StringField() # server version when enabled
enabled_time = DateTimeField() # time when enabled
enabled_user = StringField() # ID of user who enabled
2019-06-10 21:24:35 +00:00
class CompanyDefaults(EmbeddedDocument):
cluster = StringField()
2019-12-14 21:33:04 +00:00
stats_option = EmbeddedDocumentField(ReportStatsOption, default=ReportStatsOption)
2019-06-10 21:24:35 +00:00
class Company(DbModelMixin, Document):
2019-12-14 21:33:04 +00:00
meta = {"db_alias": Database.backend, "strict": strict}
2019-06-10 21:24:35 +00:00
id = StringField(primary_key=True)
name = StrippedStringField(unique=True, min_length=3)
2019-12-14 21:33:04 +00:00
defaults = EmbeddedDocumentField(CompanyDefaults, default=CompanyDefaults)
2019-06-10 21:24:35 +00:00
@classmethod
def _prepare_perm_query(cls, company, allow_public=False):
""" Override default behavior since a 'company' constraint is not supported for this document... """
return Q()