class GitRepository(BaseGitRepository):

    public_key = TextField()
    private_key = TextField()
    url = CharField(indexed=True)

    @property
    def path(self):
        #we import this here to avoid cyclic dependency problems (shouldn't be the case though)
        from quantifiedcode.settings import settings
        if not self.eager.project.eager.pk:
            raise AttributeError('You must define a primary key for the project in order to get the repository path!')
        path = os.path.join(settings.get('project_path'), settings.get('backend.paths.git_repositories'), self.pk)
        return path
예제 #2
0
class Example(BaseDocument):
    """
        An example model that has a relationship to a given user.
    """
    export_map = ("test", )

    user = ForeignKeyField("User",
                           backref="example",
                           unique=True,
                           ondelete="CASCADE")
    test = TextField()
예제 #3
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'),)
예제 #4
0
파일: models.py 프로젝트: amoursu/checkmate
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')]
예제 #5
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'), )
예제 #6
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