How to use the dbutils.User function in DBUtils

To help you get started, we’ve selected a few DBUtils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jensl / critic / src / reviewing / comment / __init__.py View on Github external
    @staticmethod
    def fromId(db, id, user):
        cursor = db.cursor()
        cursor.execute("SELECT chain, batch, uid, time, state, comment, code FROM comments WHERE id=%s", (id,))
        row = cursor.fetchone()
        if not row: return None
        else:
            chain_id, batch_id, author_id, time, state, comment, code = row
            author = dbutils.User.fromId(db, author_id)
            adjusted_time = user.adjustTimestamp(db, time)
            when = user.formatTimestamp(db, time)
            cursor.execute("SELECT 1 FROM commentstoread WHERE uid=%s AND comment=%s", (user.id, id))
            return Comment(CommentChain.fromId(db, chain_id, user), batch_id, id, state, author, adjusted_time, when, comment, code, cursor.fetchone() is not None)
github jensl / critic / src / page / showcommit.py View on Github external
if review:
                approve = row.td("approve file")
                reviewers = {}

                for index, (file, lines) in enumerate(in_parent):
                    if file:
                        span = approve.span("parent%d" % index)

                        if review_files[index].has_key(file.id):
                            review_file = review_files[index][file.id]
                            can_approve = review_file[0]
                            is_approved = review_file[1] == "reviewed"

                            for user_id in review_file[2]:
                                reviewers[user_id] = dbutils.User.fromId(db, user_id)

                            if not is_approved: fully_approved = False
                        else:
                            can_approve = False
                            is_approved = True

                        if can_approve:
                            if is_approved: checked = "checked"
                            else: checked = None
                            input = span.input(type="checkbox", critic_parent_index=index, id="p%da%d" % (index, file.id), checked=checked)
                        elif not is_approved:
                            span.text("pending")

            row.td("path").a(href="#f%d" % file_id).innerHTML(file_path)

            for index, (file, lines) in enumerate(in_parent):
github jensl / critic / src / dbutils / database.py View on Github external
def forSystem(critic=None):
        import dbutils

        db = Database(critic)
        db.setUser(dbutils.User.makeSystem())
        return db
github jensl / critic / src / operation / applyfilters.py View on Github external
def process(self, db, user, review_id):
        review = dbutils.Review.fromId(db, review_id)
        reviewers, watchers = reviewing.utils.queryFilters(db, user, review, globalfilters=True)
        return OperationResult(reviewers=[dbutils.User.fromId(db, user_id).getJSON() for user_id in reviewers],
                               watchers=[dbutils.User.fromId(db, user_id).getJSON() for user_id in watchers])
github jensl / critic / dbutils.py View on Github external
    @staticmethod
    def fromName(db, name):
        cached_user = db.storage["User"].get("n:" + name)
        if cached_user: return cached_user
        else:
            cursor = db.cursor()
            cursor.execute("SELECT id, email, fullname, status FROM users WHERE name=%s", (name,))
            row = cursor.fetchone()
            if not row: raise NoSuchUser, name
            user_id, email, fullname, status = row
            return User.cache(db, User(user_id, name, email, fullname, status))
github jensl / critic / src / cli.py View on Github external
review = dbutils.Review.fromId(db, data["review_id"])
                    filters.setFiles(db, review=review)
                    filters.load(db, review=review, user=user,
                                 added_review_filters=data.get("added_review_filters", []),
                                 removed_review_filters=data.get("removed_review_filters", []))
                else:
                    repository = gitutils.Repository.fromId(db, data["repository_id"])
                    filters.setFiles(db, file_ids=data["file_ids"])
                    filters.load(db, repository=repository, recursive=data.get("recursive", False), user=user)
                sys.stdout.write(json_encode(filters.data) + "\n")
            elif command == "generate-custom-mails":
                pending_mails = []
                for data in json_decode(sys.stdin.readline()):
                    from_user = dbutils.User.fromId(db, data["sender"])
                    if data.get("recipients"):
                        recipients = [dbutils.User.fromId(db, user_id)
                                      for user_id in data["recipients"]]
                    else:
                        recipients = None
                    subject = data["subject"]
                    headers = data.get("headers")
                    body = data["body"]
                    if "review_id" in data:
                        review = dbutils.Review.fromId(db, data["review_id"])
                    else:
                        review = None
                    pending_mails.extend(sendCustomMail(
                        from_user, recipients, subject, headers, body, review))
            elif command == "set-review-state":
                data = json_decode(sys.stdin.readline())
                error = ""
                try:
