class Grant(BaseModel): __tablename__ = "grants" user_id = db.Column(UUIDType(binary=False), db.ForeignKey("users.id")) user = db.relationship("User", backref="grants") role = db.Column(db.Enum(RoleNames), nullable=False, unique=False) team_id = db.Column(UUIDType(binary=False), db.ForeignKey("teams.id")) team = db.relationship("Team", backref="grants") def __repr__(self): return "<Grant '{0}' is {1} of {2}>".format(self.user.name, self.role.value, self.team.name)
class News(BaseModel): __tablename__ = "news" title = db.Column(db.String(100), nullable=False) message = db.Column(db.String(), nullable=False) users = db.relationship( "User", backref=db.backref("news", uselist=True), secondary="users_news" )
class Check(BaseModel): __tablename__ = "checks" __repr_fields__ = ("name",) name = db.Column(db.String(255), nullable=False) source_id = db.Column( UUIDType(binary=False), db.ForeignKey("sources.id"), nullable=False ) source = db.relationship( "Source", backref=db.backref("source_checks", uselist=True) ) type = db.Column(db.String(255), nullable=False) parameters = db.Column(MutableDict.as_mutable(JSONType), default={}, nullable=True) variables = db.relationship("Variable", backref="check")
class Team(BaseModel): __tablename__ = "teams" __repr_fields__ = ("name", ) name = db.Column(db.String(255), nullable=False) sources = db.relationship("Source", back_populates="team") rules = db.relationship("Rule", back_populates="team") configs = db.relationship("Config", back_populates="team") worst = db.relationship("Worst", back_populates="team") grants = association_proxy("grants", "user") variables = db.relationship( "Variable", primaryjoin="and_(Team.id==Variable.team_id, " "Variable.rule_id==None, " "Variable.source_id==None, " "Variable.check_id==None)", backref="team", ) metas = db.Column(EncryptedDict, default={}, nullable=True) @property def members(self): return [ grant.user for grant in self.grants if grant.role.value == "member" ] @property def editors(self): return [ grant.user for grant in self.grants if grant.role.value == "editor" ] @property def managers(self): return [ grant.user for grant in self.grants if grant.role.value == "manager" ] @property def kafka_topic(self): return "".join(e for e in self.name if e.isalnum()).lower()
class Config(BaseModel): __tablename__ = "configs" __repr_fields__ = ("id", "team") team_id = db.Column(UUIDType(binary=False), db.ForeignKey("teams.id"), nullable=False) team = db.relationship("Team", back_populates="configs") data = db.Column(MutableDict.as_mutable(JSONType), default={}, nullable=False)
class Source(BaseModel): __tablename__ = "sources" __repr_fields__ = ("name", "plugin") name = db.Column(db.String(255), nullable=False) plugin = db.Column(db.String(255), nullable=False) configuration = db.Column(EncryptedDict, default={}, nullable=True) checks = db.relationship("Check", back_populates="source") team_id = db.Column(UUIDType(binary=False), db.ForeignKey("teams.id"), nullable=True) team = db.relationship("Team", back_populates="sources") variables = db.relationship( "Variable", primaryjoin="and_(Source.id==Variable.source_id, " "Variable.rule_id==None, " "Variable.check_id==None)", backref="source", )
class Worst(BaseModel): __tablename__ = "worst" __table_args__ = (UniqueConstraint("team_id", "label", "date", "period", name="team_label_date_period_uc"), ) __repr_fields__ = ("team", "label", "date", "period") team_id = db.Column(UUIDType(binary=False), db.ForeignKey("teams.id"), nullable=False) team = db.relationship("Team", back_populates="worst") date = db.Column(db.DateTime(timezone=True), nullable=False) label = db.Column(db.String(255), nullable=False) period = db.Column(db.Enum(Periods), nullable=False, unique=False) data = db.Column(MutableDict.as_mutable(JSONType), default={}, nullable=False)