Exemplo n.º 1
0
class Application(StandardAttributes, db.Model):
    name = db.Column(db.String(200), nullable=False)
    client_id = db.Column(db.String(64),
                          default=lambda: Application.generate_token(10),
                          nullable=False,
                          unique=True)
    client_secret = db.Column(db.String(64),
                              default=lambda: Application.generate_token(),
                              nullable=False,
                              unique=True)

    jobs = db.relationship('Job', backref='jobs', lazy=True)

    user_id = db.Column(GUID,
                        db.ForeignKey('user.id'),
                        primary_key=True,
                        unique=True)
    user = db.relationship('User', innerjoin=True, uselist=False)

    __tablename__ = 'application'
    __repr__ = model_repr('name', 'client_id')

    @classmethod
    def generate_token(cls, size=32):
        return token_hex(size)
Exemplo n.º 2
0
class User(StandardAttributes, db.Model):
    email = db.Column(db.String(128), unique=True, nullable=False)

    options = db.relationship(
        'Option',
        foreign_keys='[Option.option_id]',
        primaryjoin='Option.option_id == User.id',
        viewonly=True,
        uselist=True
    )

    __tablename__ = 'user'
Exemplo n.º 3
0
class Identity(StandardAttributes, db.Model):
    user_id = db.Column(GUID,
                        db.ForeignKey('user.id', ondelete='CASCADE'),
                        nullable=False,
                        index=True)
    external_id = db.Column(db.String(64), unique=True, nullable=False)
    provider = db.Column(db.String(32), nullable=True)
    config = db.Column(JSON, nullable=False)
    scopes = db.Column(ARRAY(db.String(64)), nullable=True)

    user = db.relationship('User')

    __tablename__ = 'identity'
    __table_args__ = (db.UniqueConstraint('user_id',
                                          'provider',
                                          name='unq_identity_user'), )
Exemplo n.º 4
0
class ApplicationApiToken(StandardAttributes, db.Model, ApiTokenMixin):
    application_id = db.Column(GUID,
                               db.ForeignKey('application.id',
                                             ondelete='CASCADE'),
                               nullable=False,
                               unique=True)

    application = db.relationship('Application',
                                  backref=db.backref('token', uselist=False),
                                  innerjoin=True)

    __tablename__ = 'application_api_token'
    __repr__ = model_repr('application_id', 'key')

    def get_token_key(self):
        return 'a'

    def get_tenant(self):
        self.user
Exemplo n.º 5
0
 def application(cls):
     return db.relationship('Application', uselist=False)