Example #1
0
    def process(self, db, user, chain_id, text):
        chain = CommentChain.fromId(db, chain_id, user)
        comment_id = createComment(db, user, chain_id, text)

        db.commit()

        return OperationResult(comment_id=comment_id, draft_status=chain.review.getDraftStatus(db, user))
Example #2
0
    def process(self, db, user, chain_id, text):
        chain = CommentChain.fromId(db, chain_id, user)
        comment_id = createComment(db, user, chain_id, text)

        db.commit()

        return OperationResult(comment_id=comment_id,
                               draft_status=chain.review.getDraftStatus(
                                   db, user))
Example #3
0
    def process(self, db, user, chain_id, commit_id, sha1, offset, count):
        chain = CommentChain.fromId(db, chain_id, user)
        existing = chain.lines_by_sha1.get(sha1)

        if not existing:
            cursor = db.cursor()
            cursor.execute("""INSERT INTO commentchainlines (chain, uid, commit, sha1, first_line, last_line)
                              VALUES (%s, %s, %s, %s, %s, %s)""",
                           (chain.id, user.id, commit_id, sha1, offset, offset + count - 1))
        elif offset != existing[0] or count != existing[1]:
            raise OperationError, "the comment chain is already present at other lines in same file version"

        return self.setChainState(db, user, chain, "addressed", "open", new_last_commit=commit_id)
Example #4
0
    def process(self, db, user, chain_id, commit_id, sha1, offset, count):
        chain = CommentChain.fromId(db, chain_id, user)
        existing = chain.lines_by_sha1.get(sha1)

        if not existing:
            cursor = db.cursor()
            cursor.execute(
                """INSERT INTO commentchainlines (chain, uid, commit, sha1, first_line, last_line)
                              VALUES (%s, %s, %s, %s, %s, %s)""",
                (chain.id, user.id, commit_id, sha1, offset,
                 offset + count - 1))
        elif offset != existing[0] or count != existing[1]:
            raise OperationError, "the comment chain is already present at other lines in same file version"

        return self.setChainState(db,
                                  user,
                                  chain,
                                  "addressed",
                                  "open",
                                  new_last_commit=commit_id)
Example #5
0
    def process(self, db, user, chain_id, new_type):
        chain = CommentChain.fromId(db, chain_id, user)
        review = chain.review

        if chain.type == new_type:
            raise OperationError, "the comment chain's type is already '%s'" % new_type
        elif new_type == "note" and chain.state in ("closed", "addressed"):
            raise OperationError, "can't convert resolved or addressed issue to a note"

        if new_type == "issue": old_type = "note"
        else: old_type = "issue"

        cursor = db.cursor()

        if chain.state == "draft":
            # The chain is still a draft; just change its type directly.
            cursor.execute("""UPDATE commentchains
                                 SET type=%s
                               WHERE id=%s""",
                           (new_type, chain.id))

        elif chain.type_is_draft:
            # The user is reverting a draft chain type change; just undo the
            # draft change.
            cursor.execute("""DELETE FROM commentchainchanges
                               WHERE chain=%s
                                 AND uid=%s
                                 AND to_type IS NOT NULL""",
                           (chain.id, user.id))

        else:
            # Otherwise insert a new row into the commentchainchanges table.
            cursor.execute("""INSERT INTO commentchainchanges (review, uid, chain, from_type, to_type)
                              VALUES (%s, %s, %s, %s, %s)""",
                           (review.id, user.id, chain.id, chain.type, new_type))

        db.commit()

        return OperationResult(draft_status=review.getDraftStatus(db, user))
Example #6
0
    def process(self, db, user, chain_id, new_type):
        chain = CommentChain.fromId(db, chain_id, user)
        review = chain.review

        if chain.type == new_type:
            raise OperationError, "the comment chain's type is already '%s'" % new_type
        elif new_type == "note" and chain.state in ("closed", "addressed"):
            raise OperationError, "can't convert resolved or addressed issue to a note"

        cursor = db.cursor()

        if chain.state == "draft":
            # The chain is still a draft; just change its type directly.
            cursor.execute(
                """UPDATE commentchains
                                 SET type=%s
                               WHERE id=%s""", (new_type, chain.id))

        elif chain.type_is_draft:
            # The user is reverting a draft chain type change; just undo the
            # draft change.
            cursor.execute(
                """DELETE FROM commentchainchanges
                               WHERE chain=%s
                                 AND uid=%s
                                 AND to_type IS NOT NULL""",
                (chain.id, user.id))

        else:
            # Otherwise insert a new row into the commentchainchanges table.
            cursor.execute(
                """INSERT INTO commentchainchanges (review, uid, chain, from_type, to_type)
                              VALUES (%s, %s, %s, %s, %s)""",
                (review.id, user.id, chain.id, chain.type, new_type))

        db.commit()

        return OperationResult(draft_status=review.getDraftStatus(db, user))
Example #7
0
 def process(self, db, user, chain_id):
     return self.setChainState(db, user, CommentChain.fromId(db, chain_id, user), "open", "closed")
Example #8
0
 def process(self, db, user, chain_id):
     return self.setChainState(db, user,
                               CommentChain.fromId(db, chain_id, user),
                               "closed", "open")