github jensl / critic / src / extensions / role / processchanges.py View on Github external
cursor.execute("""SELECT extensions.id, extensions.author, extensions.name, extensionversions.sha1, roles.id, roles.script, roles.function
                        FROM extensions
                        JOIN extensionversions ON (extensionversions.extension=extensions.id)
                        JOIN extensionroles_processchanges AS roles ON (roles.version=extensionversions.id)
                       WHERE uid=%s AND roles.skip < %s""", (user_id, batch_id))

    rows = cursor.fetchall()

    if rows:
        for extension_id, author_id, extension_name, sha1, role_id, script, function in rows:
            cursor.execute("INSERT INTO extensionprocessedbatches (batch, role) VALUES (%s, %s)", (batch_id, role_id))

            # Don't do further processing of own batches.
            if batch_user_id == user_id: continue

            author = dbutils.User.fromId(db, author_id)

            if sha1 is None:
                extension_path = getExtensionPath(author.name, extension_name)
            else:
                extension_path = getExtensionInstallPath(sha1)

            class Error(Exception):
                pass

            def print_header():
                header = "%s::%s()" % (script, function)
                print >>output, "\n[%s] %s\n[%s] %s" % (extension_name, header, extension_name, "=" * len(header))

            try:
                try:
                    manifest = Manifest.load(extension_path)
github jensl / critic / src / auth / __init__.py View on Github external
if hashed is None:
        # No password set => there is no "right" password.
        raise WrongPassword

    ok, new_hashed = createCryptContext().verify_and_update(password, hashed)

    if not ok:
        raise WrongPassword

    if new_hashed:
        with db.updating_cursor("users") as cursor:
            cursor.execute("UPDATE users SET password=%s WHERE id=%s",
                           (new_hashed, user_id))

    return dbutils.User.fromId(db, user_id)
github jensl / critic / src / reviewing / utils.py View on Github external
LEFT OUTER JOIN chunks USING (changeset, file)
                                WHERE reviewchangesets.review=%s
                                  AND reviewchangesets.changeset=%s
                             GROUP BY reviewchangesets.review, reviewchangesets.changeset, fileversions.file""",
                       reviewchangesets_values)

    new_reviewers, new_watchers = assignChanges(db, user, review, changesets=changesets)

    cursor.execute("SELECT include FROM reviewrecipientfilters WHERE review=%s AND uid IS NULL", (review.id,))

    try: opt_out = cursor.fetchone()[0] is True
    except: opt_out = True

    if not new_review:
        for user_id in new_reviewers:
            new_reviewuser = dbutils.User.fromId(db, user_id)
            print "Added reviewer: %s <%s>" % (new_reviewuser.fullname, new_reviewuser.email)

            if opt_out:
                # If the user has opted out from receiving e-mails about this
                # review while only watching it, clear the opt-out now that the
                # user becomes a reviewer.
                cursor.execute("DELETE FROM reviewrecipientfilters WHERE review=%s AND uid=%s AND include=FALSE", (review.id, user_id))

        for user_id in new_watchers:
            new_reviewuser = dbutils.User.fromId(db, user_id)
            print "Added watcher:  %s <%s>" % (new_reviewuser.fullname, new_reviewuser.email)

        review.incrementSerial(db)

        reviewing.comment.propagateCommentChains(db, user, review, new_commits, replayed_rebases)