Exemplo n.º 1
0
class WorkspaceDate(Base, Persistent):
    __tablename__ = 'workspace_date'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), nullable=False)
    ws_id = db.Column(db.Integer, db.ForeignKey('workspace.id'))
    date = db.Column(db.Date, nullable=False)
    is_official_holiday = db.Column(db.Boolean(), nullable=True)

    @staticmethod
    def get_work_days_count(ws_id, start_date, end_date):
        holidays = WorkspaceDate.query(). \
            filter(WorkspaceDate.date.between(start_date, end_date)). \
            filter(WorkspaceDate.ws_id == ws_id). \
            filter(WorkspaceDate.is_official_holiday is True). \
            all()

        result = 0

        holiday_dates = map(lambda h: h.date, holidays)

        date = start_date

        while date <= end_date:
            if date.weekday() < 5 and date not in holiday_dates:
                result += 1

            date = date + datetime.timedelta(days=1)

        return result
Exemplo n.º 2
0
class UserDevice(Base, Persistent):
    __tablename__ = 'user_device'

    user_id = db.Column('user_id',
                        db.Integer,
                        db.ForeignKey('user.id'),
                        nullable=False)
    device_token = db.Column('device_token',
                             db.String,
                             primary_key=True,
                             nullable=False)
Exemplo n.º 3
0
class Balance:
    __tablename__ = 'balance'

    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column('user_id', db.Integer, db.ForeignKey('user.id'), nullable=False)
    # user = db.relationship('User', backref='balances', foreign_keys=[user_id])
    balance_type = db.Column('balance_type', db.String(120), nullable=False)
    amount = db.Column('amount', db.Integer, nullable=False)

    @classmethod
    def find_by_user_id(cls, user_id):
        return cls.find_all(user_id=user_id)
Exemplo n.º 4
0
class WorkspaceInvitation(Base, Persistent):
    __tablename__ = 'workspace_invitation'

    id = db.Column(db.Integer(), primary_key=True)
    email = db.Column(db.String(255), nullable=False)
    ws_id = db.Column(db.Integer,
                      db.ForeignKey('workspace.id'),
                      nullable=False)
    status = db.Column(db.Enum(WorkspaceInvitationStatus),
                       default=WorkspaceInvitationStatus.PENDING,
                       nullable=False)
    start_date = db.Column(db.Date, nullable=True)
Exemplo n.º 5
0
class RevokedTokenModel(db.Model):
    __tablename__ = 'revoked_token'
    id = db.Column(db.Integer, primary_key=True)
    jti = db.Column(db.String(120))

    def add(self):
        db.session.add(self)
        db.session.commit()

    @classmethod
    def is_jti_blacklisted(cls, jti):
        query = cls.query.filter_by(jti=jti).first()
        return bool(query)
Exemplo n.º 6
0
class WorkspaceUserRole(Base, Persistent):
    __tablename__ = 'workspace_user_role'

    ws_id = db.Column(db.Integer,
                      db.ForeignKey('workspace.id'),
                      nullable=False,
                      primary_key=True)
    user_id = db.Column(db.Integer,
                        db.ForeignKey('user.id'),
                        nullable=False,
                        primary_key=True)
    role = db.Column(db.Enum(WorkspaceUserRoles),
                     default=WorkspaceUserRoles.MEMBER,
                     nullable=False,
                     primary_key=True)
Exemplo n.º 7
0
class WorkspaceModel(Base, Persistent):
    __tablename__ = 'workspace'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), unique=True, nullable=False)
    description = db.Column(db.String(255))
    invitation_link_token = db.Column(db.String(255))

    @staticmethod
    def generate_invitation_link_token():
        return str(uuid.uuid4())

    @classmethod
    def find_by_user_id(cls, user_id):
        ws_ids = [x.ws_id for x in WorkspaceUser.find_all(user_id=user_id)]
        return cls.query().filter(WorkspaceModel.id.in_(ws_ids))
