From 8a465182babccec10b8e789dbc871db3beb9bec5 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Fri, 4 Jul 2014 10:40:29 +0200 Subject: 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 --- web/html/index.php | 19 +++++++++++++++++++ web/html/pkgbase.php | 2 +- web/html/pkgreq.php | 12 ++++++++---- web/lib/pkgbasefuncs.inc.php | 4 ++-- web/lib/pkgreqfuncs.inc.php | 27 +++++++++++++++++++++++---- web/template/pkgreq_close_form.php | 24 ++++++++++++++++++++++++ web/template/pkgreq_results.php | 14 +++----------- 7 files changed, 80 insertions(+), 22 deletions(-) create mode 100644 web/template/pkgreq_close_form.php (limited to 'web') diff --git a/web/html/index.php b/web/html/index.php index 40063f0..554e86c 100644 --- a/web/html/index.php +++ b/web/html/index.php @@ -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]); } elseif (!empty($tokens[1]) && '/' . $tokens[1] == get_user_route()) { if (!empty($tokens[2])) { diff --git a/web/html/pkgbase.php b/web/html/pkgbase.php index 5e27e4e..6202180 100644 --- a/web/html/pkgbase.php +++ b/web/html/pkgbase.php @@ -105,7 +105,7 @@ if (check_token()) { $ret = false; } } 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'])) { diff --git a/web/html/pkgreq.php b/web/html/pkgreq.php index 4b7d6cf..9dec1f6 100644 --- a/web/html/pkgreq.php +++ b/web/html/pkgreq.php @@ -8,7 +8,14 @@ include_once("pkgfuncs.inc.php"); set_lang(); 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()) { header('Location: /'); exit(); @@ -63,9 +70,6 @@ if (!isset($base_id)) { html_header(__("Requests")); include('pkgreq_results.php'); -} else { - html_header(__("File Request")); - include('pkgreq_form.php'); } html_footer(AUR_VERSION); diff --git a/web/lib/pkgbasefuncs.inc.php b/web/lib/pkgbasefuncs.inc.php index 0ee2c31..4c1f452 100644 --- a/web/lib/pkgbasefuncs.inc.php +++ b/web/lib/pkgbasefuncs.inc.php @@ -540,7 +540,7 @@ function pkgbase_delete ($atype, $base_ids, $merge_base_id, $via) { $dbh->exec($q); if ($via) { - pkgreq_close(intval($via), true); + pkgreq_close(intval($via), 'accepted'); } 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); if ($via) { - pkgreq_close(intval($via), true); + pkgreq_close(intval($via), 'accepted'); } if ($action) { diff --git a/web/lib/pkgreqfuncs.inc.php b/web/lib/pkgreqfuncs.inc.php index a79677e..0309bc3 100644 --- a/web/lib/pkgreqfuncs.inc.php +++ b/web/lib/pkgreqfuncs.inc.php @@ -40,6 +40,22 @@ function pkgreq_list($offset, $limit) { 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 * @@ -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_REQUEST_ML The request notification mailing list * @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 */ -function pkgreq_close($id, $accepted) { +function pkgreq_close($id, $reason) { global $AUR_LOCATION; global $AUR_REQUEST_ML; + if ($reason != 'accepted' && $reason != 'rejected') { + return array(false, __("Invalid reason.")); + } + $dbh = DB::connect(); $id = intval($id); @@ -181,8 +201,7 @@ function pkgreq_close($id, $accepted) { * user who posted the comment was in. */ $username = username_from_sid($_COOKIE['AURSID']); - $body = "Request #" . intval($id) . " has been " . - ($accepted ? "accepted" : "closed") . " by " . + $body = "Request #" . intval($id) . " has been " . $reason . " by " . $username . " [1].\n\n" . "[1] " . $AUR_LOCATION . get_user_uri($username) . "\n"; $body = wordwrap($body, 70); diff --git a/web/template/pkgreq_close_form.php b/web/template/pkgreq_close_form.php new file mode 100644 index 0000000..be36aef --- /dev/null +++ b/web/template/pkgreq_close_form.php @@ -0,0 +1,24 @@ +
+

+

+ ', htmlspecialchars($pkgbase_name), ''); ?> +

+
+
+ + +

+ + +

+

+ " /> +

+
+
+
+ diff --git a/web/template/pkgreq_results.php b/web/template/pkgreq_results.php index 9cd6faf..b5e1177 100644 --- a/web/template/pkgreq_results.php +++ b/web/template/pkgreq_results.php @@ -51,8 +51,10 @@ +
+
@@ -61,17 +63,7 @@
-
-
- - - - -
- " /> -
-
-
+ -- cgit v1.2.3-54-g00ecf