Re: [hermes] Making clients

Bo Daley <[email protected]>
Newsgroups gmane.comp.horde.whups
Message-ID <[email protected]>
hi all,

this is something that was being discussed recently on the hermes list (amongst
other lists) -- adding the concept of the 'client' to Whups, which would make
Whups modules act more like 'projects' from the perspective of other
applications (like Hermes).

after a bit of discussion it was sounding like the best approach is something
like this:

* 'clients' are stored in a Turba addressbook that can be accessed by other apps
using an API call
* objects in other apps can be attached to 'clients' using the Links API. In the
case of Whups, modules can be linked to one or more clients.

As a start, the attached patches supply:

* a means of accessing the Turba contacts from inside Whups
* a field in the EditModule admin form that allowing users to attach clients to
modules using the Links API

This can probably be done better -- also I'm a bit uncertain about how/if this
affects the existing links to Whups tickets (does anyone use those?).

Still to do:

* extending the Edit Ticket and Create Ticket forms to let the user select which
client to attach a ticket to (from the list of clients associated with the
selected module).
* displaying the client name on the ticket details page.
* displaying client name in the mybugs page
* allow searching by client


does this make any sense? comments? etc?


bo.


--
Bo Daley
Tilda Communications
http://www.tilda.com.au
[email protected]


-- 
Whups mailing list
Frequently Asked Questions: http://horde.org/faq/
To unsubscribe, mail: [email protected]
admin.php.diff (text/diff, 2.8 KB)
Index: whups/admin.php
===================================================================
RCS file: /repository/whups/admin.php,v
retrieving revision 1.43
diff -u -r1.43 admin.php
--- whups/admin.php	14 Jun 2003 04:07:08 -0000	1.43
+++ whups/admin.php	16 Jul 2003 07:55:44 -0000
@@ -293,6 +293,38 @@
                                         $vars->getVar('subjectlist'), $vars->getVar('subjects'),
                                         $vars->getVar('versioned'));
          if (!is_a($result, 'PEAR_Error')) {
+             if (isset($conf['client']['driver'])) {
+                 /* Update client links. */
+                 switch ($conf['client']['driver']) {
+                     case 'turba':
+                         $clients = $vars->getVar('clients');
+                         $clientsource = $conf['client']['params']['addressbook'];
+                         require_once HORDE_BASE . '/lib/Links.php';
+                         $links = &Horde_Links::singleton($registry->getApp());
+                         $from_application = 'projects'; 
+                         $from_parameters  = array('module_id' => $vars->getVar('module'));
+                         $to_application = 'contacts';
+                         $link_type = 'client';
+                         /* Delete all current client links for this module. */
+                         $delete_status = $links->deleteLink($from_application, $from_parameters, $to_application, '', $link_type);
+                         /* Now add in all the new client links. */
+                         foreach ($clients as $client) {
+                             $to_parameters = array('source' => $clientsource, 'id' => $client); 
+                             $status = $links->addLink($from_application, $from_parameters, $to_application, $to_parameters, $link_type);
+                             if (is_a($status, 'PEAR_Error')) {
+                                 $notification->push($status, 'horde.error');
+                             } elseif ($registry->hasMethod($to_application . '/getLinkSummary')) {
+                                 $link_summary = $registry->call($to_application . '/getLinkSummary', $to_parameters);
+                                 $notification->push(sprintf(_("Added a %s link to %s."), $link_type, $link_summary), 'horde.success');
+                             } else {
+                                 $notification->push(_("Link added."), 'horde.success');
+                             }
+                         }
+                         break;
+                     /* Any future client sources can be added here. */
+                 }
+             }
+            
              $notification->push(_("The module has been modified."), 'horde.success');
              _open();
              $form->renderInactive($RENDERER, $vars);
conf.xml.diff (text/diff, 944 B)
Index: whups/config/conf.xml
===================================================================
RCS file: /repository/whups/config/conf.xml,v
retrieving revision 1.4
diff -u -r1.4 conf.xml
--- whups/config/conf.xml	4 Jul 2003 19:05:01 -0000	1.4
+++ whups/config/conf.xml	16 Jul 2003 07:56:17 -0000
@@ -111,6 +111,23 @@
   </configmultienum>
  </configsection>
 
+ <configsection name="client">
+   <configheader>
+        Client Driver Settings
+   </configheader>
+
+   <configenum name="driver" desc="What type of client driver should we use?">
+    <values>
+     <value desc="Turba Addressbook">turba</value>
+     <value desc="None">none</value>
+    </values>
+   </configenum>
+
+   <configsection name="params">
+    <configstring name="addressbook" desc="Name of client addressbook (Turba only)">localsql</configstring>
+   </configsection>
+ </configsection>
+
  <configsection name="menu">
    <configheader>
         Menu Settings
Admin.php.diff (text/diff, 1.2 KB)
Index: whups/lib/Admin.php
===================================================================
RCS file: /repository/whups/lib/Admin.php,v
retrieving revision 1.40
diff -u -r1.40 Admin.php
--- whups/lib/Admin.php	12 Jun 2003 04:35:12 -0000	1.40
+++ whups/lib/Admin.php	16 Jul 2003 07:56:46 -0000
@@ -139,7 +139,8 @@
 
         $module = $vars->getVar('module');
         $info = $whups->getModule($module);
-
+        $clients = $whups->getClients();
+        
         parent::Horde_Form($vars, sprintf(_("Edit %s"), $info['name']));
 
         $this->addHidden('', 'module', 'int', true, true);
@@ -149,6 +150,11 @@
 
         $mdesc = &$this->addVariable(_("Module Description"), 'description', 'text', true);
         $mdesc->setDefault($info['description']);
+
+        if (!empty($clients)) {
+            $mclients = &$this->addVariable(_("Clients associated with this Module"), 'clients', 'multienum', true, false, null, array($clients));
+            $mclients->setDefault(array_keys($whups->getClients($module)));
+        }
 
         $mtypes = &$this->addVariable(_("Ticket Types associated with this Module"), 'types', 'set', true, false, null, array($whups->getAllTypes()));
         $mtypes->setDefault(array_keys($whups->getTypes($module)));
Driver.php.diff (text/diff, 2.9 KB)
Index: whups/lib/Driver.php
===================================================================
RCS file: /repository/whups/lib/Driver.php,v
retrieving revision 1.45
diff -u -r1.45 Driver.php
--- whups/lib/Driver.php	25 Jun 2003 19:54:34 -0000	1.45
+++ whups/lib/Driver.php	16 Jul 2003 07:57:19 -0000
@@ -69,6 +69,68 @@
                      'resolved' => _("Resolved"));
     }
 
