[Zope3-dev] Re: View permissions

2007-01-31 Thread Martijn Faassen

Philipp von Weitershausen wrote:

Marius Gedminas wrote:

and which causes registration as an adapter without the need for ZCML.


I am not sure I like that.  When does the registration take effect?  On
module import?


No, that would be quite terrible. It would mean you could never import 
anything without having registration going on.


The registration happens during grok time, in other words, when you 
explicitly grok something. E.g.:


  grok:grok package=foobar /

or:

   grok.grok('foobar')


Grok-time means we are able to support ZCML style actions and anything 
you can do with ZCML overrides. We intend to think that set of features 
through at some point and support it in Grok somehow, though aren't 
there yet.


The idea in Grok is to keep the benefits of ZCML without ZCML actually 
being there. :)


Regards,

Martijn

___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com



[Zope3-dev] Re: View permissions

2007-01-30 Thread Martijn Faassen

Marius Gedminas wrote:
[snip]

Also, I'd like a way to specify the adapter name in the adapter class.
Something like

from zope.interface import implements
from zope.component import adapts, named

class MyNamedAdapter(object):
adapts(IFoo)
implements(IBar)
named('myname')

def __init__(self, context):
self.context

Also I'd like to have a zope.component.Adapter class that defines

def __init__(self, context):
self.context

and does nothing else.  It seems to me that 95% of all adapters have an
__init__ like this.  It is tiring to keep repeating it.

Also, I want a pony.  Ok, not really.


You can have your pony. In grok, there's a grok.Adapter class, which
does the thing in init, where you can specify the name using grok.name, 
and which causes registration as an adapter without the need for ZCML.


Regards,

Martijn

___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com



[Zope3-dev] Re: View permissions

2007-01-30 Thread Philipp von Weitershausen

Martijn Faassen wrote:

Marius Gedminas wrote:
[snip]

Also, I'd like a way to specify the adapter name in the adapter class.
Something like

from zope.interface import implements
from zope.component import adapts, named

class MyNamedAdapter(object):
adapts(IFoo)
implements(IBar)
named('myname')

def __init__(self, context):
self.context

Also I'd like to have a zope.component.Adapter class that defines

def __init__(self, context):
self.context

and does nothing else.  It seems to me that 95% of all adapters have an
__init__ like this.  It is tiring to keep repeating it.

Also, I want a pony.  Ok, not really.


You can have your pony. In grok, there's a grok.Adapter class, which
does the thing in init, where you can specify the name using grok.name, 
and which causes registration as an adapter without the need for ZCML.



E.g.:


import grok
from zope.index.text.interfaces import ISearchableText

class Page(grok.Model):

def __init__(self, text):
self.text = text

class SearchableTextForPage(grok.Adapter):
grok.implements(ISearchableText)
grok.context(Page) # automatically assumed = the default
grok.name('')  # the default

def getSearchableText(self):
# self.context is set by grok.Adapter.__init__
return self.context.text



--
http://worldcookery.com -- Professional Zope documentation and training
Next Zope 3 training at Camp5: http://trizpug.org/boot-camp/camp5
___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com



Re: [Zope3-dev] Re: View permissions

2007-01-30 Thread Marius Gedminas
On Tue, Jan 30, 2007 at 02:37:18PM +0100, Martijn Faassen wrote:
 Marius Gedminas wrote:
 [snip]
 Also, I'd like a way to specify the adapter name in the adapter class.
 Something like
 
 from zope.interface import implements
 from zope.component import adapts, named
 
 class MyNamedAdapter(object):
 adapts(IFoo)
 implements(IBar)
 named('myname')
 
 def __init__(self, context):
 self.context
 
 Also I'd like to have a zope.component.Adapter class that defines
 
 def __init__(self, context):
 self.context
 
 and does nothing else.  It seems to me that 95% of all adapters have an
 __init__ like this.  It is tiring to keep repeating it.
 
 Also, I want a pony.  Ok, not really.
 
 You can have your pony. In grok, there's a grok.Adapter class, which
 does the thing in init, where you can specify the name using grok.name, 

