Esempio n. 1
0
class Actor(Document):

    name = CharField(indexed=True)
    gross_income_m = FloatField(indexed=True)
    salary_amount = FloatField(indexed=True, key="salary.amount")
    salary_currency = CharField(indexed=True, key="salary.currency")
    appearances = IntegerField(indexed=True)
    birth_year = IntegerField(indexed=True)
    favorite_food = ManyToManyField("Food")
    is_funny = BooleanField(indexed=True)
    movies = ManyToManyField("Movie", backref="actors")
Esempio n. 2
0
class Actor(Document):

    name = CharField(indexed=True)
    gross_income_m = FloatField(indexed=True)
    salary_amount = FloatField(indexed=True, key='salary.amount')
    salary_currency = CharField(indexed=True, key='salary.currency')
    appearances = IntegerField(indexed=True)
    birth_year = IntegerField(indexed=True)
    favorite_food = ManyToManyField('Food')
    is_funny = BooleanField(indexed=True)
    movies = ManyToManyField('Movie', backref='actors')
Esempio n. 3
0
class IssueOccurrence(BaseDocument):

    #can be uniquely identified by its filerevision.pk, issue.pk and from_row,to_row,from_column,to_column,sequence

    #calculated as hash(file_revision.hash,issue.hash,from_row,to_row,from_column,to_column,sequence)
    hash = CharField(indexed = True,length = 64)
    file_revision = ForeignKeyField('FileRevision',backref = 'issue_occurrences')
    issue = ForeignKeyField('Issue',backref = 'issue_occurrences')
    from_row = IntegerField()
    to_row = IntegerField()
    from_column = IntegerField()
    to_column = IntegerField()
    sequence = IntegerField(default = 0)
Esempio n. 4
0
class Issue(BaseDocument):
    """
    An `Issue` object represents an issue or problem with the code.
    It can be associated with one or multiple file revisions, code objects etc.

    An issue fingerprint should be a unique identifier for a given issue, hence if
    two issues have the same fingerprint they should be judged "identical".
    """
    class IgnoreReason:
        not_specified = 0
        not_relevant = 1
        false_positive = 2

    #calculated as hash(analyzer,code,fingerprint)
    hash = CharField(indexed=True, length=64)
    configuration = CharField(indexed=True, length=64)
    project = ForeignKeyField('Project', backref='issues', nullable=False)
    analyzer = CharField(indexed=True, length=100, nullable=False)
    code = CharField(indexed=True, length=100, nullable=False)
    fingerprint = CharField(indexed=True, length=255, nullable=False)

    #determines if this issue should be ignored
    ignore = BooleanField(indexed=True,
                          default=False,
                          nullable=False,
                          server_default=False)
    #gives a reason for the issue to be ignored (e.g. false_positive, )
    ignore_reason = IntegerField(indexed=True, nullable=True)
    #an optional comment for the ignore reason
    ignore_comment = CharField(indexed=False, length=255, nullable=True)

    class Meta(Document.Meta):
        unique_together = [('project', 'fingerprint', 'analyzer', 'code')]
        dbref_includes = ['code', 'analyzer']
Esempio n. 5
0
class GitSnapshot(BaseDocument):
    """
    """

    project = ForeignKeyField('Project', unique=False, backref='git_snapshots')
    snapshot = ForeignKeyField('Snapshot', unique=True, backref='git_snapshot')
    sha = CharField(indexed=True, length=40)
    hash = CharField(indexed=True, length=64)
    committer_date = DateTimeField(indexed=True)
    author_date = DateTimeField(indexed=True)
    author_name = CharField(length=100)
    committer_date_ts = IntegerField(indexed=True)
    author_date_ts = IntegerField(indexed=True)
    tree_sha = CharField(indexed=True, length=40)
    log = TextField(indexed=False)

    class Meta(BaseDocument.Meta):

        unique_together = [('project', 'sha')]
Esempio n. 6
0
class Movie(Document):

    title = CharField(nullable = True,indexed = True)
    director = ForeignKeyField(related = 'Director',nullable = True,backref = 'movies')
    cast = ManyToManyField(related = 'Actor')
    year = IntegerField(indexed = True)
    best_actor = ForeignKeyField('Actor',backref = 'best_movies')

    class Meta(Document.Meta):

        dbref_includes = ['title','year']
Esempio n. 7
0
class Movie(Document):

    title = CharField(nullable=True, indexed=True)
    director = ForeignKeyField(related="Director",
                               nullable=True,
                               backref="movies")
    cast = ManyToManyField(related="Actor")
    year = IntegerField(indexed=True)
    best_actor = ForeignKeyField("Actor", backref="best_movies")

    class Meta(Document.Meta):

        dbref_includes = ["title", "year"]
