[Zope-dev] ZCatalog API

Steve Alexander steve@cat-box.net
Sun, 30 Sep 2001 12:10:34 +0100


This is a multi-part message in MIME format.
--------------010008030805060308010400
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

E. Seifert wrote:

> Hi list,
> 
> as I'm not very familiar with the internals of ZCatalog I have a question to
> all you API experts:
> 
> Why does ZCatalog.py (under Zope 2.4.1) specify a 'addIndex' permission for
> a method called 'manage_delIndexes' although there is no such method? The
> only method I could find to delete Indexes is 'manage_deleteIndex'.
> 
> Can anyone comment on this?


Well, considering that there's these methods in ZCatalog:

   manage_addColumn
   manage_delColumns
   manage_addIndex
   manage_deleteIndex

... manage_deleteIndex is obviously the odd one out.

Especially as it allows you to delete several indexes in one go.

I suggest it be renamed manage_delIndices or manage del_Indexes.


manage_clearIndex also operates on multiple indexes, so that should 
become manage_clearIndexes.

Funnily enough, the ZCatalog regression test at
./regressiontests/regressionCatalogTiming.py uses this call:

   manage_delIndexes([x])

which supports renaming manage_deleteIndex to manage_delIndexes.

However,  while dtml/catalogIndexes.dtml uses manage_delIndexes,
./dtml/manageIndex.dtml uses manage_deleteIndex.

manage_reindexIndex should also become manage_reindexIndexes, as it 
requires a sequence of ids. Also, manage_reindexIndex doesn't have an 
associated permission.

There's a few more place this touches, although all the changes are in 
ZCatalog.py and manageIndex.dtml.


Congratulations, you've found a bug!

This would have been more obvious if ZCatalog were using the new 
declarative security assertions, as the declaration would be right next 
to the method definition.


Here's a first-draft patch, for comments etc.
I haven't looked at the documentation of the API, so that might need 
changing too.


--
Steve Alexander
Software Engineer
Cat-Box limited

--------------010008030805060308010400
Content-Type: text/plain;
 name="ZCatalog.diffs"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="ZCatalog.diffs"

*** ZCatalog.py.orig
--- ZCatalog.py
***************
*** 196,202 ****
            'manage_catalogView', 'manage_catalogFind',
            'manage_catalogSchema', 'manage_catalogIndexes',
            'manage_catalogAdvanced', 'manage_objectInformation',
!           
            'manage_catalogReindex', 'manage_catalogFoundItems',
            'manage_catalogClear', 'manage_addColumn', 'manage_delColumns',
            'manage_addIndex', 'manage_delIndexes', 'manage_main',
--- 196,202 ----
            'manage_catalogView', 'manage_catalogFind',
            'manage_catalogSchema', 'manage_catalogIndexes',
            'manage_catalogAdvanced', 'manage_objectInformation',
!           'manage_reindexIndexes', 'manage_clearIndexes',
            'manage_catalogReindex', 'manage_catalogFoundItems',
            'manage_catalogClear', 'manage_addColumn', 'manage_delColumns',
            'manage_addIndex', 'manage_delIndexes', 'manage_main',
***************
*** 422,430 ****
              RESPONSE.redirect(URL1 + '/manage_main?manage_tabs_message=Index%20Added')
          
  
!     def manage_deleteIndex(self, ids=None, REQUEST=None, RESPONSE=None,
          URL1=None):
!         """ del an index """
          if not ids:
              return MessageDialog(title='No items specified',
                  message='No items were specified!',
--- 422,430 ----
              RESPONSE.redirect(URL1 + '/manage_main?manage_tabs_message=Index%20Added')
          
  
!     def manage_delIndexes(self, ids=None, REQUEST=None, RESPONSE=None,
          URL1=None):
!         """ del indexes """
          if not ids:
              return MessageDialog(title='No items specified',
                  message='No items were specified!',
***************
*** 436,444 ****
          if REQUEST and RESPONSE:
              RESPONSE.redirect(URL1 + '/manage_main?manage_tabs_message=Index%20Deleted')
  
!     def manage_clearIndex(self, ids=None, REQUEST=None, RESPONSE=None,
          URL1=None):
!         """ del an index """
          if not ids:
              return MessageDialog(title='No items specified',
                  message='No items were specified!',
--- 436,444 ----
          if REQUEST and RESPONSE:
              RESPONSE.redirect(URL1 + '/manage_main?manage_tabs_message=Index%20Deleted')
  
!     def manage_clearIndexes(self, ids=None, REQUEST=None, RESPONSE=None,
          URL1=None):
!         """ clear indexes """
          if not ids:
              return MessageDialog(title='No items specified',
                  message='No items were specified!',
***************
*** 462,468 ****
              if obj is not None:
                  self.catalog_object(obj, p, idxs=[name])             
  
!     def manage_reindexIndex(self, ids=None, REQUEST=None, RESPONSE=None, URL1=None):
          """ Reindex indexes from a ZCatalog"""
          if not ids:
              return MessageDialog(title='No items specified',
--- 462,468 ----
              if obj is not None:
                  self.catalog_object(obj, p, idxs=[name])             
  
!     def manage_reindexIndexes(self, ids=None, REQUEST=None, RESPONSE=None, URL1=None):
          """ Reindex indexes from a ZCatalog"""
          if not ids:
              return MessageDialog(title='No items specified',
*** ./dtml/manageIndex.dtml
--- ./dtml/manageIndex.dtml
***************
*** 209,217 ****
    <td align="left" valign="top">
    <div class="form-element">
  
!   <input class="form-element" type="submit" name="manage_deleteIndex:method"  value="Remove index">
!   <input class="form-element" type="submit" name="manage_reindexIndex:method" value="Reindex">
!   <input class="form-element" type="submit" name="manage_clearIndex:method"   value="Clear index">
  
  <script type="text/javascript">
  <!-- 
--- 209,217 ----
    <td align="left" valign="top">
    <div class="form-element">
  
!   <input class="form-element" type="submit" name="manage_delIndexes:method"  value="Remove index">
!   <input class="form-element" type="submit" name="manage_reindexIndexes:method" value="Reindex">
!   <input class="form-element" type="submit" name="manage_clearIndexes:method"   value="Clear index">
  
  <script type="text/javascript">
  <!-- 

--------------010008030805060308010400--