예제 #1
0
class SherlockSettings(db.Model):
    __tablename__ = "sherlock_settings"
    __table_args__ = {'extend_existing': True}

    id = db.Column(db.Integer, primary_key=True)
    setting = db.Column(db.String(250))
    value = db.Column(db.String(250))
    who_can_change = db.Column(db.String(250))
    label = db.Column(db.String(250))

    def __init__(self, setting, value, label, who_can_change='admin'):
        self.setting = setting
        self.value = value
        self.who_can_change = who_can_change
        self.label = label
예제 #2
0
class User(db.Model):
    __tablename__ = "user"
    __table_args__ = {'extend_existing': True}

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), nullable=False)
    email = db.Column(db.String(100), nullable=False, unique=True)
    password = db.Column(db.String(250), nullable=False)
    profile = db.Column(db.String(50), nullable=False)

    cycle_scenarios = db.relationship('CycleScenarios')
    project = db.relationship('Project')

    def __init__(self, name, email, password, profile='user'):
        self.name = name
        self.email = email
        self.password = User.generate_hash_password(password)
        self.profile = profile

    def verify_password(self, password):
        password = password.encode('utf-8')
        self.password = self.password.encode('utf-8')
        if bcrypt.hashpw(password, self.password) == self.password:
            return True
        return False

    @staticmethod
    def generate_hash_password(password):
        return bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt())

    def generate_auth_token(self, expiration=600):
        s = Serializer(secretkey, expires_in=expiration)
        return s.dumps({'id': self.id})

    @staticmethod
    def verify_auth_token(token):
        s = Serializer(secretkey)
        try:
            data = s.loads(token)
        except SignatureExpired:
            return None
        except BadSignature:
            return None
        g.user = User.query.get(data['id'])
        return g.user
예제 #3
0
class TagCase(db.Model):
    __tablename__ = "tags_case"
    __table_args__ = {'extend_existing': True}

    id = db.Column(db.Integer, primary_key=True)
    case_id = db.Column(db.Integer)
    tag = db.Column(db.String(250))

    def __init__(self, case_id, tag):
        self.case_id = case_id
        self.tag = tag
예제 #4
0
class TagScenario(db.Model):
    __tablename__ = "tags_scenario"
    __table_args__ = {'extend_existing': True}

    id = db.Column(db.Integer, primary_key=True)
    scenario_id = db.Column(db.Integer)
    tag = db.Column(db.String(250))

    def __init__(self, scenario_id, tag):
        self.scenario_id = scenario_id
        self.tag = tag
예제 #5
0
class Project(db.Model):
    __tablename__ = "project"
    __table_args__ = {'extend_existing': True}

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), nullable=False)
    owner_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    type_of_project = db.Column(db.String(50), nullable=False)
    privacy_policy = db.Column(db.String(50), nullable=False)

    scenario = db.relationship('Scenario')
    cycle = db.relationship('Cycle')

    def __init__(self, name, owner_id, type_of_project, privacy_policy):
        """Setting params to the object."""
        self.name = name
        self.owner_id = owner_id
        self.type_of_project = type_of_project
        self.privacy_policy = privacy_policy

    def __repr__(self):
        """Representative Object Return."""
        return '<Project %r>' % self.name
예제 #6
0
class Cycle(db.Model):
    __tablename__ = "cycle"
    __table_args__ = {'extend_existing': True}

    id = db.Column(db.Integer, primary_key=True)
    cycle = db.Column(db.Integer, nullable=False)
    name = db.Column(db.Text)
    project_id = db.Column(db.Integer, db.ForeignKey('project.id'))
    state_code = db.Column(db.Enum(StateType))

    cycle_cases = db.relationship('CycleCases')
    cycle_scenarios = db.relationship('CycleScenarios')

    created_at = db.Column(db.DateTime, default=datetime.now)
    closed_at = db.Column(db.DateTime)
    closed_by = db.Column(db.Integer, db.ForeignKey('user.id'))
    closed_reason = db.Column(db.String(250))
    last_change = db.Column(db.DateTime, default=datetime.now)

    def __init__(self, cycle, name, project_id):
        self.cycle = cycle
        self.name = name
        self.project_id = project_id
        self.state_code = StateType.active