示例#1
0
    def process(self, db, user, review_id, note):
        review = dbutils.Review.fromId(db, review_id)

        cursor = db.cursor()
        cursor.execute(
            """SELECT DISTINCT uid
                            FROM reviewuserfiles
                            JOIN reviewfiles ON (reviewfiles.id=reviewuserfiles.file)
                            JOIN users ON (users.id=reviewuserfiles.uid)
                           WHERE reviewfiles.review=%s
                             AND reviewfiles.state='pending'
                             AND users.status!='retired'""", (review.id, ))

        user_ids = set([user_id for (user_id, ) in cursor.fetchall()])

        # Add the pinging user and the owners (they are usually the same.)
        user_ids.add(user.id)

        for owner in review.owners:
            user_ids.add(owner.id)

        recipients = [dbutils.User.fromId(db, user_id) for user_id in user_ids]

        pending_mails = []
        for recipient in recipients:
            pending_mails.extend(
                review_mail.sendPing(db, user, recipient, recipients, review,
                                     note))
        mailutils.sendPendingMails(pending_mails)

        return OperationResult()
示例#2
0
    def process(self, db, user, review_id, note):
        review = dbutils.Review.fromId(db, review_id)

        cursor = db.cursor()
        cursor.execute("""SELECT DISTINCT uid
                            FROM reviewuserfiles
                            JOIN reviewfiles ON (reviewfiles.id=reviewuserfiles.file)
                            JOIN users ON (users.id=reviewuserfiles.uid)
                           WHERE reviewfiles.review=%s
                             AND reviewfiles.state='pending'
                             AND users.status!='retired'""",
                       (review.id,))

        user_ids = set([user_id for (user_id,) in cursor.fetchall()])

        # Add the pinging user and the owners (they are usually the same.)
        user_ids.add(user.id)

        for owner in review.owners: user_ids.add(owner.id)

        recipients = [dbutils.User.fromId(db, user_id) for user_id in user_ids]

        pending_mails = []
        for recipient in recipients:
            pending_mails.extend(review_mail.sendPing(db, user, recipient, recipients, review, note))
        mailutils.sendPendingMails(pending_mails)

        return OperationResult()
示例#3
0
    def process(self, db, creator, review_id, filters):
        review = dbutils.Review.fromId(db, review_id)
        by_user = {}

        for filter in filters:
            if "user_ids" in filter:
                user_ids = set(filter["user_ids"])
            else:
                user_ids = set([])

            if "user_names" in filter:
                for user_name in filter["user_names"]:
                    user_ids.add(dbutils.User.fromName(db, user_name).id)

            if "directory_ids" in filter:
                directory_ids = set(filter["directory_ids"])
            else:
                directory_ids = set([])

            if "file_ids" in filter:
                file_ids = set(filter["file_ids"])
            else:
                file_ids = set([])

            if "paths" in filter:
                for path in filter["paths"]:
                    if not path or path == "/":
                        directory_ids.add(0)
                    elif path.endswith("/") or dbutils.is_directory(
                            db, path) or ("." not in path.split("/")[-1]
                                          and not dbutils.is_file(db, path)):
                        directory_ids.add(dbutils.find_directory(db, path))
                    else:
                        file_ids.add(dbutils.find_file(db, path))

            for user_id in user_ids:
                reviewer_directory_ids, reviewer_file_ids, watcher_directory_ids, watcher_file_ids = by_user.setdefault(
                    user_id, (set(), set(), set(), set()))

                if filter["type"] == "reviewer":
                    reviewer_directory_ids |= directory_ids
                    reviewer_file_ids |= file_ids
                else:
                    watcher_directory_ids |= directory_ids
                    watcher_file_ids |= file_ids

        pending_mails = []

        for user_id, args in by_user.items():
            user = dbutils.User.fromId(db, user_id)
            pending_mails.extend(
                review_utils.addReviewFilters(db, creator, user, review,
                                              *args))

        db.commit()

        mailutils.sendPendingMails(pending_mails)

        return OperationResult()
