Commit fc6dc442 authored by Lukas Fleischer's avatar Lukas Fleischer
Browse files

git-serve: Close orphan requests upon disown



When disowning a package base via the SSH interface, auto-accept all
pending orphan requests for the affected package.

Also, add a test case that checks whether (only) orphan requests
belonging to disowned packages are closed correctly.
Signed-off-by: Lukas Fleischer's avatarLukas Fleischer <lfleischer@archlinux.org>
parent 51101d21
......@@ -183,6 +183,44 @@ def pkgbase_set_comaintainers(pkgbase, userlist, user, privileged):
conn.close()
def pkgreq_by_pkgbase(pkgbase_id, reqtype):
conn = aurweb.db.Connection()
cur = conn.execute("SELECT PackageRequests.ID FROM PackageRequests " +
"INNER JOIN RequestTypes ON " +
"RequestTypes.ID = PackageRequests.ReqTypeID " +
"WHERE PackageRequests.Status = 0 " +
"AND PackageRequests.PackageBaseID = ?" +
"AND RequestTypes.Name = ?", [pkgbase_id, reqtype])
return [row[0] for row in cur.fetchall()]
def pkgreq_close(reqid, reason, comments, autoclose=False):
statusmap = {'accepted': 2, 'rejected': 3}
if reason not in statusmap:
die('{:s}: invalid reason: {:s}'.format(action, reason))
status = statusmap[reason]
conn = aurweb.db.Connection()
if autoclose:
userid = 0
else:
cur = conn.execute("SELECT ID FROM Users WHERE Username = ?", [user])
userid = cur.fetchone()[0]
if userid == 0:
die('{:s}: unknown user: {:s}'.format(action, user))
conn.execute("UPDATE PackageRequests SET Status = ?, ClosureComment = ? " +
"WHERE ID = ?", [status, comments, reqid])
conn.commit()
conn.close()
subprocess.Popen((notify_cmd, 'request-close', str(userid), str(reqid),
reason)).wait()
def pkgbase_disown(pkgbase, user, privileged):
pkgbase_id = pkgbase_from_name(pkgbase)
if not pkgbase_id:
......@@ -193,7 +231,11 @@ def pkgbase_disown(pkgbase, user, privileged):
die('{:s}: permission denied: {:s}'.format(action, user))
# TODO: Support disowning package bases via package request.
# TODO: Scan through pending orphan requests and close them.
# Scan through pending orphan requests and close them.
comment = 'The user {:s} disowned the package.'.format(user)
for reqid in pkgreq_by_pkgbase(pkgbase_id, 'orphan'):
pkgreq_close(reqid, 'accepted', comment, True)
comaintainers = []
new_maintainer_userid = None
......
......@@ -317,4 +317,27 @@ test_expect_success "Force-disown a package base and check (co-)maintainer list.
test_cmp expected actual
'
test_expect_success "Check whether package requests are closed when disowning." '
SSH_ORIGINAL_COMMAND="adopt foobar" AUR_USER=user AUR_PRIVILEGED=0 \
"$GIT_SERVE" 2>&1 &&
cat <<-EOD | sqlite3 aur.db &&
INSERT INTO PackageRequests (ID, ReqTypeID, PackageBaseID, PackageBaseName, UsersID) VALUES (1, 2, 3, "foobar", 4);
INSERT INTO PackageRequests (ID, ReqTypeID, PackageBaseID, PackageBaseName, UsersID) VALUES (2, 3, 3, "foobar", 5);
INSERT INTO PackageRequests (ID, ReqTypeID, PackageBaseID, PackageBaseName, UsersID) VALUES (3, 2, 2, "foobar2", 6);
EOD
>sendmail.out &&
SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=user AUR_PRIVILEGED=0 \
"$GIT_SERVE" 2>&1 &&
cat <<-EOD >expected &&
Subject: [PRQ#1] Request Accepted
EOD
grep "^Subject.*PRQ" sendmail.out >sendmail.parts &&
test_cmp sendmail.parts expected &&
cat <<-EOD >expected &&
1|2|3|foobar||4||The user user disowned the package.|0|2
EOD
echo "SELECT * FROM PackageRequests WHERE Status = 2;" | sqlite3 aur.db >actual &&
test_cmp actual expected
'
test_done
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment