Allow for selecting a reason when closing a request

When closing a package request, Trusted Users can now pick a reason
("Accepted" or "Rejected"). This allows for marking a request as
accepted, even if the corresponding package base has already been
deleted.

Also, the notification email now always explicitly states whether a
request has been accepted or closed in the message body.

Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
This commit is contained in:
Lukas Fleischer 2014-07-04 10:40:29 +02:00
parent 61d70c1fa5
commit 8a465182ba
7 changed files with 80 additions and 22 deletions

View file

@ -88,6 +88,25 @@ if (!empty($tokens[1]) && '/' . $tokens[1] == get_pkg_route()) {
} }
} }
include get_route('/' . $tokens[1]);
} elseif (!empty($tokens[1]) && '/' . $tokens[1] == get_pkgreq_route()) {
if (!empty($tokens[2])) {
/* TODO: Create a proper data structure to pass variables from
* the routing framework to the individual pages instead of
* initializing arbitrary variables here. */
if (!empty($tokens[3]) && $tokens[3] == 'close') {
$pkgreq_id = $tokens[2];
} else {
$pkgreq_id = null;
}
if (!$pkgreq_id) {
header("HTTP/1.0 404 Not Found");
include "./404.php";
return;
}
}
include get_route('/' . $tokens[1]); include get_route('/' . $tokens[1]);
} elseif (!empty($tokens[1]) && '/' . $tokens[1] == get_user_route()) { } elseif (!empty($tokens[1]) && '/' . $tokens[1] == get_user_route()) {
if (!empty($tokens[2])) { if (!empty($tokens[2])) {

View file

@ -105,7 +105,7 @@ if (check_token()) {
$ret = false; $ret = false;
} }
} elseif (current_action("do_CloseRequest")) { } elseif (current_action("do_CloseRequest")) {
list($ret, $output) = pkgreq_close($_POST['reqid'], false); list($ret, $output) = pkgreq_close($_POST['reqid'], $_POST['reason']);
} }
if (isset($_REQUEST['comment'])) { if (isset($_REQUEST['comment'])) {

View file

@ -8,7 +8,14 @@ include_once("pkgfuncs.inc.php");
set_lang(); set_lang();
check_sid(); check_sid();
if (!isset($base_id)) { if (isset($base_id)) {
html_header(__("File Request"));
include('pkgreq_form.php');
} elseif (isset($pkgreq_id)) {
html_header(__("Close Request"));
$pkgbase_name = pkgreq_get_pkgbase_name($pkgreq_id);
include('pkgreq_close_form.php');
} else {
if (!check_user_privileges()) { if (!check_user_privileges()) {
header('Location: /'); header('Location: /');
exit(); exit();
@ -63,9 +70,6 @@ if (!isset($base_id)) {
html_header(__("Requests")); html_header(__("Requests"));
include('pkgreq_results.php'); include('pkgreq_results.php');
} else {
html_header(__("File Request"));
include('pkgreq_form.php');
} }
html_footer(AUR_VERSION); html_footer(AUR_VERSION);

View file

@ -540,7 +540,7 @@ function pkgbase_delete ($atype, $base_ids, $merge_base_id, $via) {
$dbh->exec($q); $dbh->exec($q);
if ($via) { if ($via) {
pkgreq_close(intval($via), true); pkgreq_close(intval($via), 'accepted');
} }
return array(true, __("The selected packages have been deleted.")); return array(true, __("The selected packages have been deleted."));
@ -598,7 +598,7 @@ function pkgbase_adopt ($atype, $base_ids, $action=true, $via) {
$dbh->exec($q); $dbh->exec($q);
if ($via) { if ($via) {
pkgreq_close(intval($via), true); pkgreq_close(intval($via), 'accepted');
} }
if ($action) { if ($action) {

View file

@ -40,6 +40,22 @@ function pkgreq_list($offset, $limit) {
return $dbh->query($q)->fetchAll(); return $dbh->query($q)->fetchAll();
} }
/**
* Obtain the package base that belongs to a package request.
*
* @param int $id Package request ID to retrieve the package base for
*
* @return int The name of the corresponding package base
*/
function pkgreq_get_pkgbase_name($id) {
$dbh = DB::connect();
$q = "SELECT PackageBaseName FROM PackageRequests ";
$q.= "WHERE ID = " . intval($id);
$result = $dbh->query($q);
return $result->fetch(PDO::FETCH_COLUMN, 0);
}
/** /**
* File a deletion/orphan request against a package base * File a deletion/orphan request against a package base
* *
@ -139,14 +155,18 @@ function pkgreq_file($ids, $type, $merge_into, $comments) {
* @global string $AUR_LOCATION The AUR's URL used for notification e-mails * @global string $AUR_LOCATION The AUR's URL used for notification e-mails
* @global string $AUR_REQUEST_ML The request notification mailing list * @global string $AUR_REQUEST_ML The request notification mailing list
* @param int $id The package request to close * @param int $id The package request to close
* @param bool $accepted True if the request has been accepted, false otherwise * @param string $reason Whether the request was accepted or rejected
* *
* @return array Tuple of success/failure indicator and error message * @return array Tuple of success/failure indicator and error message
*/ */
function pkgreq_close($id, $accepted) { function pkgreq_close($id, $reason) {
global $AUR_LOCATION; global $AUR_LOCATION;
global $AUR_REQUEST_ML; global $AUR_REQUEST_ML;
if ($reason != 'accepted' && $reason != 'rejected') {
return array(false, __("Invalid reason."));
}
$dbh = DB::connect(); $dbh = DB::connect();
$id = intval($id); $id = intval($id);
@ -181,8 +201,7 @@ function pkgreq_close($id, $accepted) {
* user who posted the comment was in. * user who posted the comment was in.
*/ */
$username = username_from_sid($_COOKIE['AURSID']); $username = username_from_sid($_COOKIE['AURSID']);
$body = "Request #" . intval($id) . " has been " . $body = "Request #" . intval($id) . " has been " . $reason . " by " .
($accepted ? "accepted" : "closed") . " by " .
$username . " [1].\n\n" . $username . " [1].\n\n" .
"[1] " . $AUR_LOCATION . get_user_uri($username) . "\n"; "[1] " . $AUR_LOCATION . get_user_uri($username) . "\n";
$body = wordwrap($body, 70); $body = wordwrap($body, 70);

View file

@ -0,0 +1,24 @@
<div class="box">
<h2><?= __('Close Request: %s', htmlspecialchars($pkgbase_name)) ?></h2>
<p>
<?= __('Use this form to close the request for package base %s%s%s.',
'<strong>', htmlspecialchars($pkgbase_name), '</strong>'); ?>
</p>
<form action="<?= get_uri('/pkgbase/'); ?>" method="post">
<fieldset>
<input type="hidden" name="reqid" value="<?= $pkgreq_id ?>" />
<input type="hidden" name="token" value="<?= htmlspecialchars($_COOKIE['AURSID']) ?>" />
<p>
<label for="id_reason"><?= __("Reason") ?>:</label>
<select name="reason" id="id_reason">
<option value="accepted"><?= __('Accepted') ?></option>
<option value="rejected"><?= __('Rejected') ?></option>
</select>
</p>
<p>
<input type="submit" class="button" name="do_CloseRequest" value="<?= __("Close Request") ?>" />
</p>
</fieldset>
</form>
</div>

View file

@ -51,8 +51,10 @@
<?php if ($row['BaseID']): ?> <?php if ($row['BaseID']): ?>
<?php if ($row['Type'] == 'deletion'): ?> <?php if ($row['Type'] == 'deletion'): ?>
<a href="<?= get_pkgbase_uri($row['Name']) ?>delete/?via=<?= intval($row['ID']) ?>"><?= __('Accept') ?></a> <a href="<?= get_pkgbase_uri($row['Name']) ?>delete/?via=<?= intval($row['ID']) ?>"><?= __('Accept') ?></a>
<br/ >
<?php elseif ($row['Type'] == 'merge'): ?> <?php elseif ($row['Type'] == 'merge'): ?>
<a href="<?= get_pkgbase_uri($row['Name']) ?>merge/?into=<?= urlencode($row['MergeInto']) ?>&via=<?= intval($row['ID']) ?>"><?= __('Accept') ?></a> <a href="<?= get_pkgbase_uri($row['Name']) ?>merge/?into=<?= urlencode($row['MergeInto']) ?>&via=<?= intval($row['ID']) ?>"><?= __('Accept') ?></a>
<br />
<?php elseif ($row['Type'] == 'orphan'): ?> <?php elseif ($row['Type'] == 'orphan'): ?>
<form action="<?= get_pkgbase_uri($row['Name']) . 'disown/'; ?>" method="post"> <form action="<?= get_pkgbase_uri($row['Name']) . 'disown/'; ?>" method="post">
<input type="hidden" name="token" value="<?= htmlspecialchars($_COOKIE['AURSID']) ?>" /> <input type="hidden" name="token" value="<?= htmlspecialchars($_COOKIE['AURSID']) ?>" />
@ -61,17 +63,7 @@
</form> </form>
<?php endif; ?> <?php endif; ?>
<?php endif; ?> <?php endif; ?>
<form action="<?= get_uri('/pkgbase/'); ?>" method="post"> <a href="<?= get_pkgreq_route() . '/' . intval($row['ID']) ?>/close/"><?= __('Close') ?></a>
<fieldset>
<input type="hidden" name="IDs[<?= $row['BaseID'] ?>]" value="1" />
<input type="hidden" name="ID" value="<?= $row['BaseID'] ?>" />
<input type="hidden" name="token" value="<?= htmlspecialchars($_COOKIE['AURSID']) ?>" />
<input type="hidden" name="reqid" value="<?= $row['ID'] ?>" />
<div>
<input type="submit" class="button text-button" name="do_CloseRequest" value="<?= __("Close") ?>" />
</div>
</fieldset>
</form>
</td> </td>
<?php else: ?> <?php else: ?>
<td><?= __("Closed") ?></td> <td><?= __("Closed") ?></td>