示例#4
0
    def process(self, db, creator, review_id, filters):
        review = dbutils.Review.fromId(db, review_id)
        by_user = {}

        for filter in filters:
            if "user_ids" in filter:
                user_ids = set(filter["user_ids"])
            else:
                user_ids = set([])

            if "user_names" in filter:
                for user_name in filter["user_names"]:
                    user_ids.add(dbutils.User.fromName(db, user_name).id)

            if "paths" in filter:
                paths = set(reviewing.filters.sanitizePath(path) for path in filter["paths"])

                for path in paths:
                    try:
                        reviewing.filters.validatePattern(path)
                    except reviewing.filters.PatternError as error:
                        raise OperationFailure(
                            code="invalidpattern",
                            title="Invalid path pattern",
                            message="There are invalid wild-cards in the path: %s" % error.message)
            else:
                paths = set()

            if "file_ids" in filter:
                for file_id in filter["file_ids"]:
                    paths.add(dbutils.describe_file(file_id))

            for user_id in user_ids:
                reviewer_paths, watcher_paths = by_user.setdefault(user_id, (set(), set()))

                if filter["type"] == "reviewer":
                    reviewer_paths |= paths
                else:
                    watcher_paths |= paths

        pending_mails = []

        for user_id, (reviewer_paths, watcher_paths) in by_user.items():
            user = dbutils.User.fromId(db, user_id)
            if not user:
                raise OperationFailure(code="invaliduserid",
                                       title="Invalid user ID",
                                       message="At least one of the specified user IDs was invalid.")
            pending_mails.extend(reviewing.utils.addReviewFilters(db, creator, user, review, reviewer_paths, watcher_paths))

        review = dbutils.Review.fromId(db, review_id)
        review.incrementSerial(db)

        db.commit()

        mailutils.sendPendingMails(pending_mails)

        return OperationResult()
示例#5
0
    def process(self, db, creator, review_id, filters):
        review = dbutils.Review.fromId(db, review_id)
        by_user = {}

        for filter in filters:
            if "user_ids" in filter:
                user_ids = set(filter["user_ids"])
            else:
                user_ids = set([])

            if "user_names" in filter:
                for user_name in filter["user_names"]:
                    user_ids.add(dbutils.User.fromName(db, user_name).id)

            if "directory_ids" in filter:
                directory_ids = set(filter["directory_ids"])
            else:
                directory_ids = set([])

            if "file_ids" in filter:
                file_ids = set(filter["file_ids"])
            else:
                file_ids = set([])

            if "paths" in filter:
                for path in filter["paths"]:
                    if not path or path == "/":
                        directory_ids.add(0)
                    elif path.endswith("/") or dbutils.is_directory(db, path) or ("." not in path.split("/")[-1] and not dbutils.is_file(db, path)):
                        directory_ids.add(dbutils.find_directory(db, path))
                    else:
                        file_ids.add(dbutils.find_file(db, path))

            for user_id in user_ids:
                reviewer_directory_ids, reviewer_file_ids, watcher_directory_ids, watcher_file_ids = by_user.setdefault(user_id, (set(), set(), set(), set()))

                if filter["type"] == "reviewer":
                    reviewer_directory_ids |= directory_ids
                    reviewer_file_ids |= file_ids
                else:
                    watcher_directory_ids |= directory_ids
                    watcher_file_ids |= file_ids

        pending_mails = []

        for user_id, args in by_user.items():
            user = dbutils.User.fromId(db, user_id)
            pending_mails.extend(review_utils.addReviewFilters(db, creator, user, review, *args))

        db.commit()

        mailutils.sendPendingMails(pending_mails)

        return OperationResult()
示例#6
0
    def process(self, db, creator, review_id, filters):
        review = dbutils.Review.fromId(db, review_id)
        by_user = {}

        for filter in filters:
            if "user_ids" in filter:
                user_ids = set(filter["user_ids"])
            else:
                user_ids = set([])

            if "user_names" in filter:
                for user_name in filter["user_names"]:
                    user_ids.add(dbutils.User.fromName(db, user_name).id)

            if "paths" in filter:
                paths = set(filter["paths"])
            else:
                paths = set()

            if "file_ids" in filter:
                for file_id in filter["file_ids"]:
                    paths.add(dbutils.describe_file(file_id))

            for user_id in user_ids:
                reviewer_paths, watcher_paths = by_user.setdefault(user_id, (set(), set()))

                if filter["type"] == "reviewer":
                    reviewer_paths |= paths
                else:
                    watcher_paths |= paths

        pending_mails = []

        for user_id, (reviewer_paths, watcher_paths) in by_user.items():
            user = dbutils.User.fromId(db, user_id)
            pending_mails.extend(reviewing.utils.addReviewFilters(db, creator, user, review, reviewer_paths, watcher_paths))

        db.commit()

        mailutils.sendPendingMails(pending_mails)

        return OperationResult()
示例#7
0
    def process(self, db, user, review_id, user_name, files):
        reviewer = dbutils.User.fromName(db, user_name)
        new_file_ids = set(files)

        cursor = db.cursor()
        cursor.execute("SELECT 1 FROM reviewusers WHERE review=%s AND uid=%s", (review_id, reviewer.id))

        if not cursor.fetchone():
            cursor.execute("INSERT INTO reviewusers (review, uid) VALUES (%s, %s)", (review_id, reviewer.id))
            current_file_ids = set()
        else:
            cursor.execute("SELECT file FROM fullreviewuserfiles WHERE review=%s AND assignee=%s", (review_id, reviewer.id))
            current_file_ids = set(file_id for (file_id,) in cursor)

        delete_file_ids = current_file_ids - new_file_ids
        new_file_ids -= current_file_ids

        if delete_file_ids or new_file_ids:
            cursor.execute("INSERT INTO reviewassignmentstransactions (review, assigner) VALUES (%s, %s) RETURNING id", (review_id, user.id))
            transaction_id = cursor.fetchone()[0]

        if delete_file_ids:
            cursor.executemany("""INSERT INTO reviewassignmentchanges (transaction, file, uid, assigned)
                                       SELECT %s, reviewfiles.id, reviewuserfiles.uid, false
                                         FROM reviewfiles
                                         JOIN reviewuserfiles ON (reviewuserfiles.file=reviewfiles.id)
                                        WHERE reviewfiles.review=%s
                                          AND reviewfiles.file=%s
                                          AND reviewuserfiles.uid=%s""",
                               itertools.izip(itertools.repeat(transaction_id),
                                              itertools.repeat(review_id),
                                              delete_file_ids,
                                              itertools.repeat(reviewer.id)))

            cursor.executemany("""DELETE FROM reviewuserfiles
                                        WHERE file IN (SELECT id
                                                         FROM reviewfiles
                                                        WHERE review=%s
                                                          AND file=%s)
                                          AND uid=%s""",
                               itertools.izip(itertools.repeat(review_id),
                                              delete_file_ids,
                                              itertools.repeat(reviewer.id)))

        if new_file_ids:
            cursor.executemany("""INSERT INTO reviewuserfiles (file, uid)
                                       SELECT reviewfiles.id, %s
                                         FROM reviewfiles
                                        WHERE reviewfiles.review=%s
                                          AND reviewfiles.file=%s""",
                               itertools.izip(itertools.repeat(reviewer.id),
                                              itertools.repeat(review_id),
                                              new_file_ids))

            cursor.executemany("""INSERT INTO reviewassignmentchanges (transaction, file, uid, assigned)
                                       SELECT %s, reviewfiles.id, %s, true
                                         FROM reviewfiles
                                        WHERE reviewfiles.review=%s
                                          AND reviewfiles.file=%s""",
                               itertools.izip(itertools.repeat(transaction_id),
                                              itertools.repeat(reviewer.id),
                                              itertools.repeat(review_id),
                                              new_file_ids))

        if delete_file_ids or new_file_ids:
            cursor.execute("UPDATE reviews SET serial=serial+1 WHERE id=%s", (review_id,))

            pending_mails = reviewing.utils.generateMailsForAssignmentsTransaction(db, transaction_id)

            db.commit()

            mailutils.sendPendingMails(pending_mails)

        return OperationResult()
示例#8
0
    def process(self, db, user, review_id, user_name, files):
        reviewer = dbutils.User.fromName(db, user_name)
        new_file_ids = set(files)

        cursor = db.cursor()
        cursor.execute("SELECT 1 FROM reviewusers WHERE review=%s AND uid=%s",
                       (review_id, reviewer.id))

        if not cursor.fetchone():
            cursor.execute(
                "INSERT INTO reviewusers (review, uid) VALUES (%s, %s)",
                (review_id, reviewer.id))
            current_file_ids = set()
        else:
            cursor.execute(
                "SELECT file FROM fullreviewuserfiles WHERE review=%s AND assignee=%s",
                (review_id, reviewer.id))
            current_file_ids = set(file_id for (file_id, ) in cursor)

        delete_file_ids = current_file_ids - new_file_ids
        new_file_ids -= current_file_ids

        if delete_file_ids or new_file_ids:
            cursor.execute(
                "INSERT INTO reviewassignmentstransactions (review, assigner) VALUES (%s, %s) RETURNING id",
                (review_id, user.id))
            transaction_id = cursor.fetchone()[0]

        if delete_file_ids:
            cursor.executemany(
                """INSERT INTO reviewassignmentchanges (transaction, file, uid, assigned)
                                       SELECT %s, reviewfiles.id, reviewuserfiles.uid, false
                                         FROM reviewfiles
                                         JOIN reviewuserfiles ON (reviewuserfiles.file=reviewfiles.id)
                                        WHERE reviewfiles.review=%s
                                          AND reviewfiles.file=%s
                                          AND reviewuserfiles.uid=%s""",
                itertools.izip(itertools.repeat(transaction_id),
                               itertools.repeat(review_id), delete_file_ids,
                               itertools.repeat(reviewer.id)))

            cursor.executemany(
                """DELETE FROM reviewuserfiles
                                        USING reviewfiles
                                        WHERE reviewuserfiles.file=reviewfiles.id
                                          AND reviewfiles.review=%s
                                          AND reviewfiles.file=%s
                                          AND reviewuserfiles.uid=%s""",
                itertools.izip(itertools.repeat(review_id), delete_file_ids,
                               itertools.repeat(reviewer.id)))

        if new_file_ids:
            cursor.executemany(
                """INSERT INTO reviewuserfiles (file, uid)
                                       SELECT reviewfiles.id, %s
                                         FROM reviewfiles
                                        WHERE reviewfiles.review=%s
                                          AND reviewfiles.file=%s""",
                itertools.izip(itertools.repeat(reviewer.id),
                               itertools.repeat(review_id), new_file_ids))

            cursor.executemany(
                """INSERT INTO reviewassignmentchanges (transaction, file, uid, assigned)
                                       SELECT %s, reviewfiles.id, %s, true
                                         FROM reviewfiles
                                        WHERE reviewfiles.review=%s
                                          AND reviewfiles.file=%s""",
                itertools.izip(itertools.repeat(transaction_id),
                               itertools.repeat(reviewer.id),
                               itertools.repeat(review_id), new_file_ids))

        if delete_file_ids or new_file_ids:
            cursor.execute("UPDATE reviews SET serial=serial+1 WHERE id=%s",
                           (review_id, ))

            pending_mails = review.utils.generateMailsForAssignmentsTransaction(
                db, transaction_id)

            db.commit()

            mailutils.sendPendingMails(pending_mails)

        return OperationResult()
示例#9
0
    def process(self, db, creator, review_id, filters):
        review = dbutils.Review.fromId(db, review_id)
        by_user = {}

        for filter in filters:
            if "user_ids" in filter:
                user_ids = set(filter["user_ids"])
            else:
                user_ids = set([])

            if "user_names" in filter:
                for user_name in filter["user_names"]:
                    user_ids.add(dbutils.User.fromName(db, user_name).id)

            if "paths" in filter:
                paths = set(
                    reviewing.filters.sanitizePath(path)
                    for path in filter["paths"])

                for path in paths:
                    try:
                        reviewing.filters.validatePattern(path)
                    except reviewing.filters.PatternError as error:
                        raise OperationFailure(
                            code="invalidpattern",
                            title="Invalid path pattern",
                            message=
                            "There are invalid wild-cards in the path: %s" %
                            error.message)
            else:
                paths = set()

            if "file_ids" in filter:
                for file_id in filter["file_ids"]:
                    paths.add(dbutils.describe_file(file_id))

            for user_id in user_ids:
                reviewer_paths, watcher_paths = by_user.setdefault(
                    user_id, (set(), set()))

                if filter["type"] == "reviewer":
                    reviewer_paths |= paths
                else:
                    watcher_paths |= paths

        pending_mails = []

        for user_id, (reviewer_paths, watcher_paths) in by_user.items():
            try:
                user = dbutils.User.fromId(db, user_id)
            except dbutils.InvalidUserId:
                raise OperationFailure(
                    code="invaliduserid",
                    title="Invalid user ID",
                    message=
                    "At least one of the specified user IDs was invalid.")
            pending_mails.extend(
                reviewing.utils.addReviewFilters(db, creator, user, review,
                                                 reviewer_paths,
                                                 watcher_paths))

        review = dbutils.Review.fromId(db, review_id)
        review.incrementSerial(db)

        db.commit()

        mailutils.sendPendingMails(pending_mails)

        return OperationResult()