[aur-dev] [PATCH 1/4] Add functions for getting arrays of maintainer and co-maintainer UIDs
Signed-off-by: Johannes Löthberg <johannes@kyriasis.com> --- web/lib/pkgbasefuncs.inc.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/web/lib/pkgbasefuncs.inc.php b/web/lib/pkgbasefuncs.inc.php index c8c99eb..d12a228 100644 --- a/web/lib/pkgbasefuncs.inc.php +++ b/web/lib/pkgbasefuncs.inc.php @@ -318,6 +318,19 @@ function pkgbase_maintainer_uid($base_id) { return $result->fetch(PDO::FETCH_COLUMN, 0); } +/** + * Retrieve the maintainers of an array of package bases given by their ID + * + * @param int $base_ids The array of IDs of the package bases to query + * + * @return int The user ID of the current package maintainer + */ +function pkgbase_maintainer_uids($base_ids) { + $dbh = DB::connect(); + $q = "SELECT MaintainerUID FROM PackageBases WHERE ID IN (" . implode(",", $base_ids) . ")"; + $result = $dbh->query($q); + return $result->fetchAll(PDO::FETCH_COLUMN, 0); +} /** * Flag package(s) as out-of-date @@ -993,6 +1006,28 @@ function pkgbase_get_comaintainers($base_id) { } /** + * Get a list of package base co-maintainer IDs + * + * @param int $base_id The package base ID to retrieve the co-maintainers for + * + * @return array An array of co-maintainer user UDs + */ +function pkgbase_get_comaintainer_uids($base_ids) { + $dbh = DB::connect(); + $q = "SELECT UsersID FROM PackageComaintainers "; + $q .= "INNER JOIN Users ON Users.ID = PackageComaintainers.UsersID "; + $q .= "WHERE PackageComaintainers.PackageBaseID IN (" . implode(",", $base_ids) . ") "; + $q .= "ORDER BY Priority ASC"; + $result = $dbh->query($q); + + if ($result) { + return $result->fetchAll(PDO::FETCH_COLUMN, 0); + } else { + return array(); + } +} + +/** * Update the list of co-maintainers of a package base * * @param int $base_id The package base ID to update the co-maintainers of -- 2.4.4
Signed-off-by: Johannes Löthberg <johannes@kyriasis.com> --- web/lib/pkgbasefuncs.inc.php | 3 ++- web/template/pkg_details.php | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/web/lib/pkgbasefuncs.inc.php b/web/lib/pkgbasefuncs.inc.php index d12a228..d9185e7 100644 --- a/web/lib/pkgbasefuncs.inc.php +++ b/web/lib/pkgbasefuncs.inc.php @@ -411,7 +411,8 @@ function pkgbase_unflag($base_ids) { $q.= "OutOfDateTS = NULL "; $q.= "WHERE ID IN (" . implode(",", $base_ids) . ") "; - if (!has_credential(CRED_PKGBASE_UNFLAG)) { + $maintainers = array_merge(pkgbase_maintainer_uids($base_ids), pkgbase_get_comaintainer_uids($base_ids)); + if (!has_credential(CRED_PKGBASE_UNFLAG, $maintainers)) { $q.= "AND MaintainerUID = " . $uid; } diff --git a/web/template/pkg_details.php b/web/template/pkg_details.php index 2f121e7..fb81442 100644 --- a/web/template/pkg_details.php +++ b/web/template/pkg_details.php @@ -18,6 +18,12 @@ $maintainer = username_from_id($row["MaintainerUID"]); $comaintainers = pkgbase_get_comaintainers($base_id); $packager = username_from_id($row["PackagerUID"]); +if ($row["MaintainerUID"] !== NULL) { + $maintainers = array_merge(array($row["MaintainerUID"]), pkgbase_get_comaintainer_uids(array($base_id))); +} else { + $maintainers = NULL; +} + $votes = $row['NumVotes']; # In case of wanting to put a custom message @@ -99,7 +105,7 @@ $sources = pkg_sources($row["ID"]); <input type="submit" class="button text-button" name="do_Flag" value="<?= __('Flag package out-of-date') ?>" /> </form> </li> - <?php elseif (($row["OutOfDateTS"] !== NULL) && has_credential(CRED_PKGBASE_UNFLAG, array($row["MaintainerUID"]))): ?> + <?php elseif (($row["OutOfDateTS"] !== NULL) && has_credential(CRED_PKGBASE_UNFLAG, $maintainers)): ?> <li> <form action="<?= get_pkgbase_uri($row['BaseName']) . 'unflag/'; ?>" method="post"> <input type="hidden" name="token" value="<?= htmlspecialchars($_COOKIE['AURSID']) ?>" /> -- 2.4.4
Signed-off-by: Johannes Löthberg <johannes@kyriasis.com> --- web/lib/pkgbasefuncs.inc.php | 3 ++- web/template/pkg_details.php | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/web/lib/pkgbasefuncs.inc.php b/web/lib/pkgbasefuncs.inc.php index d9185e7..92202bf 100644 --- a/web/lib/pkgbasefuncs.inc.php +++ b/web/lib/pkgbasefuncs.inc.php @@ -957,7 +957,8 @@ function pkgbase_get_keywords($base_id) { function pkgbase_set_keywords($base_id, $keywords) { $base_id = intval($base_id); - if (!has_credential(CRED_PKGBASE_SET_KEYWORDS, array(pkgbase_maintainer_uid($base_id)))) { + $maintainers = array_merge(array(pkgbase_maintainer_uid($base_id)), pkgbase_get_comaintainer_uids(array($base_id))); + if (!has_credential(CRED_PKGBASE_SET_KEYWORDS, $maintainers)) { return array(false, __("You are not allowed to edit the keywords of this package base.")); } diff --git a/web/template/pkg_details.php b/web/template/pkg_details.php index fb81442..9a360e3 100644 --- a/web/template/pkg_details.php +++ b/web/template/pkg_details.php @@ -196,13 +196,13 @@ $sources = pkg_sources($row["ID"]); <td><a href="<?= htmlspecialchars($row['URL'], ENT_QUOTES) ?>" title="<?= __('Visit the website for') . ' ' . htmlspecialchars( $row['Name'])?>"><?= htmlspecialchars($row['URL'], ENT_QUOTES) ?></a></td> </tr> <?php -if (has_credential(CRED_PKGBASE_SET_KEYWORDS, array($row["MaintainerUID"])) || count($keywords) > 0): +if (has_credential(CRED_PKGBASE_SET_KEYWORDS, $maintainers) || count($keywords) > 0): ?> <tr> <th><?= __('Keywords') . ': ' ?></th> <td> <?php -if (has_credential(CRED_PKGBASE_SET_KEYWORDS, array($row["MaintainerUID"]))): +if (has_credential(CRED_PKGBASE_SET_KEYWORDS, $maintainers)): ?> <form method="post" action="<?= htmlspecialchars(get_pkgbase_uri($row['BaseName']), ENT_QUOTES); ?>"> <div> -- 2.4.4
Signed-off-by: Johannes Löthberg <johannes@kyriasis.com> --- web/template/pkg_details.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/template/pkg_details.php b/web/template/pkg_details.php index 9a360e3..82bc262 100644 --- a/web/template/pkg_details.php +++ b/web/template/pkg_details.php @@ -178,7 +178,7 @@ $sources = pkg_sources($row["ID"]); <th><?= __('Git Clone URL') . ': ' ?></th> <td> <a href="<?= $git_clone_uri_anon ?>"><?= $git_clone_uri_anon ?></a> (<?= __('read-only') ?>) - <?php if ($uid == $row["MaintainerUID"]): ?> + <?php if (in_array($uid, $maintainers)): ?> <br /> <a href="<?= $git_clone_uri_priv ?>"><?= $git_clone_uri_priv ?></a> <?php endif; ?> </td> -- 2.4.4
participants (1)
-
Johannes Löthberg