Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
for changeset in changesets:
author_user_ids = changeset.child.author.getUserIds(db) if changeset.child else set()
cursor.execute("SELECT DISTINCT file FROM fileversions WHERE changeset=%s", (changeset.id,))
for (file_id,) in cursor:
reviewers_found = False
for user_id, (filter_type, delegate) in filters.listUsers(file_id).items():
if filter_type == 'reviewer':
if user_id not in author_user_ids:
reviewer_user_ids = [user_id]
elif delegate:
reviewer_user_ids = []
for delegate_user_name in delegate.split(","):
delegate_user = dbutils.User.fromName(db, delegate_user_name)
reviewer_user_ids.append(delegate_user.id)
else:
reviewer_user_ids = []
for reviewer_user_id in reviewer_user_ids:
reviewers.setdefault(file_id, {}).setdefault(reviewer_user_id, set()).add(changeset.id)
reviewers_found = True
else:
watchers.setdefault(file_id, {}).setdefault(user_id, set()).add(changeset.id)
if not reviewers_found:
reviewers.setdefault(file_id, {}).setdefault(None, set()).add(changeset.id)
return reviewers, watchers
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:
def process(self, db, user, repository_id, source_location, source_name,
target_name, users, forced=None):
cursor = db.cursor()
cursor.execute("""SELECT 1
FROM trackedbranches
WHERE repository=%s
AND local_name=%s""",
(repository_id, target_name))
if cursor.fetchone():
raise OperationError("branch '%s' already tracks another branch" % target_name)
users = [dbutils.User.fromName(db, username) for username in users]
if target_name.startswith("r/"):
cursor.execute("""SELECT 1
FROM reviews
JOIN branches ON (branches.id=reviews.branch)
WHERE branches.repository=%s
AND branches.name=%s""",
(repository_id, target_name))
if not cursor.fetchone():
raise OperationError("non-existing review branch can't track another branch")
if forced is None:
forced = True
elif forced is None:
forced = False
connection.unbind_s()
def getAttribute(name, defvalue=None):
value_list = attributes.get(name)
if value_list is None or not value_list or not value_list[0]:
defvalue
return value_list[0]
username = getAttribute(self.configuration["username_attribute"])
if username is None:
raise auth.AuthenticationError(
"Configured username LDAP attribute missing")
try:
user = dbutils.User.fromName(db, username)
except dbutils.NoSuchUser:
if not self.configuration["create_user"]:
raise auth.AuthenticationFailed("No matching Critic user found")
fullname = getAttribute(self.configuration["fullname_attribute"],
username)
email = getAttribute(self.configuration["email_attribute"])
user = dbutils.User.create(
db, username, fullname, email, email_verified=None)
db.setUser(user, authentication_labels)
self.cache.set(fields, (user.id, authentication_labels))
parser = argparse.ArgumentParser(
description="Critic administration interface: configtest",
prog="criticctl [options] configtest")
parser.add_argument("--user", "-u", help="Impersonate this user")
arguments = parser.parse_args(argv)
import api
critic = api.critic.startSession(for_user=bool(arguments.user),
for_system=not bool(arguments.user))
db = critic.database
if arguments.user:
db.setUser(dbutils.User.fromName(db, arguments.user))
IPython.embed()
return 0
def check(self, db):
self.user = dbutils.User.fromName(db, self.value)
def contribute(self, query):
def getAuthor(self, db):
return dbutils.User.fromName(db, self.__author_name)