Esempio n. 8
0
class IssueClass(BaseDocument):

    hash = CharField(indexed = True,length = 64)
    title = CharField(indexed = True,length = 100)
    analyzer = CharField(indexed = True,length = 50)
    language = CharField(indexed = True,length = 50)
    code = CharField(indexed = True,length = 50)
    description = TextField(indexed = False)
    occurrence_description = CharField(indexed = True,length = 2000)
    severity = IntegerField(indexed = True)
    categories = ManyToManyField('IssueCategory')

    class Meta(BaseDocument.Meta):
        unique_together = (('code','analyzer'),)
Esempio n. 9
0
class IssueClass(BaseDocument):
    class Severity:
        critical = 1
        potential_bug = 2
        minor = 3
        recommendation = 4

    hash = CharField(indexed=True, length=64)
    title = CharField(indexed=True, length=100)
    analyzer = CharField(indexed=True, length=50)
    language = CharField(indexed=True, length=50)
    code = CharField(indexed=True, length=50)
    description = TextField(indexed=False)

    #obsolete
    occurrence_description = CharField(indexed=True, length=2000)

    severity = IntegerField(indexed=True)
    categories = ManyToManyField('IssueCategory')

    class Meta(BaseDocument.Meta):
        unique_together = (('code', 'analyzer'), )
Esempio n. 10
0
class Project(BaseProject):
    class AnalysisPriority:
        low = 0
        medium = 1
        high = 2
        do_it_now_i_say_exclamation_mark = 3

    class AnalysisStatus:
        succeeded = 'succeeded'
        in_progress = 'in_progress'
        failed = 'failed'

    IssueClass = IssueClass

    delete = BooleanField(indexed=True, default=False)
    deleted = BooleanField(indexed=True, default=False)

    name = CharField(indexed=True, length=100)
    description = CharField(indexed=True, length=2000)
    public = BooleanField(indexed=True, default=False)
    permalink = CharField(indexed=True,
                          unique=True,
                          nullable=False,
                          length=100)
    source = CharField(indexed=True, length=100, nullable=False)

    analyze = BooleanField(indexed=True, default=False)
    analysis_priority = IntegerField(default=AnalysisPriority.low,
                                     indexed=True)
    analysis_requested_at = DateTimeField(indexed=True)
    analysis_status = CharField(indexed=True, length=50)
    analyzed_at = DateTimeField(indexed=True)

    reset = BooleanField(indexed=True, default=False)
    reset_requested_at = DateTimeField(indexed=True)

    fetched_at = DateTimeField(indexed=True, nullable=True)
    fetch_status = CharField(indexed=True, nullable=True)
    fetch_error = TextField(default='')

    tags = ManyToManyField('Tag')

    def get_analysis_queue_position(self, backend=None):

        if backend is None:
            backend = self.backend

        analysis_priority_query = [{
            'analysis_priority': self.analysis_priority
        }]
        if self.analysis_requested_at is not None:
            analysis_priority_query += [{
                'analysis_requested_at': {
                    '$lte': self.analysis_requested_at
                }
            }]
        # if the project is flagged for analysis we calculate its position in the analysis queue...
        if self.get('analyze', False) and self.get('analysis_priority',
                                                   None) is not None:
            return len(
                backend.filter(
                    self.__class__, {
                        '$and': [{
                            'analyze': True
                        }, {
                            'pk': {
                                '$ne': self.pk
                            }
                        }, {
                            '$or': [{
                                'deleted': {
                                    '$exists': False
                                }
                            }, {
                                'deleted': False
                            }]
                        }, {
                            '$or': [{
                                'analysis_priority': {
                                    '$gt': self.analysis_priority
                                }
                            }, {
                                '$and': analysis_priority_query
                            }]
                        }]
                    })) + 1
            return None

    def is_authorized(self, user, roles=None, public_ok=False, backend=None):
        """
        Checks if a user is allowed to access a project.
        Returns True or False
        """
        if backend is None:
            backend = self.backend

        if roles is None:
            roles = ['admin', 'collaborator', 'owner']

        # super users can see everything
        if user.is_superuser():
            return True

        if public_ok and self.get("public"):
            return True

        # check if the user is authorized via a role
        user_roles = backend.filter(UserRole, {
            'project': self,
            'user': user,
            'role': {
                '$in': list(roles)
            }
        })

        if user_roles:
            return True

        return False