From fc23a9bd5012d07cc6ef9d1eba12f320763068d9 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Wed, 7 Jan 2015 12:10:53 +0100 Subject: Add support for package base co-maintainers This allows for having multiple co-maintainers for AUR packages. Co-maintainers have push access to the package base Git repository but are not allowed to change the package base category, disown the package or modify the list of co-maintainers. The primary maintainer of an AUR package can edit the list of co-maintainers from the Package Actions box. Implements FS#17911. Signed-off-by: Lukas Fleischer --- web/html/comaintainers.php | 21 ++++++++++++ web/html/index.php | 3 ++ web/html/pkgbase.php | 4 ++- web/lib/credentials.inc.php | 2 ++ web/lib/pkgbasefuncs.inc.php | 64 +++++++++++++++++++++++++++++++++++++ web/template/comaintainers_form.php | 20 ++++++++++++ web/template/pkg_details.php | 3 ++ web/template/pkgbase_details.php | 3 ++ 8 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 web/html/comaintainers.php create mode 100644 web/template/comaintainers_form.php (limited to 'web') diff --git a/web/html/comaintainers.php b/web/html/comaintainers.php new file mode 100644 index 0000000..591fcad --- /dev/null +++ b/web/html/comaintainers.php @@ -0,0 +1,21 @@ +exec($q); } + +/** + * Get a list of package base co-maintainers + * + * @param int $base_id The package base ID to retrieve the co-maintainers for + * + * @return array An array of co-maintainer user names + */ +function pkgbase_get_comaintainers($base_id) { + $dbh = DB::connect(); + $q = "SELECT UserName FROM PackageComaintainers "; + $q .= "INNER JOIN Users ON Users.ID = PackageComaintainers.UsersID "; + $q .= "WHERE PackageComaintainers.PackageBaseID = " . intval($base_id); + $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 + * @param array $users Array of co-maintainer user names + * + * @return array Tuple of success/failure indicator and error message + */ +function pkgbase_set_comaintainers($base_id, $users) { + if (!has_credential(CRED_PKGBASE_EDIT_COMAINTAINERS, array(pkgbase_maintainer_uid($base_id)))) { + return array(false, __("You are not allowed to manage co-maintainers of this package base.")); + } + + /* Remove empty and duplicate user names. */ + $users = array_unique(array_filter(array_map('trim', $users))); + + $dbh = DB::connect(); + + $uids = array(); + foreach($users as $user) { + $q = "SELECT ID FROM Users "; + $q .= "WHERE UserName = " . $dbh->quote($user); + $result = $dbh->query($q); + $uid = $result->fetchColumn(0); + + if (!$uid) { + return array(false, __("Invalid user name: %s", $user)); + } + + $uids[] = $uid; + } + + $q = sprintf("DELETE FROM PackageComaintainers WHERE PackageBaseID = %d", $base_id); + $dbh->exec($q); + + foreach ($uids as $uid) { + $q = sprintf("INSERT INTO PackageComaintainers (PackageBaseID, UsersID) VALUES (%d, %d)", $base_id, $uid); + $dbh->exec($q); + } + + return array(true, __("The package base co-maintainers have been updated.")); +} diff --git a/web/template/comaintainers_form.php b/web/template/comaintainers_form.php new file mode 100644 index 0000000..050f255 --- /dev/null +++ b/web/template/comaintainers_form.php @@ -0,0 +1,20 @@ +
+

+

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

+
+
+ +

+ + +

+

+ " /> +

+
+
+
+ diff --git a/web/template/pkg_details.php b/web/template/pkg_details.php index ecb081c..359ea3c 100644 --- a/web/template/pkg_details.php +++ b/web/template/pkg_details.php @@ -131,6 +131,9 @@ $sources = pkg_sources($row["ID"]); + +
  • +
  • 0) { echo _n('%d pending request', '%d pending requests', $row["RequestCount"]); } ?>
  • diff --git a/web/template/pkgbase_details.php b/web/template/pkgbase_details.php index e698fb0..ae363fd 100644 --- a/web/template/pkgbase_details.php +++ b/web/template/pkgbase_details.php @@ -82,6 +82,9 @@ $pkgs = pkgbase_get_pkgnames($base_id); + +
  • +
  • 0) { echo _n('%d pending request', '%d pending requests', $row["RequestCount"]); } ?>
  • -- cgit v1.2.3-70-g09d2