Cool!

 and which causes registration as an adapter without the need for ZCML.

I am not sure I like that.  When does the registration take effect?  On
module import?

Marius Gedminas
-- 
Which is worse: ignorance or apathy?  Who knows?  Who cares?


signature.asc
Description: Digital signature
___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com



[Zope3-dev] Re: View permissions

2007-01-30 Thread Philipp von Weitershausen

Marius Gedminas wrote:

and which causes registration as an adapter without the need for ZCML.


I am not sure I like that.  When does the registration take effect?  On
module import?


No, that would be quite terrible. It would mean you could never import 
anything without having registration going on.


The registration happens during grok time, in other words, when you 
explicitly grok something. E.g.:


  grok:grok package=foobar /

or:

   grok.grok('foobar')

--
http://worldcookery.com -- Professional Zope documentation and training
Next Zope 3 training at Camp5: http://trizpug.org/boot-camp/camp5
___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com



[Zope3-dev] Re: View permissions

2007-01-23 Thread Philipp von Weitershausen

Jim Fulton wrote:

Albertas Agejevas wrote:

Hi all,

Unpleasant things happen when views are security wrapped.  Widgets
refuse to work, because they are registered as views, and get a custom
secuity checker (in zope.app.component.metaconfigure.view).  The
default view custom checker only protects '__call__', leaves all other
attributes forbidden. This makes rendering a label or errors of a widget
fail.  Defining security permissions for the widget class does not
help as the custom checker overrides them.

The TextWidget is registered in zope/app/form/browser/configure.zcml
as follows:

  view
  type=zope.publisher.interfaces.browser.IBrowserRequest
  for=zope.schema.interfaces.ITextLine
  provides=zope.app.form.interfaces.IInputWidget
  factory=.TextWidget
  permission=zope.Public
  /

Gary Poster helped me find 3 ways to overcome the security wrapped
widget problem:

  1. ZCML only fix: add allowed_interface=...ITextBrowserWidget to the
 text widget ZCML registration, and the relevant interfaces to all
 other widgets (maybe just IInputWidget is enough).

  2. Make the view custom permission checker merge permissions registered
 for the view class with the permissions allowed by the view
 registration.

  3. Make the provided interface the default allowed interface.
 Fall back on allowing just __call__ for the views that only
 provide zope.interface.Interface.

I feel that the last option is best.


I'm surprised it doesnt' do that already.


Why not just use:

   adapter
   for=zope.schema.interfaces.ITextLine
zope.publisher.interfaces.browser.IBrowserRequest
   provides=zope.app.form.interfaces.IInputWidget
   factory=.TextWidget
   permission=zope.Public
   /

That's what I would do.

I might even hack the TextWidget so I could just do:

   adapter
   factory=.TextWidget
   permission=zope.Public
   /

I'd be happy to deprecate the view directive.


+1

--
http://worldcookery.com -- Professional Zope documentation and training
2nd edition of Web Component Development with Zope 3 is now shipping!
___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com



Re: [Zope3-dev] Re: View permissions

2007-01-23 Thread Albertas Agejevas
On Tue, Jan 23, 2007 at 04:51:30PM +0100, Philipp von Weitershausen wrote:
 Jim Fulton wrote:
 Why not just use:
 
adapter
for=zope.schema.interfaces.ITextLine
 zope.publisher.interfaces.browser.IBrowserRequest
provides=zope.app.form.interfaces.IInputWidget
factory=.TextWidget
permission=zope.Public
/
 
 That's what I would do.
 
 I might even hack the TextWidget so I could just do:
 
adapter
factory=.TextWidget
permission=zope.Public
/
 
 I'd be happy to deprecate the view directive.
 
 +1

I converted all view directives in that ZCML file to adapter
directives in revision 72195.

Also, I needed to register all the input widgets with
ISimpleInputWidget as the provided interface, instead of IInputWidget,
so that the errors method is accessible.

Albertas
___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com