/** * Update user and roles of a package * * @static * @param int $pkgid The package id to update * @param array $users Assoc array containing the list of users * in the form: '<user>' => array('role' => '<role>', 'active' => '<active>') * @return mixed PEAR_Error or true */ function updateAll($pkgid, $users) { global $dbh, $auth_user; $admin = $auth_user->isAdmin(); // Only admins and leads can do this. if (maintainer::mayUpdate($pkgid) == false) { return PEAR::raiseError('maintainer::updateAll: insufficient privileges'); } $pkg_name = package::info((int) $pkgid, "name", true); // Needed for logging if (empty($pkg_name)) { PEAR::raiseError('maintainer::updateAll: no such package'); } $old = maintainer::get($pkgid); if (DB::isError($old)) { return $old; } $old_users = array_keys($old); $new_users = array_keys($users); if (!$admin && !in_array($auth_user->handle, $new_users)) { return PEAR::raiseError("You can not delete your own maintainer role or you will not " . "be able to complete the update process. Set your name " . "in package.xml or let the new lead developer upload " . "the new release"); } foreach ($users as $user => $u) { $role = $u['role']; $active = $u['active']; if (!maintainer::isValidRole($role)) { return PEAR::raiseError("invalid role '{$role}' for user '{$user}'"); } // The user is not present -> add him if (!in_array($user, $old_users)) { $e = maintainer::add($pkgid, $user, $role, $active); if (PEAR::isError($e)) { return $e; } continue; } // Users exists but role has changed -> update it if ($role != $old[$user]['role']) { $res = maintainer::update($pkgid, $user, $role, $active); if (DB::isError($res)) { return $res; } } } // Drop users who are no longer maintainers foreach ($old_users as $old_user) { if (!in_array($old_user, $new_users)) { $res = maintainer::remove($pkgid, $old_user); if (DB::isError($res)) { return $res; } } } return true; }
$name = $pkg['name']; $type = $pkg['type']; $summary = stripslashes($pkg['summary']); $license = $pkg['license']; $description = stripslashes($pkg['description']); $category = $pkg['category']; $homepage = $pkg['homepage']; $pacid = $pkg['packageid']; $cvs_link = $pkg['cvs_link']; $doc_link = $pkg['doc_link']; $bug_link = $pkg['bug_link']; $unmaintained = $pkg['unmaintained'] ? 'Y' : 'N'; $supersede = (bool) $pkg['new_channel']; // Maintainer information include_once 'pear-database-maintainer.php'; $maintainers = maintainer::get($pacid); $accounts = '<ul>' . "\n"; //$bugs = new PEAR_Bugs; foreach ($maintainers as $handle => $row) { //$buginfo = $bugs->getRank($handle); $accounts .= '<li>'; $accounts .= user_link($handle); $accounts .= ' (' . $row['role'] . ($row['active'] == 0 ? ', inactive' : ''); $accounts .= ')</li>' . "\n"; } $accounts .= '</ul>' . "\n"; $channel_name = PEAR_CHANNELNAME; if ($pkg['blocktrackbacks']) { $trackback_header = ''; } else { $trackback_uri = "http://{$channel_name}/trackback/trackback.php?id={$name}";
/** * Get maintainers to inform of a trackback (the lead maintainers of a package). * * * @since * @access public * @param boolean $activeOnly To get only active leads * is set to false by default so there's * no bc problems. * * @return array(string) The list of maintainer emails. */ function getMaintainers($activeOnly = true) { include_once 'pear-database-maintainer.php'; $maintainers = maintainer::get($this->get('id'), true, $activeOnly); $res = array(); include_once 'pear-database-user.php'; foreach ($maintainers as $maintainer => $data) { $tmpUser = user::info($maintainer, 'email'); if (empty($tmpUser['email'])) { continue; } $res[] = $tmpUser['email']; } return $res; }
if ($_POST['captcha'] != $_SESSION['answer']) { $errors[] = 'Incorrect Captcha'; } } // try to verify the user if (isset($auth_user)) { $_POST['in']['handle'] = $auth_user->handle; } if (!$errors) { /* * Skip did_luser_search check if the user is logged in * and is a pear developer */ if (isset($auth_user) && auth_check('pear.dev')) { require_once 'pear-database-maintainer.php'; $m = maintainer::get($_POST['in']['package_name'], false, true); if (isset($m[$auth_user->handle]) && in_array($m[$auth_user->handle]['role'], array('lead', 'developer'))) { $_POST['in']['did_luser_search'] = 1; } } /* * When user submits a report, do a search and display * the results before allowing them to continue. */ if (!isset($_POST['in']['did_luser_search']) || $_POST['in']['did_luser_search'] == '0') { $_POST['in']['did_luser_search'] = 1; // search for a match using keywords from the subject $sdesc = $_POST['in']['sdesc']; /* * If they are filing a feature request, * only look for similar features
function isAllowed($package) { global $auth_user; auth_require(); $lead = in_array($auth_user->handle, array_keys(maintainer::get($package, true))); $admin = user::isAdmin($auth_user->handle); return $lead || $admin; }
/** * Get maintainers * * Get maintainers to inform of a trackback (the * lead maintainers of a package). * * @since * @access public * @param boolean $activeOnly To get only active leads * is set to false by default so there's * no bc problems. * * @return array(string) The list of maintainer emails. */ function getMaintainers($id, $leadOnly = false, $activeOnly = true) { include_once 'pear-database-maintainer.php'; $maintainers = maintainer::get($id, $leadOnly, $activeOnly); $res = array(); include_once 'pear-database-user.php'; foreach ($maintainers as $maintainer => $data) { $tmpUser = user::info($maintainer, 'email'); if (!is_array($tmpUser) || !isset($tmpUser['email'])) { continue; } $res[] = $tmpUser['email']; } return $res; }
+----------------------------------------------------------------------+ $Id$ */ redirect_to_https(); @session_start(); $csrf_token_name = 'pear_csrf_token_' . basename(__FILE__, '.php'); auth_require(); $pid = isset($_GET['pid']) ? (int) $_GET['pid'] : false; if ($pid && $pid < 1) { report_error('Invalid package'); } include_once 'pear-database-package.php'; $package_name = package::info($pid, 'name'); response_header('Administration - ' . htmlspecialchars($package_name) . ' - Package Maintainers'); include_once 'pear-database-maintainer.php'; $maintainers = maintainer::get($pid); // Maintainer being lead can go further, if not QA and up if (!(isset($maintainers[$auth_user->handle]) && $maintainers[$auth_user->handle]['role'] == 'lead')) { auth_require('pear.qa'); } if (isset($_POST) && isset($_POST['role'])) { if (!validate_csrf_token($csrf_token_name)) { report_error('Invalid token.'); response_footer(); exit; } // Got a new maintainer? if (isset($_POST['handle']['new']) && !empty($_POST['handle']['new'])) { $new = strip_tags($_POST['handle']['new']); include_once 'pear-database-user.php'; if (!ereg('^[0-9a-z_]{2,20}$', $new)) {
// Get the database class. require_once 'DB.php'; $options = array('persistent' => false, 'portability' => DB_PORTABILITY_ALL); $dbh =& DB::connect(PEAR_DATABASE_DSN, $options); if (DB::isError($dbh)) { die("Failed to connect: {$dsn}\n"); } require_once 'pear-database-maintainer.php'; require_once 'pear-database-note.php'; require_once 'Damblan/Karma.php'; $karma = new Damblan_Karma($dbh); $karma_level = 'pecl.dev'; $sql = "SELECT p.name, p.id\n FROM packages p\n WHERE p.package_type = 'pecl'\n ORDER BY p.name"; $packages = $dbh->getAssoc($sql, false, null, DB_FETCHMODE_ASSOC); foreach ($packages as $n => $id) { $m = maintainer::get((int) $id); if (!empty($m)) { echo "\nAltering karma for maintainers of {$n} package id {$id}\n"; foreach ($m as $handle => $m_data) { if (!$karma->has($handle, $karma_level)) { echo "Giving {$handle} {$karma_level} karma\n"; // Bypassing damblan karma because it needs a logged in user $id = $dbh->nextId('karma'); if (DB::isError($id)) { echo "Couldn't get a new id from the karma table\n"; exit; } $query = 'INSERT INTO karma (id, user, level, granted_by, granted_at) VALUES (?, ?, ?, ?, NOW())'; $sth = $dbh->query($query, array($id, $handle, $karma_level, 'peclweb')); if (DB::isError($sth)) {
/** * Update user and roles of a package * * @static * @param int $pkgid The package id to update * @param array $users Assoc array containing the list of users * in the form: '<user>' => array('role' => '<role>', 'active' => '<active>') * @param bool Whether to print the logging information to the screen * @return mixed PEAR_Error or true */ static function updateAll($pkgid, $users, $print = false, $releasing = false) { require_once 'Damblan/Log.php'; global $dbh, $auth_user; // Only admins and leads can do this. if (maintainer::mayUpdate($pkgid) == false) { return PEAR::raiseError('maintainer::updateAll: insufficient privileges'); } $logger = new Damblan_Log(); if ($print) { require_once 'Damblan/Log/Print.php'; $observer = new Damblan_Log_Print(); $logger->attach($observer); } include_once 'pear-database-package.php'; $pkg_name = package::info((int) $pkgid, "name"); // Needed for logging if (empty($pkg_name)) { PEAR::raiseError('maintainer::updateAll: no such package'); } $old = maintainer::get($pkgid); if (DB::isError($old)) { return $old; } $old_users = array_keys($old); $new_users = array_keys($users); $admin = $auth_user->isAdmin(); $qa = $auth_user->isQA(); if (!$admin && !$qa && !in_array($auth_user->handle, $new_users)) { return PEAR::raiseError("You can not delete your own maintainer role or you will not " . "be able to complete the update process. Set your name " . "in package.xml or let the new lead developer upload " . "the new release"); } if ($releasing && user::maintains($auth_user->handle, (int) $pkgid, 'lead') && $users[$auth_user->handle]['role'] != 'lead') { return PEAR::raiseError('You cannot demote your role from lead to ' . $users[$auth_user->handle]['role']); } foreach ($users as $user => $u) { $role = $u['role']; $active = $u['active']; if (!maintainer::isValidRole($role)) { return PEAR::raiseError("invalid role '{$role}' for user '{$user}'"); } // The user is not present -> add him if (!in_array($user, $old_users)) { $e = maintainer::add($pkgid, $user, $role, $active); if (PEAR::isError($e)) { return $e; } $logger->log("[Maintainer] NEW: " . $user . " (" . $role . ") to package " . $pkg_name . " by " . $auth_user->handle); continue; } // Users exists but the role or the "active" flag have changed -> update it if ($role != $old[$user]['role'] || $active != $old[$user]['active']) { $res = maintainer::update($pkgid, $user, $role, $active); if (DB::isError($res)) { return $res; } $logger->log("[Maintainer] UPDATE: " . $user . " (" . $role . ") to package " . $pkg_name . " by " . $auth_user->handle); } } // Drop users who are no longer maintainers foreach ($old_users as $old_user) { if (!in_array($old_user, $new_users)) { $res = maintainer::remove($pkgid, $old_user); if (DB::isError($res)) { return $res; } $logger->log("[Maintainer] REMOVED: " . $old_user . " (" . $role . ") to package " . $pkg_name . " by " . $auth_user->handle); } } return true; }