[aur-dev] [PATCH 1/2] Allow users to delete their own packages
Allow users to remove their own package bases for a short period of time after initial submission (defaults to one day). Implements FS#43648. Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- conf/config.proto | 1 + web/lib/pkgbasefuncs.inc.php | 5 +++-- web/lib/pkgreqfuncs.inc.php | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/conf/config.proto b/conf/config.proto index b4a381d..95194a7 100644 --- a/conf/config.proto +++ b/conf/config.proto @@ -25,6 +25,7 @@ max_rpc_results = 5000 aur_request_ml = aur-requests@archlinux.org request_idle_time = 1209600 auto_orphan_age = 15552000 +auto_delete_age = 86400 [auth] key-prefixes = ssh-rsa ssh-dss ecdsa-sha2-nistp256 ecdsa-sha2-nistp384 ecdsa-sha2-nistp521 ssh-ed25519 diff --git a/web/lib/pkgbasefuncs.inc.php b/web/lib/pkgbasefuncs.inc.php index 5741b01..6f9ef85 100644 --- a/web/lib/pkgbasefuncs.inc.php +++ b/web/lib/pkgbasefuncs.inc.php @@ -436,11 +436,12 @@ function pkgbase_unflag($base_ids) { * @param array $base_ids Array of package base IDs to delete * @param int $merge_base_id Package base to merge the deleted ones into * @param int $via Package request to close upon deletion + * @param bool $grant Allow anyone to delete the package base * * @return array Tuple of success/failure indicator and error message */ -function pkgbase_delete ($base_ids, $merge_base_id, $via) { - if (!has_credential(CRED_PKGBASE_DELETE)) { +function pkgbase_delete ($base_ids, $merge_base_id, $via, $grant=false) { + if (!$grant && !has_credential(CRED_PKGBASE_DELETE)) { return array(false, __("You do not have permission to delete packages.")); } diff --git a/web/lib/pkgreqfuncs.inc.php b/web/lib/pkgreqfuncs.inc.php index a5d6be8..0fab447 100644 --- a/web/lib/pkgreqfuncs.inc.php +++ b/web/lib/pkgreqfuncs.inc.php @@ -184,6 +184,7 @@ function pkgreq_file($ids, $type, $merge_into, $comments) { " Request for " . $row['Name'], $body, $headers); $auto_orphan_age = config_get('options', 'auto_orphan_age'); + $auto_delete_age = config_get('options', 'auto_delete_age'); $details = pkgbase_get_details($base_id); if ($type == 'orphan' && $details['OutOfDateTS'] > 0 && time() - $details['OutOfDateTS'] >= $auto_orphan_age && @@ -201,6 +202,19 @@ function pkgreq_file($ids, $type, $merge_into, $comments) { $q = "UPDATE PackageBases SET MaintainerUID = NULL "; $q.= "WHERE ID = " . $base_id; $dbh->exec($q); + } else if ($type == 'deletion' && $details['MaintainerUID'] == $uid && + $details['SubmittedTS'] > 0 && $auto_delete_age > 0 && + time() - $details['SubmittedTS'] <= $auto_delete_age) { + /* + * Close package request. NOTE: This needs to happen *before* + * the actual deletion operation. Otherwise, the former + * maintainer will not be included in the Cc list of the + * request notification email. + */ + pkgreq_close($request_id, "accepted", + "Deletion of a fresh package requested by its " . + "current maintainer.", true); + pkgbase_delete(array($base_id), NULL, NULL, true); } return array(true, __("Added request successfully.")); -- 2.3.1
Close requests automatically when a package is deleted or orphaned. Implements FS#43799. Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- web/lib/pkgbasefuncs.inc.php | 31 ++++++++++++++++++++++++++++++- web/lib/pkgreqfuncs.inc.php | 21 +++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/web/lib/pkgbasefuncs.inc.php b/web/lib/pkgbasefuncs.inc.php index 6f9ef85..3f02bc7 100644 --- a/web/lib/pkgbasefuncs.inc.php +++ b/web/lib/pkgbasefuncs.inc.php @@ -509,6 +509,22 @@ function pkgbase_delete ($base_ids, $merge_base_id, $via, $grant=false) { pkgreq_close(intval($via), 'accepted', ''); } + /* Scan through pending deletion requests and close them. */ + if (!$action) { + $username = username_from_sid($_COOKIE['AURSID']); + foreach ($base_ids as $base_id) { + $pkgreq_ids = array_merge( + pkgreq_by_pkgbase($base_id, 'deletion'), + pkgreq_by_pkgbase($base_id, 'merge'), + pkgreq_by_pkgbase($base_id, 'orphan')); + foreach ($pkgreq_ids as $pkgreq_id) { + pkgreq_close(intval($pkgreq_id), 'accepted', + 'The user ' . $username . + ' deleted the package.', true); + } + } + } + if ($merge_base_id) { /* Merge comments */ $q = "UPDATE PackageComments "; @@ -555,6 +571,8 @@ function pkgbase_delete ($base_ids, $merge_base_id, $via, $grant=false) { * @return array Tuple of success/failure indicator and error message */ function pkgbase_adopt ($base_ids, $action=true, $via) { + $dbh = DB::connect(); + $uid = uid_from_sid($_COOKIE["AURSID"]); if (!$uid) { if ($action) { @@ -583,7 +601,18 @@ function pkgbase_adopt ($base_ids, $action=true, $via) { pkgreq_close(intval($via), 'accepted', ''); } - $dbh = DB::connect(); + /* Scan through pending orphan requests and close them. */ + if (!$action) { + $username = username_from_sid($_COOKIE['AURSID']); + foreach ($base_ids as $base_id) { + $pkgreq_ids = pkgreq_by_pkgbase($base_id, 'orphan'); + foreach ($pkgreq_ids as $pkgreq_id) { + pkgreq_close(intval($pkgreq_id), 'accepted', + 'The user ' . $username . + ' disowned the package.', true); + } + } + } $q = "UPDATE PackageBases "; if ($action) { diff --git a/web/lib/pkgreqfuncs.inc.php b/web/lib/pkgreqfuncs.inc.php index 0fab447..e4c63b5 100644 --- a/web/lib/pkgreqfuncs.inc.php +++ b/web/lib/pkgreqfuncs.inc.php @@ -42,6 +42,27 @@ function pkgreq_list($offset, $limit) { } /** + * Get a list of all open package requests belonging to a certain package base + * + * @param int $baseid The package base ID to retrieve requests for + * @param int $type The type of requests to obtain + * + * @return array List of package request IDs + */ +function pkgreq_by_pkgbase($baseid, $type) { + $dbh = DB::connect(); + + $q = "SELECT PackageRequests.ID "; + $q.= "FROM PackageRequests INNER JOIN RequestTypes ON "; + $q.= "RequestTypes.ID = PackageRequests.ReqTypeID "; + $q.= "WHERE PackageRequests.Status = 0 "; + $q.= "AND PackageRequests.PackageBaseID = " . intval($baseid) . " "; + $q.= "AND RequestTypes.Name = " . $dbh->quote($type); + + return $dbh->query($q)->fetchAll(PDO::FETCH_COLUMN, 0); +} + +/** * Obtain the package base that belongs to a package request. * * @param int $id Package request ID to retrieve the package base for -- 2.3.1
participants (1)
-
Lukas Fleischer