+    function getClients($module=null)
+    {
+        /* Gets list of clients from the client source. */
+        
+        $clients = array();
+        global $conf;
+        
+        if (!empty($conf['client']['driver'])) {
+            $clientsource = $conf['client']['driver'];
+        } else {
+            $clientsource = '';
+        }
+
+        switch($clientsource) {
+            case 'turba';
+                /* get client data from a Turba addressbook. */
+                if (!empty($conf['client']['params']['addressbook'])) {
+                    $addressbook = $conf['client']['params']['addressbook'];
+                    global $registry;
+                    $args = array(array($addressbook), array('name'));
+                    $clients = $registry->callByPackage('turba', 'list', $args);
+                    if (!empty($module)) {
+                        $clients = $this->filterClientsByModule($clients, $module);
+                    }
+                    if (is_a('PEAR_Error', $clients)) {
+                        $notification->push(_("Could not access client list from Turba."));
+                    }
+                } else {
+                    $notification->push(_("No Turba addressbook specificified in Whups configuration."));
+                }
+                break;
+        }
+
+        return $clients;
+        
+    }
+
+    function filterClientsByModule($clients, $module) {
+        /* 
+        Take a list of clients and return only those associated with the specified module. 
+        Client/module associations come from the Links API.
+        */
+        global $registry;
+        $clients_filtered = array();
+        require_once HORDE_BASE . '/lib/Links.php';
+        $links = &Horde_Links::singleton($registry->getApp());
+        $from_application = 'projects'; 
+        // TODO: add from/to_application to listLinks in Links API so it only returns links for this application
+        $from_parameters = array('module_id' => $module);
+        $to_application = 'contacts';
+        $link_type = 'projects/client';
+        $client_links = $links->listLinks($link_type, $from_parameters);
+        foreach($clients as $client_id => $name) {
+            foreach ($client_links as $l) {
+                if ($client_id == $l['to_parameters']['id']) {
+                    $clients_filtered[$client_id] = $name;        
+                }
+            }
+        }
+        return $clients_filtered;
+    }
+
     function notifyTicket($ticket_id, $summary, $module_name, $creator)
     {
         $subject = sprintf(_("New ticket (%s): %s"), $ticket_id, $summary);
turba_api.php.diff (text/diff, 2.5 KB)
Index: turba/lib/api.php
===================================================================
RCS file: /repository/turba/lib/api.php,v
retrieving revision 1.55
diff -u -r1.55 api.php
--- turba/lib/api.php	15 May 2003 17:18:40 -0000	1.55
+++ turba/lib/api.php	16 Jul 2003 07:57:44 -0000
@@ -22,6 +22,10 @@
     'args' => array('addresses', 'addressbooks', 'fields'),
     'type' => 'array');
 
