cvs: pearweb /include pear-database.php pear-format-html.php /include/Damblan Karma.php

From: Date: Fri, 26 Sep 2003 19:50:14 +0000
Subject: cvs: pearweb /include pear-database.php pear-format-html.php /include/Damblan Karma.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-13116@lists.php.net to get a copy of this message
mj Fri Sep 26 15:50:14 2003 EDT Modified files: /pearweb/include pear-database.php pear-format-html.php /pearweb/include/Damblan Karma.php Log: * Adjusting for the new karma system.

Index: pearweb/include/pear-database.php diff -u pearweb/include/pear-database.php:1.139 pearweb/include/pear-database.php:1.140 --- pearweb/include/pear-database.php:1.139 Sun Sep 14 04:01:58 2003 +++ pearweb/include/pear-database.php Fri Sep 26 15:50:13 2003 @@ -17,7 +17,7 @@ | Tomas V.V.Cox <cox@php.net> | | Martin Jansen <mj@php.net> | +----------------------------------------------------------------------+ - $Id: pear-database.php,v 1.139 2003/09/14 08:01:58 mj Exp $ + $Id: pear-database.php,v 1.140 2003/09/26 19:50:13 mj Exp $ */ require_once 'DB/storage.php'; @@ -683,7 +683,7 @@ if (PEAR::isError($package_id) || empty($package_id)) { return PEAR::raiseError("Package not registered. Please register it first with \"New Package\""); } - if (empty($auth_user->admin)) { + if ($auth_user->isAdmin() == false) { $role = user::maintains($auth_user->handle, $package_id); if ($role != 'lead' && $role != 'developer') { return PEAR::raiseError('package::updateInfo: insufficient privileges'); @@ -806,11 +806,7 @@ function add($package, $user, $role) { global $dbh, $auth_user; - /* - That breaks package-new.php, as the new package do not have any lead assigned - if (empty($auth_user->admin) && !user::maintains($auth_user->handle, $package, 'lead')) { - return PEAR::raiseError('maintainer::add: insufficient privileges'); - }*/ + if (!user::exists($user)) { return PEAR::raiseError("User $user does not exist"); } @@ -899,7 +895,7 @@ function remove($package, $user) { global $dbh, $auth_user; - if (empty($auth_user->admin) && !user::maintains($auth_user->handle, $package, 'lead')) { + if (!$auth_user->isAdmin() && !user::maintains($auth_user->handle, $package, 'lead')) { return PEAR::raiseError('maintainer::drop: insufficient privileges'); } if (is_string($package)) { @@ -925,7 +921,9 @@ { // Only admins and leads can do this. global $dbh, $auth_user; - if (empty($auth_user->admin) && !user::maintains($auth_user->handle, $pkgid, 'lead')) { + $admin = $auth_user->isAdmin(); + + if (!$admin && !user::maintains($auth_user->handle, $pkgid, 'lead')) { return PEAR::raiseError('maintainer::updateAll: insufficient privileges'); } $sql = "SELECT handle, role FROM maintains WHERE package = ?"; @@ -935,7 +933,7 @@ } $old_users = array_keys($old); $new_users = array_keys($users); - if (!$auth_user->admin && !in_array($auth_user->handle, $new_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 ". @@ -1083,7 +1081,7 @@ { global $auth_user; $role = user::maintains($auth_user->handle, $package); - if ($role != 'lead' && $role != 'developer' && !$auth_user->admin) { + if ($role != 'lead' && $role != 'developer' && !$auth_user->isAdmin()) { return PEAR::raiseError('release::upload: insufficient privileges'); } $ref = release::validateUpload($package, $version, $state, $relnotes, $tarball, $md5sum); @@ -1111,7 +1109,7 @@ { global $dbh, $auth_user; $role = user::maintains($auth_user->handle, $package); - if ($role != 'lead' && $role != 'developer' && !$auth_user->admin) { + if ($role != 'lead' && $role != 'developer' && !$auth_user->isAdmin()) { return PEAR::raiseError('release::validateUpload: insufficient privileges'); } // (2) verify that package exists @@ -1195,7 +1193,7 @@ @unlink($upload_ref); $role = user::maintains($auth_user->handle, $package_id); - if ($role != 'lead' && $role != 'developer' && !$auth_user->admin) { + if ($role != 'lead' && $role != 'developer' && !$auth_user->isAdmin()) { return PEAR::raiseError('release::confirmUpload: insufficient privileges'); } @@ -1524,7 +1522,7 @@ function remove($package, $release) { global $dbh, $auth_user; - if (empty($auth_user->admin) && + if (!$auth_user->isAdmin() && !user::maintains($auth_user->handle, $package, 'lead')) { return PEAR::raiseError('release::remove: insufficient privileges'); } @@ -1564,6 +1562,25 @@ } // }}} + // {{{ getFAQ() + + /** + * Get FAQ items for given package version + * + * @param string Name of the package + * @param string Version string of the package + * @return mixed PEAR_Error or Array + */ + function getFAQ($package, $version) + { + global $dbh; + + $query = "SELECT f.* FROM packages_faq f, packages p, releases r " + . "WHERE p.name = ? AND p.id = r.package AND r.version = ? AND r.id = f.release"; + + return $dbh->getAll($query, array($package, $version), DB_FETCHMODE_ASSOC); + } + // }}} } @@ -1657,9 +1674,13 @@ function activate($uid) { + require_once "Damblan/Karma.php"; + global $dbh; $user =& new PEAR_User($dbh, $uid); + $karma = new Damblan_Karma($dbh); + if (@$user->registered) { return false; } @@ -1673,6 +1694,7 @@ $user->set('created', gmdate('Y-m-d H:i')); $user->set('createdby', $_COOKIE['PEAR_USER']); $user->store(); + $karma->grant($user->handle, "pear.dev"); note::add("uid", $uid, "Account opened"); $msg = "Your PEAR account request has been opened.\n". "To log in, go to http://pear.php.net/ and click on \"login\" in\n". @@ -1687,12 +1709,12 @@ function isAdmin($handle) { - global $dbh; + require_once "Damblan/Karma.php"; - $query = "SELECT handle FROM users WHERE handle = ? AND admin = 1"; - $sth = $dbh->query($query, array($handle)); + global $dbh; + $karma = new Karma($dbh); - return ($sth->numRows() > 0); + return $karma->has($handle, "pear.admin"); } // }}} @@ -1700,10 +1722,12 @@ function listAdmins() { + require_once "Damblan/Karma.php"; + global $dbh; + $karma = new Karma($dbh); - $query = "SELECT email FROM users WHERE admin = 1"; - return $dbh->getCol($query); + return $karma->getUser("pear.admin"); } // }}} @@ -1825,29 +1849,6 @@ // }}} -// {{{ mail_pear_admins() - -function mail_pear_admins($subject = "PEAR Account Request", $msg, $xhdr = '') -{ - global $dbh; - $admins = $dbh->getAll("SELECT name,email FROM users WHERE admin = 1", - DB_FETCHMODE_ASSOC); - if (count($admins) > 0) { - foreach ($admins as $value) { - if ($value['name'] == "") { - $rcpt[] = "<" . $value['email'] . ">"; - } else { - $rcpt[] = "\"" . $value['name'] . "\" <" . $value['email'] . ">"; - } - } - $rcpt = implode(", ", $rcpt); - return mail($rcpt, $subject, $msg, $xhdr, "-f pear-sys@php.net"); - } - return false; -} - -// }}} - // {{{ class PEAR_User class PEAR_User extends DB_storage @@ -1872,7 +1873,7 @@ function isAdmin() { - return ($this->admin == 1); + return (user::isAdmin($this->handle)); } } Index: pearweb/include/pear-format-html.php diff -u pearweb/include/pear-format-html.php:1.66 pearweb/include/pear-format-html.php:1.67 --- pearweb/include/pear-format-html.php:1.66 Tue Sep 16 15:45:50 2003 +++ pearweb/include/pear-format-html.php Fri Sep 26 15:50:13 2003 @@ -15,7 +15,7 @@ +----------------------------------------------------------------------+ | Authors: | +----------------------------------------------------------------------+ - $Id: pear-format-html.php,v 1.66 2003/09/16 19:45:50 mj Exp $ + $Id: pear-format-html.php,v 1.67 2003/09/26 19:50:13 mj Exp $ */ /* Send charset */ @@ -79,7 +79,7 @@ global $developer_menu; $SIDEBAR_DATA .= draw_navigation($developer_menu, 'Developers:'); } - if (!empty($auth_user->admin)) { + if ($auth_user->isAdmin()) { global $admin_menu; $SIDEBAR_DATA .= draw_navigation($admin_menu, 'Administrators:'); } Index: pearweb/include/Damblan/Karma.php diff -u pearweb/include/Damblan/Karma.php:1.2 pearweb/include/Damblan/Karma.php:1.3 --- pearweb/include/Damblan/Karma.php:1.2 Tue Sep 23 06:18:34 2003 +++ pearweb/include/Damblan/Karma.php Fri Sep 26 15:50:13 2003 @@ -15,7 +15,7 @@ +----------------------------------------------------------------------+ | Author: Martin Jansen <mj@php.net> | +----------------------------------------------------------------------+ - $Id: Karma.php,v 1.2 2003/09/23 10:18:34 mj Exp $ + $Id: Karma.php,v 1.3 2003/09/26 19:50:13 mj Exp $ */ /** @@ -26,7 +26,7 @@ * single-sign-on system some time in the future. * * @author Martin Jansen <mj@php.net> - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ */ class Damblan_Karma { @@ -137,6 +137,18 @@ function get($user) { $query = "SELECT * FROM karma WHERE user = ?"; return $this->_dbh->getAll($query, array($user), DB_FETCHMODE_ASSOC); + } + + /** + * Get all users with given karma level + * + * @access public + * @param string Level + * @return array + */ + function getUsers($level) { + $query = "SELECT * FROM karma WHERE level = ?"; + return $this->_dbh->getAll($query, array($handle), DB_FETCHMODE_ASSOC); } } ?>
« previous php.pear.cvs (#13116) next »