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

83 lines
2.1 KiB
Python
Raw Normal View History

2019-06-10 21:24:35 +00:00
from mongoengine import (
StringField,
EmbeddedDocument,
EmbeddedDocumentListField,
EmailField,
DateTimeField,
2024-03-18 13:49:42 +00:00
BooleanField,
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.model import DbModelMixin
from apiserver.database.model.base import AuthDocument
from apiserver.database.utils import get_options
2019-06-10 21:24:35 +00:00
class Entities(object):
company = "company"
task = "task"
user = "user"
model = "model"
class Role(object):
system = "system"
""" Internal system component """
root = "root"
""" Root admin (person) """
admin = "admin"
""" Company administrator """
superuser = "superuser"
""" Company super user """
user = "user"
""" Company user """
annotator = "annotator"
""" Annotator with limited access"""
guest = "guest"
""" Guest user. Read Only."""
2019-06-10 21:24:35 +00:00
@classmethod
def get_system_roles(cls) -> set:
return {cls.system, cls.root}
@classmethod
def get_company_roles(cls) -> set:
return set(get_options(cls)) - cls.get_system_roles()
class Credentials(EmbeddedDocument):
meta = {"strict": False}
2019-06-10 21:24:35 +00:00
key = StringField(required=True)
secret = StringField(required=True)
label = StringField()
last_used = DateTimeField()
last_used_from = StringField()
2019-06-10 21:24:35 +00:00
class User(DbModelMixin, AuthDocument):
meta = {"db_alias": Database.auth, "strict": strict}
2019-06-10 21:24:35 +00:00
id = StringField(primary_key=True)
name = StringField()
2019-06-10 21:24:35 +00:00
created = DateTimeField()
""" User auth entry creation time """
validated = DateTimeField()
""" Last validation (login) time """
role = StringField(required=True, choices=get_options(Role), default=Role.user)
""" User role """
company = StringField(required=True)
""" Company this user belongs to """
credentials = EmbeddedDocumentListField(Credentials, default=list)
""" Credentials generated for this user """
2021-01-05 16:34:46 +00:00
email = EmailField(unique=True, sparse=True)
2019-06-10 21:24:35 +00:00
""" Email uniquely identifying the user """
2024-03-18 13:49:42 +00:00
autocreated = BooleanField(default=False)
""" Set to true if the user was auto created based on config settings"""