+$_services['list'] = array(
+    'args' => array('addressbooks', 'fields'),
+    'type' => 'array');
+
 $_services['add'] = array(
     'args' => array('name', 'address', 'addressbook'),
     'type' => 'boolean');
@@ -246,6 +250,47 @@
     return $results;
 }
 
+function _turba_list($addressbooks = array(), $fields = array()) {
+    require_once dirname(__FILE__) . '/base.php';
+    require_once TURBA_BASE . '/lib/Source.php';
+    require TURBA_BASE . '/config/attributes.php';
+    global $cfgSources;
+
+    $results = array();
+
+    if (!isset($cfgSources) || !is_array($cfgSources) || !count($cfgSources)) {
+        return array();
+    }
+
+    if (count($addressbooks) == 0) {
+        $addressbooks = array(key($cfgSources));
+    }
+
+    foreach ($addressbooks as $source) {
+        if (isset($cfgSources[$source])) {
+            $driver = &Turba_Source::singleton($source, $cfgSources[$source]);
+            if (is_a($driver, 'PEAR_Error')) {
+                return PEAR::raiseError(_("Failed to connect to the specified directory."), 'horde.error', null, null, $source);
+            } else {
+                $res = $driver->search(array());
+                if (is_a($res, 'Turba_List')) {
+                    while ($ob = $res->next()) {
+                        foreach ($fields as $field) {
+                            if ($ob->hasValue($field)) {
+                                $results[$ob->getValue('__key')] = $ob->getValue($field);
+                            }
+                        }
+                    }
+                } else {
+                    return PEAR::raiseError(_("Failed to search the specified directory."), 'horde.error', null, null, $source);
+                }
+            }
+        }
+    }
+
+    return $results;
+}
+
 function _turba_add($name = '', $address = '', $addressbook = '')
 {
     require_once dirname(__FILE__) . '/base.php';
@@ -577,6 +622,7 @@
 function _turba_getLinkSummary($source = null, $id = null)
 {
     if (!isset($source) || !isset($id)) {
+        echo "source is $source and id is $id<br>\n";
         return PEAR::raiseError(_("Missing information"));
     }
     $t = _turba_getFieldById($source, $id, $field = 'name');
Links_sql.php.diff (text/diff, 1.6 KB)
Index: lib/Links/sql.php
===================================================================
RCS file: /repository/horde/lib/Links/sql.php,v
retrieving revision 1.8
diff -u -r1.8 sql.php
--- lib/Links/sql.php	19 Jun 2003 18:47:46 -0000	1.8
+++ lib/Links/sql.php	16 Jul 2003 07:58:15 -0000
@@ -107,13 +107,22 @@
     {
         $this->_connect();
 
-        $query = sprintf('DELETE FROM %s WHERE link_type = %s AND link_from_provider = %s AND link_from_parameter = %s AND link_to_provider = %s AND link_to_parameter = %s',
+        /* Treat empty values in $from_parameters and $to_parameters as wildcards 
+           so we can delete multiple links at once. */
+        $from_param_txt = '';
+        $to_param_txt = '';
+        if (!empty($from_parameters)) {
+            $from_param_txt = ' AND link_from_parameter = ' . $this->_db->quote(serialize($from_parameters));
+        }
+        if (!empty($to_parameters)) {
+            $to_param_txt = ' AND link_to_parameter = ' . $this->_db->quote(serialize($to_parameters));
+        }
+
+        $query = sprintf('DELETE FROM %s WHERE link_type = %s AND link_from_provider = %s ' . $from_param_txt . ' AND link_to_provider = %s ' . $to_param_txt,
             $this->_params['table'],
             $this->_db->quote($link_type),
             $this->_db->quote($from_application),
-            $this->_db->quote(serialize($from_parameters)),
-            $this->_db->quote($to_application),
-            $this->_db->quote(serialize($to_parameters))
+            $this->_db->quote($to_application)
         );
 
         $result = $this->_db->query($query);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.