From: Ben Klang Date: Sun, 29 Jan 2006 07:32:58 +0000 (+0000) Subject: This should be Beta 1! X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=dde30ab75196e2d5027f153164754d3db2029047;p=horde.git This should be Beta 1! Most functionality works. Still need to figure out how to handle a single-user edit. Needs LOTS of testing Tested functions: Add user, edit existing user data, some checking of context perms. git-svn-id: https://svn.alkaloid.net/gpl/shout/trunk@278 06cd67b6-e706-0410-b29e-9de616bca6e9 --- diff --git a/andrew.session b/andrew.session index 2f88da28e..42c0092c5 100644 --- a/andrew.session +++ b/andrew.session @@ -60,63 +60,63 @@ - - - - + + + + - - + + - - + + - - + + - - - + + + - + - - + + - - + + - + - + - - - - + + + + - - - - + + + + - + - - - - + + + + - - - - + + + + diff --git a/andrew.webprj b/andrew.webprj index 84c09849a..4680d6f5b 100644 --- a/andrew.webprj +++ b/andrew.webprj @@ -1,42 +1,42 @@ - + -//w3c//dtd xhtml 1.0 strict//en - + - + - - - - - - + + + + + + - + - - - - + + + + - - - - - - + + + + + + - - - - - + + + + + @@ -99,11 +99,11 @@ templates/ toolbars/ - - + + - - + + @@ -126,15 +126,15 @@ - - - - + + + + - - - - - + + + + + diff --git a/lib/Driver/ldap.php b/lib/Driver/ldap.php index 98afe2c40..486b14c72 100644 --- a/lib/Driver/ldap.php +++ b/lib/Driver/ldap.php @@ -93,7 +93,7 @@ class Shout_Driver_ldap extends Shout_Driver return $entries[$searchfilters]; } - if ($filterperms == null) { + if ($filterperms === null) { $filterperms = PERMS_SHOW|PERMS_READ; } @@ -282,8 +282,7 @@ type"); $i = 0; while ($i < $res['count']) { $extension = $res[$i]['voicemailbox'][0]; - $uid = md5($res['dn']); - $entries[$context][$uid] = $extension; + $uid = md5($res[$i]['dn']); $entries[$context][$extension] = array(); $entries[$context][$extension]['uid'] = $uid; @@ -577,7 +576,7 @@ for $context")); $limits = array('telephonenumbersmax', 'voicemailboxesmax', - 'asteriskusers'); + 'asteriskusersmax'); if(!is_null($extension) && is_null($context)) { return PEAR::raiseError("Extension specified but no context " . @@ -704,14 +703,17 @@ for $context")); */ function saveUser($context, $extension, $userdetails) { + $ldapKey = &$this->_ldapKey; + $appKey = &$this->_appKey; # FIXME Access Control/Authorization - if (!Shout::checkRights("shout:contexts:$context:users", - PERMS_DELETE, 1)) { + if ( + !(Shout::checkRights("shout:contexts:$context:users", PERMS_EDIT, 1)) + && + !($userdetails[$appKey] == Auth::getAuth()) + ) { return PEAR::raiseError("No permission to modify users in this " . "context."); } - $ldapKey = &$this->_ldapKey; - $appKey = &$this->_appKey; $contexts = &$this->getContexts(); // $domain = $contexts[$context]['domain']; @@ -734,9 +736,11 @@ for $context")); $entry = array( 'cn' => $userdetails['name'], + 'sn' => $userdetails['name'], 'mail' => $userdetails['email'], + 'uid' => $userdetails['email'], 'voiceMailbox' => $userdetails['newextension'], - 'voiceMailboxPin' => $userdetails['pin'], + 'voiceMailboxPin' => $userdetails['mailboxpin'], 'context' => $context, 'asteriskUserDialOptions' => $userdetails['dialopts'], ); @@ -746,7 +750,7 @@ for $context")); } $validusers = &$this->getUsers($context); - if (!isset($validusers[$userdetails['uid']])) { + if (!isset($validusers[$extension])) { # Test to see if we're modifying an existing user that has # no telephone system objectClasses and update that object/user $rdn = $ldapKey.'='.$userdetails[$appKey].','; @@ -779,7 +783,7 @@ for $context")); ); $tmp['voiceMailbox'] = $extension; $tmp['context'] = $context; - $res = @ldap_mod_add($this->_LDAP, $rdn.$branch, $tmp); + $res = @ldap_mod_replace($this->_LDAP, $rdn.$branch, $tmp); if (!$res) { return PEAR::raiseError("Unable to modify the user: " . ldap_error($this->_LDAP)); @@ -811,7 +815,7 @@ for $context")); if (is_a($limits, "PEAR_Error")) { return $limits; } - if (count($validusers) >= $limits['asteriskmaxusers']) { + if (count($validusers) >= $limits['asteriskusersmax']) { return PEAR::raiseError('Maximum number of users reached.'); } diff --git a/lib/Shout.php b/lib/Shout.php index eac179385..f25fe0a75 100644 --- a/lib/Shout.php +++ b/lib/Shout.php @@ -36,30 +36,31 @@ class Shout require_once 'Horde/Menu.php'; $menu = &new Menu(HORDE_MENU_MASK_ALL); + $permprefix = "shout:contexts:$context"; - if (isset($context) && $section == "users" && - Shout::checkRights("shout:contexts:$context:users", + if (isset($context) && $section == "usermgr" && + Shout::checkRights("$permprefix:users", PERMS_EDIT, 1)) { - $url = Horde::applicationUrl("users.php"); + $url = Horde::applicationUrl("index.php"); $url = Util::addParameter($url, array('context' => $context, 'section' => $section, 'action' => 'add')); # Goofy hack to make the icon make a little more sense # when editing/deleting users - if (!isset($action)) { +// if (!isset($action)) { $icontitle = "Add"; - } else { - $icontitle = $action; - $icontitle[0] = strtoupper($action[0]); - } +// } else { +// $icontitle = $action; +// $icontitle[0] = strtoupper($action[0]); +// } # End goofy hack $menu->add($url, _("$icontitle User"), "add-user.gif"); } if (isset($context) && isset($section) && $section == "dialplan" && - Shout::checkRights("shout:contexts:$context:dialplan", + Shout::checkRights("$permprefix:dialplan", PERMS_EDIT, 1)) { $url = Horde::applicationUrl("dialplan.php"); $url = Util::addParameter($url, array('context' => $context, @@ -157,6 +158,7 @@ class Shout */ function checkRights($permname, $permmask = null, $numparents = 0) { + $perms = Perms::singleton(); if ($permmask === null) { $permmask = PERMS_SHOW|PERMS_READ; } @@ -165,10 +167,13 @@ class Shout $user = 0; $superadmin = 0; - $superadmin = Auth::isAdmin("shout:superadmin", $permmask); + $superadmin = $perms->hasPermission("shout:superadmin", + Auth::getAuth(), $permmask); while ($numparents >= 0) { - $tmpuser = Auth::isAdmin($permname, $permmask); + $tmpuser = $perms->hasPermission($permname, + Auth::getAuth(), $permmask); + $user = $user | $tmpuser; if ($numparents > 0) { $pos = strrpos($permname, ':'); @@ -180,7 +185,7 @@ class Shout } $test = $superadmin | $user; - return $test; + return ($test & $permmask) == $permmask; } // }}} diff --git a/lib/User.php b/lib/User.php index 91c7f675e..ad61cdb7f 100644 --- a/lib/User.php +++ b/lib/User.php @@ -13,6 +13,8 @@ // {{{ class UserDetailsForm extends Horde_Form { + var $_userdetails = false; // Store the user's details for fillUserForm + function UserDetailsForm(&$vars) { global $shout, $notification; @@ -25,13 +27,14 @@ class UserDetailsForm extends Horde_Form { } if (array_key_exists($extension, $users)) { # We must be editing an existing user - $this->fillUserForm(&$vars, $users[$extension]); +// $this->fillUserForm(&$vars, $users[$extension]); + $this->_userdetails = $users[$extension]; $limits = &$shout->getLimits($context, $extension); if (is_a($limits, 'PEAR_Error')) { $notification->push($limits); } $formtitle = "Edit User"; - $this->addHidden('', 'uid', 'text,' true); + $this->addHidden('', 'uid', 'text', true); } else { $limits = &$shout->getLimits($context); if (is_a($limits, 'PEAR_Error')) { @@ -50,7 +53,7 @@ class UserDetailsForm extends Horde_Form { $this->addVariable(_("Pager E-Mail Address"), 'pageremail', 'email', false); # TODO: Integrate with To-Be-Written user manager and possibly make this # TODO: new user also an email account. - $this->addVariable(_("PIN"), 'pin', 'int', true); + $this->addVariable(_("PIN"), 'mailboxpin', 'int', true); # FIXME: Make this work if limits don't exist. $t = 1; @@ -88,19 +91,28 @@ class UserDetailsForm extends Horde_Form { * * @return boolean True if successful, Pear::raiseError object on failure */ - function fillUserForm(&$vars, $userdetails) + function fillUserForm(&$vars) { #Array ( [dialopts] => Array ( [0] => m [1] => t ) [mailboxopts] => Array ( #) [mailboxpin] => 1234 [name] => Ricardo Paul [phonenumbers] => Array ( ) #[dialtimeout] => 30 [email] => ricardo.paul@v-office.biz [pageremail] => ) - $vars->set('name', $userdetails['name']); - $vars->set('email', $userdetails['email']); - $vars->set('pin', $userdetails['mailboxpin']); - $vars->set('uid', $userdetails['uid']); + if (!$this->_userdetails) { + return true; + } + foreach(array('name', 'email', 'pageremail', 'mailboxpin', 'uid') + as $var) { + # FIXME This will be done the Right Way in Shout 0.7 + $vars->set($var, $this->_userdetails[$var]); + } +// $vars->set('name', $this->_userdetails['name']); +// $vars->set('email', $this->_userdetails['email']); +// $vars->set('pager', $this->_userdetails['pager']); +// $vars->set('mailboxpin', $this->_userdetails['mailboxpin']); +// $vars->set('uid', $this->_userdetails['uid']); $vars->set('newextension', $vars->get('extension')); $i = 1; - foreach($userdetails['phonenumbers'] as $number) { + foreach($this->_userdetails['phonenumbers'] as $number) { $vars->set("telephone$i", $number); $i++; } @@ -111,7 +123,7 @@ class UserDetailsForm extends Horde_Form { // $vars->set('callappearance', 'caller'); - foreach ($userdetails['dialopts'] as $opt) { + foreach ($this->_userdetails['dialopts'] as $opt) { if ($opt == 'm') { $vars->set('moh', true); } diff --git a/lib/api.php b/lib/api.php index 7df8fe28a..906cc74e6 100644 --- a/lib/api.php +++ b/lib/api.php @@ -43,6 +43,18 @@ function _shout_perms() foreach ($contexts as $context => $contextInfo) { $perms['tree']['shout']['contexts'][$context] = false; $perms['title']['shout:contexts:' . $context] = $context; + + foreach( + array( + 'users' => 'Users', + 'dialplan' => 'Dialplan', + 'moh' => 'Music on Hold', + 'conferences' => 'Conferencing', + ) + as $module => $modname) { + $perms['tree']['shout']['contexts'][$context][$module] = false; + $perms['title']["shout:contexts:$context:$module"] = $modname; + } } diff --git a/usermgr.php b/usermgr.php index f4029ddec..6bb17299e 100644 --- a/usermgr.php +++ b/usermgr.php @@ -24,8 +24,10 @@ $title = _("User Manager: "); switch ($action) { case "add": $title .= _("Add User"); + # Treat adds just like an empty edit - unset($extension); + $action = "edit"; + $extension = 0; break; case "edit": $title .= _("Edit User (Extension ") . "$extension)"; diff --git a/usermgr/edit.php b/usermgr/edit.php index 7f56f956a..3c3fe1e9f 100644 --- a/usermgr/edit.php +++ b/usermgr/edit.php @@ -33,15 +33,20 @@ if (is_a($Form, 'PEAR_Error')) { $FormValid = $Form->validate($vars, true); if (is_a($FormValid, 'PEAR_Error')) { $notification->push($FormValid); + } else { + $Form->fillUserForm(&$vars, $extension); } } + $notification->notify(); if (!$FormValid || !$Form->isSubmitted()) { # Display the form for editing $Form->open($RENDERER, $vars, 'index.php', 'post'); - $Form->preserve($vars); + $Form->preserveVarByPost(&$vars, 'extension'); + $Form->preserveVarByPost(&$vars, 'context'); + $Form->preserveVarByPost(&$vars, 'section'); $RENDERER->beginActive($Form->getTitle()); $RENDERER->renderFormActive($Form, $vars); $RENDERER->submit(); diff --git a/usermgr/list.php b/usermgr/list.php index 4dbd7cc8b..c0d2efcbf 100644 --- a/usermgr/list.php +++ b/usermgr/list.php @@ -17,4 +17,5 @@ if (!isset($SHOUT_RUNNING) || !$SHOUT_RUNNING) { $users = &$shout->getUsers($context); ksort($users); +$notification->notify(); require SHOUT_TEMPLATES . "/users/userlist.inc"; \ No newline at end of file diff --git a/usermgr/save.php b/usermgr/save.php index d91101ba8..8a4768af5 100644 --- a/usermgr/save.php +++ b/usermgr/save.php @@ -38,7 +38,7 @@ if (!$FormValid || !$Form->isSubmitted()) { $userdetails = array( "newextension" => $vars->get('newextension'), "name" => $vars->get('name'), - "pin" => $vars->get('pin'), + "mailboxpin" => $vars->get('mailboxpin'), "email" => $vars->get('email'), "uid" => $vars->get('uid'), ); @@ -54,6 +54,7 @@ if (!$FormValid || !$Form->isSubmitted()) { } $userdetails['dialopts'] = array(); + if ($vars->get('moh')) { $userdetails['dialopts'][] = 'm'; } @@ -67,9 +68,10 @@ if (!$FormValid || !$Form->isSubmitted()) { if (is_a($res, 'PEAR_Error')) { $notification->push($res); } else { - $notification->push('User information updated.', 'horde.success'); + $notification->push('User information updated. '. + 'Changes will take effect within 10 minutes', + 'horde.success'); } - $notification->notify(); - require SHOUT_BASE . '/usermgr/edit.php'; + $notification->notify(); }