Exemplo n.º 8
0
class WorkspaceRule(Base, Persistent):
    __tablename__ = 'workspace_rule'

    ws_id = db.Column(db.Integer,
                      db.ForeignKey('workspace.id'),
                      nullable=False,
                      primary_key=True)
    type = db.Column(db.Enum(WorkspaceRuleTypes),
                     nullable=False,
                     primary_key=True)
    rule = db.Column(db.String, nullable=False)
    node = db.Column(db.BLOB, nullable=True)

    def __init__(self, ws_id, type, rule):
        self.ws_id = ws_id
        self.type = type
        self.rule = rule
        self.node = pickle.dumps(Intellect().learn_policy(rule))
Exemplo n.º 9
0
class User(Base, Persistent):
    __tablename__ = 'user'

    id = db.Column(db.Integer, primary_key=True)
    password = db.Column(db.String(120), nullable=False)
    created_time = db.Column(db.DateTime(), nullable=False)
    jti = db.Column(db.String, nullable=True)
    email = db.Column(db.String(120), unique=True, nullable=False)

    @classmethod
    def find_by_email(cls, email):
        return cls.find(email=email)

    @staticmethod
    def generate_hash(password):
        return sha256.hash(password)

    @staticmethod
    def verify_hash(password, password_hash):
        return sha256.verify(password, password_hash)
Exemplo n.º 10
0
class WorkspaceUser(Base, Persistent):
    __tablename__ = 'workspace_user'

    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), primary_key=True)
    ws_id = db.Column(db.Integer,
                      db.ForeignKey('workspace.id'),
                      primary_key=True)
    start_date = db.Column(db.Date,
                           default=datetime.datetime.now(),
                           nullable=False)

    profile = db.relationship(
        'UserProfile',
        primaryjoin='foreign(UserProfile.user_id) == WorkspaceUser.user_id',
        uselist=False,
        viewonly=True)

    def get_worked_months(self):
        now = datetime.datetime.now()
        return (now.year -
                self.start_date.year) * 12 + now.month - self.start_date.month
Exemplo n.º 11
0
class UserModel(db.Model):
    __tablename__ = 'user'

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(120), unique=True, nullable=False)
    password = db.Column(db.String(120), nullable=False)

    def save_to_db(self):
        db.session.add(self)
        db.session.commit()

    @classmethod
    def find_by_username(cls, username):
        return cls.query.filter_by(username=username).first()

    @staticmethod
    def generate_hash(password):
        return sha256.hash(password)

    @staticmethod
    def verify_hash(password, password_hash):
        return sha256.verify(password, password_hash)
Exemplo n.º 12
0
class DayOff(Base, Persistent):
    __tablename__ = 'day_off'

    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column('user_id', db.Integer, db.ForeignKey('user_profile.user_id'), nullable=False)
    user = db.relationship('UserProfile', foreign_keys=[user_id])

    approved_by_id = db.Column('approved_by_id', db.Integer, db.ForeignKey('user_profile.user_id'), nullable=True)
    approved_by = db.relationship('UserProfile', foreign_keys=[approved_by_id])

    leave_type = db.Column('leave_type', db.Enum(LeaveTypes), nullable=False)

    start_date = db.Column('start_date', db.Date, nullable=False)
    end_date = db.Column('end_date', db.Date, nullable=False)

    workspace_id = db.Column('workspace_id', db.Integer, db.ForeignKey('workspace.id'), nullable=False)
    workspace = db.relationship('WorkspaceModel', foreign_keys=[workspace_id])

    comment = db.Column('comment', db.String(255), nullable=True)

    @classmethod
    def find_by_user_id(cls, user_id):
        return cls.find_all(user_id=user_id)
Exemplo n.º 13
0
class UserProfile(Base, Persistent):
    __tablename__ = 'user_profile'

    user_id = db.Column('user_id',
                        db.Integer,
                        db.ForeignKey('user.id'),
                        primary_key=True,
                        nullable=False)
    first_name = db.Column('first_name', db.String, nullable=True)
    last_name = db.Column('last_name', db.String, nullable=True)
    position = db.Column('position', db.String, nullable=True)
    phone = db.Column('phone', db.String, nullable=True)
    email = db.Column('email', db.String, nullable=False)
    user = db.relationship('User', foreign_keys=[user_id])

    @classmethod
    def find_by_user_id(cls, user_id):
        return cls.find(user_id=user_id)