Re: [Zope-CMF] Re: How do deal with cmfcatalog-wrapped objects?

2006-04-09 Thread Andreas Jung



--On 9. April 2006 13:15:15 +0200 Philipp von Weitershausen 
<[EMAIL PROTECTED]> wrote:


You are of course free to introduce adapters of your own, but I think
the second solution suggested is not too heavy and easily implemented.
After all, other code will also depend on the wrapper being as
transparent as possible.


This solution requires changing CMF which is not acceptable for existing
CMF installation and older CMF versions. Monkeypatching also is not really 
an option. My solution is highly portable across all CMF versions and not 
very much invasive.


-aj


pgp8ro5h2PicQ.pgp
Description: PGP signature
___
Zope-CMF maillist  -  Zope-CMF@lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


Re: [Zope-CMF] Re: How do deal with cmfcatalog-wrapped objects?

2006-04-09 Thread Philipp von Weitershausen
Andreas Jung wrote:
> Both solution appear a bit "heavy" to me. I solved this issue for 
> TextIndexNG3 by adding generic support for wrapped objects by 
> introducing an IObjectWrapper interface which is checked by the 
> indexer. Using five:implements it is easy to attach this interface - 
> if necessary - to any wrapper class (including
> [EMAIL PROTECTED]). Writing an adapter for adapting
> IndexableObjectWrapper to IObjectWrapper is trivial. I think this
> solution is more straight forward and does not require any changes to
> the CMF.

You are of course free to introduce adapters of your own, but I think
the second solution suggested is not too heavy and easily implemented.
After all, other code will also depend on the wrapper being as
transparent as possible.

Philipp
___
Zope-CMF maillist  -  Zope-CMF@lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


Re: [Zope-CMF] Re: How do deal with cmfcatalog-wrapped objects?

2006-04-06 Thread Andreas Jung
Both solution appear a bit "heavy" to me. I solved this issue for 
TextIndexNG3 by adding generic support for wrapped objects by introducing an
IObjectWrapper interface which is checked by the indexer. Using 
five:implements it is easy to attach this interface - if necessary - to any

wrapper class (including [EMAIL PROTECTED]). Writing an adapter
for adapting IndexableObjectWrapper to IObjectWrapper is trivial. I think 
this solution is more straight forward and does not require any changes

to the CMF.

-aj

--On 31. März 2006 14:11:58 +0200 Philipp von Weitershausen 
<[EMAIL PROTECTED]> wrote:


1. I think for the long term, IndexableObjectWrapper could be made a
decorator. This works as follows:

  from zope.proxy import getProxiedObject
  from zope.app.decorator import Decorator

  class IndexableObjectWrapper(Decorator):

  def allowedRolesAndUsers(self):
  ob = getProxiedObject(self)
  allowed = {}
  for r in rolesForPermissionOn(View, ob):
  allowed[r] = 1
  localroles = _mergedLocalRoles(ob)
  for user, roles in localroles.items():
  for role in roles:
  if allowed.has_key(role):
  allowed['user:' + user] = 1
  if allowed.has_key('Owner'):
  del allowed['Owner']
  return list(allowed.keys())

2. In the short term we can apply the following trick
(IndexableObjectWrapper needs to be a new style class!):

  from zope.interface import providedBy
  from zope.interface.declarations import ObjectSpecificationDescriptor
  from zope.interface.declarations import getObjectSpecification
  from zope.interface.declarations import ObjectSpecification

  class IndexableObjectSpecification(ObjectSpecificationDescriptor):

  def __get__(self, inst, cls=None):
  if inst is None:
  return getObjectSpecification(cls)
  else:
provided = providedBy(inst.__ob)
cls = type(inst)
return ObjectSpecification(provided, cls)

  class IndexableObjectWrapper(object):   # new-style!
  implements(...)  # it can implement as much as it wants
  __providedBy__ = IndexableObjectSpecification()

  ...




pgpfcjjy8RqC3.pgp
Description: PGP signature
___
Zope-CMF maillist  -  Zope-CMF@lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests