示例#1
0
class CVEGroupEntry(db.Model):

    __tablename__ = 'cve_group_entry'
    __versioned__ = {}

    id = db.Column(db.Integer(),
                   index=True,
                   unique=True,
                   primary_key=True,
                   autoincrement=True)
    group_id = db.Column(db.Integer(),
                         db.ForeignKey('cve_group.id', ondelete="CASCADE"),
                         nullable=False)
    cve_id = db.Column(db.String(15),
                       db.ForeignKey('cve.id', ondelete="CASCADE"),
                       nullable=False)

    group = db.relationship("CVEGroup", back_populates="issues")
    cve = db.relationship("CVE")

    __table_args__ = (db.Index('cve_group_entry__group_cve_idx',
                               group_id,
                               cve_id,
                               unique=True), )

    def __repr__(self):
        return '<CVEGroupEntry %r from %r referencing %r>' % (
            self.id, self.group_id, self.cve_id)
示例#2
0
class CVEGroup(db.Model):

    REFERENCES_LENGTH = 4096
    NOTES_LENGTH = 4096

    __versioned__ = {}
    __tablename__ = 'cve_group'

    id = db.Column(db.Integer(),
                   index=True,
                   unique=True,
                   primary_key=True,
                   autoincrement=True)
    status = db.Column(Status.as_type(),
                       nullable=False,
                       default=Status.unknown,
                       index=True)
    severity = db.Column(Severity.as_type(),
                         nullable=False,
                         default=Severity.unknown)
    affected = db.Column(db.String(32), nullable=False)
    fixed = db.Column(db.String(32))
    bug_ticket = db.Column(db.String(9))
    reference = db.Column(db.String(REFERENCES_LENGTH))
    notes = db.Column(db.String(NOTES_LENGTH))
    created = db.Column(db.DateTime,
                        default=datetime.utcnow,
                        nullable=False,
                        index=True)
    changed = db.Column(db.DateTime,
                        default=datetime.utcnow,
                        nullable=False,
                        index=True)
    advisory_qualified = db.Column(db.Boolean(), default=True, nullable=False)

    issues = db.relationship("CVEGroupEntry",
                             back_populates="group",
                             cascade="all,delete-orphan")
    packages = db.relationship("CVEGroupPackage",
                               back_populates="group",
                               cascade="all,delete-orphan")

    @property
    def name(self):
        return 'AVG-{}'.format(self.id)

    def __str__(self):
        return self.name

    def __repr__(self):
        return '<CVEGroup %r>' % (self.id)
class Advisory(db.Model):
    WORKAROUND_LENGTH = 4096
    IMPACT_LENGTH = 4096
    CONTENT_LENGTH = 65536
    REFERENCE_LENGTH = 120

    __tablename__ = 'advisory'
    id = db.Column(db.String(15), index=True, unique=True, primary_key=True)
    group_package_id = db.Column(db.Integer(),
                                 db.ForeignKey('cve_group_package.id'),
                                 nullable=False,
                                 unique=True,
                                 index=True)
    advisory_type = db.Column(db.String(64),
                              default='multiple issues',
                              nullable=False)
    publication = db.Column(Publication.as_type(),
                            nullable=False,
                            default=Publication.scheduled)
    workaround = db.Column(db.String(WORKAROUND_LENGTH), nullable=True)
    impact = db.Column(db.String(IMPACT_LENGTH), nullable=True)
    content = db.Column(db.String(CONTENT_LENGTH), nullable=True)
    created = db.Column(db.DateTime,
                        default=datetime.utcnow,
                        nullable=False,
                        index=True)
    reference = db.Column(db.String(REFERENCE_LENGTH), nullable=True)

    group_package = db.relationship("CVEGroupPackage")

    def __repr__(self):
        return '<Advisory {}>'.format(self.id)
示例#4
0
class Users(UserMixin, db.Model):
    """Users table"""
    id = db.Column(db.Integer, primary_key=True)
    first_name = db.Column(db.String(50), nullable=False)
    last_name = db.Column(db.String(50), nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    phone_number = db.Column(db.String(20), unique=True, nullable=True)
    verified = db.Column(db.Boolean(), default=False)
    password = db.Column(db.String(300), nullable=False)
    medicines = db.relationship('Medicines', backref='medicine', lazy=True)

    def __repr__(self):
        return f'{self.first_name} {self.last_name}'
示例#5
0
class User(db.Model, UserMixin, ModelMixin):
    id = Column(Integer, primary_key=True)

    # User authentication information
    username = Column(db.Unicode, nullable=False, unique=True)
    password = Column(db.Unicode, nullable=False, server_default='')
    reset_password_token = Column(
        db.Unicode, nullable=False, server_default='')

    # User email information
    email = Column(db.Unicode, nullable=False, unique=True)
    confirmed_at = Column(ArrowType, default=utcnow, nullable=False)

    # User information
    active = Column('is_active', Boolean(), nullable=False, server_default='0')
    first_name = Column(db.Unicode, nullable=False, server_default='')
    last_name = Column(db.Unicode, nullable=False, server_default='')
    receive_email = Column(Boolean, nullable=True, default=False)

    def __repr__(self):
        return self.username

    @property
    def is_admin(self):
        for user_role in self.roles:
            if user_role.name == 'admin':
                return True
        return False

    @property
    def is_super_admin(self):
        for user_role in self.roles:
            if user_role.name == 'super-admin':
                return True
        return False

    # Relationships
    roles = db.relationship('Role', secondary='user_roles',
                            backref=db.backref('users', lazy='dynamic'))
示例#6
0
class Task(db.Model):

    __tablename__ = 'tasks'

    id = db.Column(db.Integer, primary_key=True)
    uuid = db.Column(db.String(length=32), unique=True)
    title = db.Column(db.String(length=200))
    description = db.Column(db.Text())
    date = db.Column(db.Date)
    start_time = db.Column(db.TIMESTAMP)
    end_time = db.Column(db.TIMESTAMP)
    duration = db.Column(db.Integer())
    user_id = db.Column(db.Integer,
                        db.ForeignKey('users.id', ondelete="CASCADE"))

    user = db.relationship('User', backref=db.backref('tasks', lazy='dynamic'))

    @property
    def objects(self):
        return db_managers.TaskManager(self)

    def save(self):
        self.objects.save()