Re: AW: [Zope3-Users] PAU / credentials / authentication

2007-09-06 Thread Rupert Redington
Roger Ineichen wrote:
> Hi
> 
>> An: Hermann Himmelbauer
>> Cc: zope3-users@zope.org
>> Betreff: Re: [Zope3-Users] PAU / credentials / authentication
> 
> [...]
> 
>> # My event subscriber will be passed a reference to the site 
>> object # from which we can get the sitemanager sitemanager = 
>> event.object.getSiteManager() pau = PluggableAuthentication() 
>> sitemanager['PAU'] = pau sitemanager.registerUtility(pau, 
>> IAuthentication) # Tell the PAU which sort of credentials we 
>> want to use pau.credentialsPlugins = (u'Session Credentials') 
> 
> make sure this is a tuple:
> pau.credentialsPlugins = (u'Session Credentials',)
> 
> or even better, never override it:
> pau.credentialsPlugins += (u'Session Credentials',)
> 
> 
> Regards
> Roger Ineichen
> _
> END OF MESSAGE
> 

Thanks Roger,

The non-tuple was an editing mistake, mine normally reads:

pau.credentialsPlugins = (u'Session Credentials', u'Zope Realm Basic-Auth')

but your other suggestion is much cleaner anyway.

Rupert
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] PAU / credentials / authentication

2007-09-06 Thread Rupert Redington
Hermann Himmelbauer wrote:
> Hi,
> After thoroughly studying Philipp's book and the PAU-doctests, I 
> unfortunately 
> still have no clue how to do my authentication. My (simple) scenario is the 
> following:
> 
> - I wrote a Zope package that can be added as a site
> - I have one Zope instance with several of these sites
> - Users should authenticate site-specific, e.g. users that authenticated for 
> site A should not automatically be authenticated for site B and never for the 
> Zope root
> - I want to use Session Credentials
> - I wrote an authenticator plug-in for an existing relational database that 
> looks like this:
> 
> class PasswdAuthenticator(Persistent):
> implements(IPasswd, IAuthenticatorPlugin, ILocation)
> __parent__ = __name__ = None
> 
> def authenticateCredentials(self, credentials):
> if not (credentials and 'login' in credentials and
> 'password' in credentials):
> return
> login, password = credentials['login'], credentials['password']
> if relation_db_check(login,passwd):
> return PrincipalInfo()
> 
> Now I have to glue all this together, but how?
> 
> Do I need a local, site specific PAU? If yes, how do I create/store one 
> without the ZMI? I want that to automatically be done during site creation, 
> e.g. via a subscriber (I have already one that builds the basic site 
> structure). Probably a PAU is created like this:
> 
> pau = zope.app.authentication.PluggableAuthentication('myprefix_')
> 
> But - how do I add this to my site manager then? Have the prefixes to be 
> different for every PAU that are located in the different sites?
> 
> How do I enable Session Credentials, or are they already enabled?
> 
> And - how do I tell the PAU to use my authentication utility, perhaps I have 
> to create one and somehow place it into the PAU, as it's a container? Or 
> should I register it as a local utility? Or as a global utility? In case of a 
> utility, the Authenticator Plugin probably does not have to inherit from 
> persistent.Persistent?
> 
> Moreover Philipp's book states that available plug-ins need to be configured 
> but I don't know to do this without the ZMI?
> 
> Best Regards,
> Hermann
> 


Hi Hermann,

I do it roughly like this - but, in my experience there's usually a
better way of doing things than whatever way I choose :-)

It answers some of your questions...

from zope.app.authentication.authentication import PluggableAuthentication
from zope.app.security.interfaces import IAuthentication
from zope.app.authentication.principalfolder import PrincipalFolder
from zope.app.authentication.interfaces import IAuthenticatorPlugin

# My event subscriber will be passed a reference to the site object
# from which we can get the sitemanager
sitemanager = event.object.getSiteManager()
pau = PluggableAuthentication()
sitemanager['PAU'] = pau
sitemanager.registerUtility(pau, IAuthentication)
# Tell the PAU which sort of credentials we want to use
pau.credentialsPlugins = (u'Session Credentials')
# make whatever authenticatorPlugin we want
users = PrincipalFolder()
users.prefix = u'users.'
pau[u'users'] = users
# get the current list of authenticator plugins, add users and reset
aplugins = list(pau.authenticatorPlugins)
aplugins.append(u'users')
pau.authenticatorPlugins = aplugins

Cheers,

Rupert
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Default Skins for certain sites - how?

2007-06-21 Thread Rupert Redington
Hi Hermann,

I do this by registering a subscriber for
zope.app.publication.interfaces.IBeforeTraverseEvent:



the handler sets the skin:
(note that my site objects have a site_skin attribute which allows me to
switch skins.)

def skinTraverseSubscriber(event):
""" Sets the skin during traversal"""
if (IMySite.providedBy(event.object) and
IBrowserRequest.providedBy(event.request)):
skin = zope.component.getUtility(IBrowserSkinType,
event.object.site_skin)
if not '++skin++' in event.request.URL[0]:
applySkin(event.request, skin)


I'm pretty sure that one shouldn't have to check the type of the object
that's being traversed. I believe that you should be able to add another
interface to the 'for' attribute of the subscriber zcml - but that never
worked for me.

I'd be interested in hearing other/more efficient ways of doing this though.

Rupert
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Re: Evolution of ZoDB after changing python modules structure (moving content classes to another module)

2007-06-12 Thread Rupert Redington
Aleksander Kowalczyk wrote:
> On 6/8/07, Alek Kowalczyk <[EMAIL PROTECTED]> wrote:
>>
>> Alek Kowalczyk <[EMAIL PROTECTED]> writes:
>>
>> >
>> > Hi,
>> > I moved my content class from mypackage.mymodule.MyContentClass into
>> > mypackage.mysubpackage.mymodule.MyContentClass.
>> > But when started Zope and went to visit an object I have previously
>> created (of
>> > MyContentClass), I get:
>> > ComponentLookupError: ((> mypackage.mymodule.MyContentClass
>> > instance '\x00\x00\x00\x00\x00\x00\x02q'>,
>> > >
> I found a quite well working solution on
>> http://mail.zope.org/pipermail/zodb-dev/2006-September/010382.html
>>
>> There was only one issue: this solution assumes that we have given a DB,
>> while
>> Zope evolve method receives already open connection. Unfortunately
>> classFactory
>> from DB is cached in Connection's private fields in constructor.
>> Because of that I could not assign my custom 'renaming' class factory
>> using:
>>
>> def evolve(context): #won't work!
>> context.connection.db().classFactory = myClassFactory
>>
>> Instead I had to do some dirty private fields substitution in
>> Connection's
>> ObjectReader:
>>
>> def evolve(context): #this works nice
>> context.connection._reader._factory = myClassFactory
> 
> 
> I shouldn't announce success too early. The solution works but only during
> first Zope run (i.e just after evolving the schema).
> Although classFactory returns proper class during evolve, the new class
> name
> is not saved in ZoDB, so after next unghosting object get old class names
> again.
> 
> Here is my evolve script. I really don't know what more should I do to make
> Zope/ZoDB write the new class name in ZoDB. Can someone help me a bit... :)
> ?
> 
> def convertingClassFactory(connection, moduleName, globalName):
>#convert class name to new one and return the class object
> 
> def evolve(context):
>#dirty hack to substitute classFactory
>context.connection._reader._factory = convertingClassFactory
>root = context.connection.root().get(ZopePublication.root_name, None)
>for object in findObjectsMatching(root, lambda x: True):
>if hasattr(object, '_p_activate'):
>object._p_activate()
>object._p_changed = True
> 

Somebody correct me if I'm wrong
I imagine you'd need to commit the transaction manually:


 def evolve(context):
#dirty hack to substitute classFactory
context.connection._reader._factory = convertingClassFactory
root = context.connection.root().get(ZopePublication.root_name, None)
for object in findObjectsMatching(root, lambda x: True):
 if hasattr(object, '_p_activate'):
object._p_activate()
object._p_changed = True
import transaction
transaction.commit()


Hope that helps,

Rupert
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] "Wrong contained type" - why?

2007-05-02 Thread Rupert Redington
For me it was a problem with my vocabulary which works in this form...

class ClipboardVocabFactory(object):
implements(IVocabularyFactory)

def __call__(self, context):

terms = [(x.title, x) for x in \
Session().query(ArchiveObject).select()]
voc = SimpleVocabulary.fromItems(terms)
return voc

I clearly need to understand vocabulary construction better.

Did you ever figure out how to omit fields from a subwidget?

Rupert
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] "Wrong contained type" - why?

2007-04-26 Thread Rupert Redington
Hermann Himmelbauer wrote:
> Hi,
> As already mentioned before, I use interfaces that contain lists of other 
> interfaces via the following syntax:
> 
> emails = List(value_type=Object(schema=IEmail))
> 
> In my formlib-based class, I have use the following, so that the widgets are 
> displayed correctly:
> 
> email_widget = CustomWidgetFactory(ObjectWidget,Email)
> emails_widget = CustomWidgetFactory(ListSequenceWidget, 
> subwidget=email_widget)
> 
> and in the form.Form based class:
> 
> form_fields['emails'].custom_widget = emails_widget
> 
> The widgets are displayed perfectly, but when I try to update the data, the 
> validation fails with the following error:
> 
> "Wrong contained type"
> 
> I don't know how to get around this, especially I don't find a good entry 
> point to this problem - it seems that this error comes from the 
> widget.getInputValue() function - is that true?
> 
> All objects in my example are of the type Interface, perhaps I have to define 
> them as containers? 
> 
> Another thing I don't know is how I can omit fields from the email_widget, is 
> there a simple solution?
> 
> Best Regards,
> Hermann
> 

Hi Guys,

Curiously I seem to have run into a similar problem to Hermann's at
about the same time...

I too am using a Custom ObjectWidget in a ListSequenceWidget:

viewassociation_widget = CustomWidgetFactory(ObjectWidget, ViewAssociation)
elements_widget = CustomWidgetFactory(ListSequenceWidget,
subwidget=viewassociation_widget)

and placing it into my formlib.EditForm :

form_fields['elements'].custom_widget = elements_widget


The fields in the ObjectWidget are drawn from IViewAssociation :

class IViewAssociation(Interface):
"""Stores information about an editor's choice of view
   for an item within a section
"""

viewtype = Choice(
title=_(u"View Type"),
description=_(u"A type for the view"),
required = True,
values = [u'insert', u'thumbnail', u'link']
)

item = Choice(
title=_(u"Content Item"),
description=_(u"The item providing data for this view element"),
required = True,
vocabulary = u'Clipboard',
)

section = Attribute(u'The Section Object using this Association')


The form renders correctly, which is nice, but only validates and
creates and add the ViewAssociation objects if I knock out the 'item' field.

When I include the 'item' field in the schema validation fails with
"Wrong contained type". Here's the current simplified testing version of
the "Clipboard" vocabulary.

session = z3c.zalchemy.getSession
class ClipboardVocabFactory(object):
implements(IVocabularyFactory)

def __call__(self, context):
items = [x for x in session().query(ArchiveObject).select()]
voc = SimpleVocabulary.fromValues(items)
return voc


ViewAssociation objects can accept ArchiveObjects in their item
attribute in my unit tests...

To (spookily) increase the similarity of my case to Hermann's I too
would like to control the subwidgets in the Custom ObjectWidget - in my
case by using a RadioWidget for the viewtype field - but I can't quite
work out how.

viewassociation_widget = CustomWidgetFactory(ObjectWidget,
ViewAssociation, viewtype_widget=RadioWidget)

raises:

TypeError: Unable to configure a widget for viewtype - attribute
viewtype_widget does not implement IWidget

Thanks for fighting through this overlong post.
Can anyone help?

Rupert
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Re: UnicodeEncodeErrors from zope/app/maildir.py

2006-11-29 Thread Rupert Redington
Raphael Ritz wrote:

> Well, there are the "officials" like:
> 
> http://unicode.org
> http://en.wikipedia.org/wiki/Unicode
> 
> but you want probably something more like
> 
> http://www.joelonsoftware.com/articles/Unicode.html
> 
> and for Python in particular I found
> 
> http://www.amk.ca/python/howto/unicode

Those are great pointers, thanks, but I still can't understand why
zope.app.mail's MailDir functions want to encode the message using the
'ascii' encoding, nor does there seem to be any way to suggest a
different encoding to the mail system.

How is it possible to send emails containing non-ascii encodings from
zope? Is there a problem with the python smtplib which is forcing this
behaviour? (Or do I still not get it...?)


Thanks for your help,

Rupert
R
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


[Zope3-Users] Annotations factory

2006-11-28 Thread Rupert Redington
I've just made my first annotation adapter using
zope.annotation.factory, but I find myself needing access to some
attributes of the adapted object. Using the older pattern I would gain
access to the original object through the context passed to the __init__
of my adapter. The annotations factory doesn't pass a context to the
adapter.

Should I revert to the old pattern if I'm going to need continued access
to the unadapted object or is there a clever reference somewhere that I
can't find?

Thanks,

Rupert
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


[Zope3-Users] UnicodeEncodeErrors from zope/app/maildir.py

2006-11-28 Thread Rupert Redington
I write this in expectation of needing to kick myself quite soon...

I collect some data from a form, using a Text schema/widget, get my
IMailDelivery utility (which uses queued delivery) and pass my from and
 to addresses and the message data I collected from the form (with a
subject line and a couple of new lines added to the top) to the
utility's send method.

If the collected data contains characters outside the ascii set ( a UK
pound sign - for example) then I'll get an error thus:

File "/home/busstop39/Zope3/lib/python/zope/app/mail/maildir.py",   line
116, in write
self._fd.write(data)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa3' in
position 113: ordinal not in range(128)


I'm constantly aware that I need a much better grasp of character
encoding issues (and had hoped that the wonders of unicode/UTF-8 would
save me from this) - can anyone give me a pointer?

Rupert
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] filter possibilities

2006-09-26 Thread Rupert Redington
I'm no expert on this... In fact I often find myself struggling to get
cataloging in Zope3 to do what I want in a painless way (which is
probably why hurry exists...). Experts please correct me if I'm doing
anything objectionable...

I'm assuming that you've got an IntIds utility and a catalog,
and I'm assuming that in your catalog is a FieldIndex which uses
IZopeDublinCore...

If not the following _may_ provide a little help:
from zope.app.catalog.interfaces import ICatalog
from zope.app.catalog.catalog import Catalog
from zope.app.catalog.field import FieldIndex
from zope.app.dublincore.interfaces import IZopeDublinCore
from zope.app.component.hooks import getSite
from zope.app.component.site import UtilityRegistration
from zope.app.component.interfaces.registration import ActiveStatus
from zope.component import provideUtility

# Find your site's manager and get the default tool folder
sm = getSite().getSiteManager()
smf = sm['default']
# make a catalog and put it in the folder
catalog = Catalog()
smf['My Catalog'] = catalog

# Register the new catalog so that its available for use
reg = UtilityRegistration('', ICatalog, catalog)
smf.registrationManager.addRegistration(reg)
reg.status = ActiveStatus

# Use provide utility so that the catalog is ready for use
provideUtility(catalog, ICatalog)

# Add a Field index which will catalog the creation time of objects
index = FieldIndex('created', IZopeDublinCore)
catalog['Date Created'] = index

Once your catalog has indexes and they're indexing objects then you can
start trying queries. Here's an attempt at a query to find all indexed
objects created in the last 10 days:

from zope.app.catalog.interfaces import ICatalog
from hurry.query.interfaces import IQuery
from hurry.query import Ge
import datetime

#Grab our catalog and query utilities
catalog = getUtility(ICatalog)
query = getUtility(IQuery)

# make a tuple to tell hurry which catalog and index we want to use
index = (catalog, 'Date Created')

# make a datetime object (in my timezone) to find out when
# 10 days ago was...
now = datetime.datetime.now(pytz.timezone('GB'))
then = now - datetime.timedelta(10)

results = query.searchResults(Ge(index, then))

Good Luck,

Rupert







___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Re: Access request object from content_factory

2006-06-21 Thread Rupert Redington
Philipp von Weitershausen wrote:

> 
> That already sounds like bad design. Why would the local utility worry
> about URLs at all?
> 

It probably is :-)

The utility is responsible for generating a PDF snapshot of a view - as
seen by the invoking user at the point when the utility is invoked. To
do this I open an HTMLDOC subprocess which needs a url to go to, and
which needs to know which user to pretend to be so that it can
authenticate... This is indeed all very ugly, but I needed it done and
couldn't think of a better way at the time.

I can't help feeling that to say that a utility should never ever
concern itself with URLs is unnecessarily restrictive.


> 
>> Furthermore I sometimes find myself using this in event subscribers - I
>> can't see any way to get request data from an event...
> 
> Why would you want to? If you really want to use events, throw an event
> that also holds on to the request. I still think that this wouldn't be
> necessary in most cases.

I sometimes send out an email from an event handler and
getInteraction().participations[0].principal.title is a convenient way
to tell the recipient of the mail who it was that initiated the
change... (from John's post I begin to understand that I might find the
actors details stored in an annotation (if its an annotatable content
object thats been altered))

Rupert (who clearly doesn't 'get' some things yet...)
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Re: Access request object from content_factory

2006-06-21 Thread Rupert Redington


John Smith wrote:
> --- Rupert Redington <[EMAIL PROTECTED]> wrote:
>  
>> I realise that I shouldn't use zapi anymore... apart
> 
> 
> Good gracious!
> 
> No zapi?
> 
> How did I miss that? Where do I get my utilities,
> parents, roots, adapters from now?
> 
> John.
> 
> (dazed and confused)
> 
> 

I think the right answer to that is "wherever zapi got them from in the
first place"

reading zope/app/zapi/__init__.py is informative...

Rupert

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


[Zope3-Users] Formlib and fieldsets

2006-06-21 Thread Rupert Redington
Hi All,

I can't find anything in Formlib to indicate that there's a well trodden
path to handling fieldsets in formlib.

I'm not really sure what the best way to do this is. Clearly the formlib
form templates that I can see in Zope 3.2 don't contain any code for
handling fieldsets - but that doesn't sound too hard to manage.

Where though should fieldset definitions be handled?

Rupert
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Re: Access request object from content_factory

2006-06-21 Thread Rupert Redington
Philipp von Weitershausen wrote:
> Marco Mariani wrote:
>> Rupert Redington wrote:
>>> from zope.security.management import getInteraction
>>>
>>> request = getInteraction().participations[0]
>>>
>>> Why this works is outlined (IIRC) in zope/app/securitypolicy/zopepolicy.txt.
>>>
>>> There may well be better ways to fish for the request than this... any
>>> offerings?
>>>   
>> In my understanding, if you need to look for the request inside a
>> content object, you're doing something that should be done in another
>> place, be it a view or an adapter.
> 

I understand this... I think...

> Indeed.
> 
>> Of course, I've been wrong before :-]
> 
> Not this time :).
> 
> The hack displayed above (going thru the security interaction) should
> not be considered a standard procedure for getting at the request in
> places where you don't have it. Content objects are dull. They do
> nothing. Other stuff does things *to* them. Mats' solution is the better
> one.
> 

That's me told :-)

The place I found myself doing this was not in a content object, but in
a local utility which needed to return some absolute urls:

siteurl = zapi.absoluteURL(getSite(), getInteraction().participations[0])

I really don't like passing the request from the view to the utility's
method - I often end up calling one utility from another and feel
uncomfortable with forwarding the request through several calls - it
just seems ugly.

I realise that I shouldn't use zapi anymore... apart from that - what
can I do to achieve the effect of lines like the one above without
resorting to a hack?

Furthermore I sometimes find myself using this in event subscribers - I
can't see any way to get request data from an event...

What am I missing this time?

Cheers

Rupert
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Access request object from content_factory

2006-06-21 Thread Rupert Redington
Hi John,

When I'm looking for the request object from somewhere like that I use

from zope.security.management import getInteraction

request = getInteraction().participations[0]

Why this works is outlined (IIRC) in zope/app/securitypolicy/zopepolicy.txt.

There may well be better ways to fish for the request than this... any
offerings?

Rupert

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Create RSS feed

2006-06-01 Thread Rupert Redington
Tarek Ziadé wrote:
> Achim Domma wrote:
> 
>> Hi,
>>
>> I want to provide an RSS for a content object which is a site. Seems
>> to me, like this should be a generic functionality so I wonder if
>> there is already some product which I did not found!?
>>
>> regards,
>> Achim
>>
>> ___
>> Zope3-users mailing list
>> Zope3-users@zope.org
>> http://mail.zope.org/mailman/listinfo/zope3-users
> 
> 
> Hi,
> Take a look here http://zope-cookbook.org/cookbook/recipe59
> 
> Tarek
> 
> ___
> Zope3-users mailing list
> Zope3-users@zope.org
> http://mail.zope.org/mailman/listinfo/zope3-users


I've found PyRSS2Gen
(http://www.dalkescientific.com/Python/PyRSS2Gen.html) very useful for
doing the work of formatting the feed from inside a BrowserView.

Rupert
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] ViewletManager

2006-03-29 Thread Rupert Redington

Hi David,



should do it...

Rupert

David Johnson wrote:
> Has anyone used a viewlet manager?  I think I understand how to define one,
> but I don't think I understand how to make it show up on a page.  Is it a
> skin thing or some tal code?  I'm think it must work something like:
> 
>  
> 
> 
> 
> 
> 
> some top of page viewlet goes here like
> a stock ticker
> 
> Body
> 
> 
> 
> 
> 
> 
> 
>  
> 
> --
> 
> David Johnson
> 
> [EMAIL PROTECTED]
> 
> 201 Main Street Suite 1320
> 
> Fort Worth, TX 76102
> 
> (877) 572-8324 x2200
> 
>  
> 
> 
> 
> 
> 
> 
> ___
> Zope3-users mailing list
> Zope3-users@zope.org
> http://mail.zope.org/mailman/listinfo/zope3-users
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Grants to unathenticatedPrincipal[Resolved]

2006-03-20 Thread Rupert Redington
Frank Burkhardt wrote:
> Hi,
> 
> On Sat, Mar 18, 2006 at 10:32:39AM +0000, Rupert Redington wrote:
>> When I try to make a permission or role based grant to zope.anybody
>> through zcml I fail with:
>>
>>  File "/home/rupert/Zope3/lib/python/zope/app/security/principal.py",
>> line 50, in checkPrincipal
>> raise ValueError("Undefined principal id", principal_id)
>> zope.configuration.config.ConfigurationExecutionError:
>> exceptions.ValueError: ('Undefined principal id', 'zope.anybody')
>>
>> But the principal is defined in principals.zcml...
>> If I try to overrride 'zope.anybody' by declaring my own
>> unauthenticatedPrincipal in overrides.zcml my grant fails in a similar
>> manner.
>>
>> Is it possible to make grants to the unauthenticatedPrincipal?
> 
> Yes.
> 
>> What am I missing this time?
> 
> You most probably tried to grant before defining the principal.
> Have a look at etc/site.zcml - securitypolicy.zcml is processed
> before principals.zcml . Placing your '' somewhere
> behind those two includes should work.
> 
> Regards,
> 
> Frank

Thanks Frank,

That was it indeed...

Rupert
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


[Zope3-Users] Grants to unathenticatedPrincipal

2006-03-18 Thread Rupert Redington
When I try to make a permission or role based grant to zope.anybody
through zcml I fail with:

 File "/home/rupert/Zope3/lib/python/zope/app/security/principal.py",
line 50, in checkPrincipal
raise ValueError("Undefined principal id", principal_id)
zope.configuration.config.ConfigurationExecutionError:
exceptions.ValueError: ('Undefined principal id', 'zope.anybody')

But the principal is defined in principals.zcml...
If I try to overrride 'zope.anybody' by declaring my own
unauthenticatedPrincipal in overrides.zcml my grant fails in a similar
manner.

Is it possible to make grants to the unauthenticatedPrincipal?

What am I missing this time?

Cheers

Rupert
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Check permissions

2006-03-17 Thread Rupert Redington

from zope.security.management import checkPermission

if checkPermission('zope.ManageContent', self.context):
""" ... """

Cheers,

Rupert

Frank Burkhardt wrote:
> Hi,
> 
> how can I test, if the current principal (e.g. by being member in a special
> group) has a given permission on a given content object?
> 
> Maybe something like this:
> 
>  if 'zope.ManageContent' in self.context.permissions():
> """..."""
> 
> This should include all permission defined in ZCML *and* all permission
> granted in ZMI.
> 
> Thank you for all hints.
> 
> Regards,
> 
> Frank
> ___
> Zope3-users mailing list
> Zope3-users@zope.org
> http://mail.zope.org/mailman/listinfo/zope3-users
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Problem with the Zope3 book Example (Can't Browse Interface in Zope 3.2)

2006-02-27 Thread Rupert Redington
Siddhartha Azad wrote:
> Hi all,
> I recently bought the "Web component Devlopment with
> Zope3" book and downloaded the worldcookery example. I
> tried to deploy the example (chapter 5) into my Zope
> 3.2 instance and restarted it. The book says that I
> should click on "Manage Site" and go to "Site
> Management" where I will see a "Browse Interfaces"
> option, but I couldn't find any such 'Browse
> Interfaces' tab. Is this not present in Zope 3.2 or is
> my Zope instance not showing the IRecipe interface.
> To deploy the example, I moved it to my instances'
> python/lib/worldcookery and added the
> worldcookery-configure.zcml into etc/package-includes.
> Please let me know if anyone is facing similar
> problems with this example in Zope 3.2.
> Thanks, Sid.

Hi Sid,

My answers are often flawed but I'll plow on anyway.

Philipp's book is great, and I found it pleasant to digest - there have
been plenty of changes since its publication though...

AFAIK there is no longer a "Browse Interfaces" tab...
The route I've been using to get to this information varies a little but:

In your case - point your browser at http://host:port/++apidoc++

This is an invaluable resource! From the top left panel choose
"Interface Types" then in the bottom right expand "IContentType", if all's
well you should find IRecipe in there.

Once you've added a Recipe object to the ZODB you can more quickly find
this kind of information by visiting the object in your browser and
choosing its "Introspector" tab.

Hope this is of some use.

Rupert
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] zodb objects backup

2006-02-25 Thread Rupert Redington
Alen Stanisic wrote:
> On Sat, 2006-02-25 at 07:52 -0600, Andreas Jung wrote:
>> --On 26. Februar 2006 00:04:39 +1100 Alen Stanisic 
>> <[EMAIL PROTECTED]> wrote:
>>
>>> Hello,
>>>
>>> what would be the best way of taking a backup of persistent objects
>>> inside Data.fs with possibility to rebuild it on a fresh Zope 3 install
>>> in case of a disaster recovery lets say.
>>>
>> Just backup the Data.fs file.
>>
> 
> For some reason it doesn't feel completely safe just relying on Data.fs.
> Maybe I am thinking too much in rdb land and transaction logging where
> you could rebuild your db from the logs.
> 
> Alen

I once felt like this... But I've learned to stop worrying and love the
ZODB :-)

I can recommend looking into the very useful repozo.py which ships as
part of ZODB tools - at least in all the Zope-2 series (afaik). Its
invaluable for making incremental backups of your Data.fs as it grows.
(There are some issues about copying the Data.fs out of a running zope
instance...)

I don't have a production application in deployed with Zope3 (yet), but
a quick 'tree' informs me that repozo.py isn't shipped with Zope-3.2.
Can anyone tell me why not?

Cheers

Rupert
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Trying to use browser:form -> 404

2006-02-10 Thread Rupert Redington
Florian Lindner wrote:

> 
> Also specifying an interface and calling the view from an object implementing 
> this interface does not make it work.
> 
>> FYI - Florian, it appears we're doing something very similar - mines a
>> signup/registration form too! Do you intend to submit the form data to a
>> method on a localUtility?
> 
> Don't know exactly how I will proccess the data... first task is to make the 
> form working... :-(
> 
> Florian

Here's what I'm using,
Rupert:



class ISingletonSignup(Interface):
"""A minimal schema for use in a sign-up process.

Gathers a username and full name and email.
"""

login = TextLine(title=u"Login",
 description=u"Login/Username.",
 required=True)

title = TextLine(title=u'Full Name',
 description=u"Your real name",
 required=True)

email = TextLine(title=u'Email',
 description=u'The email address to which your
password will be sent.',
 required=True)


class SignUp:

def getData(self):
return {}

def setData(self):
pass
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Trying to use browser:form -> 404

2006-02-10 Thread Rupert Redington
Florian Lindner wrote:
> Am Freitag, 10. Februar 2006 15:18 schrieb Garanin Michael:
>> I simulate this for Buddy from buddydemo (see attached) ==> it is normal
>> work for Buddy-object!
>>
>> I think you make mistakes:
>> 1) __init__ for 'view' always get 3-parameters (self, context, request)
> 
> I've removed __init__ from the view class, like you did.
> 
>> 2) getData must return dictionary.
> 
> getData was never called (otherwise I would jumped into pdb).
> 
> Anyway, I've changed it accordingly and still no success.
> 
> Any more ideas?
> 
> Florian

I've just run the same test, Michael's code works for me, but _only_
when I declare an interface specifically in the "for" attribute,

eg:
for="persistent.interfaces.IPersistent"

if I use a wildcard I get the 404 Florian describes...

Rupert
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Trying to use browser:form -> 404

2006-02-10 Thread Rupert Redington
Garanin Michael wrote:
> В Птн, 10/02/2006 в 14:22 +0100, Florian Lindner пишет:
>> Am Freitag, 10. Februar 2006 14:05 schrieb Garanin Michael:
>>> Do you register the 'centershock'skin?
>>> Write this part of zcml-code, please.
>> Yes, there are a number of page directives that use the centershock skin and 
>> are working correctly.
>>
>> Florian
> Do you include 'default'-layer to 'centershock'-skin definition?
> I think 'browser:form' ignore 'layer'-attribute and use
> 'default'-layer

I don't think that's the problem.

I've just run into the very same problem - which occurs in every skin I
use (including the default + Debug)

It seems to me that browser:form doesn't respect for="*" in the same way
that browser:page does.

Of course once I specify a particular interface I soon run ito rouble
rendering the widgets.

FYI - Florian, it appears we're doing something very similar - mines a
signup/registration form too! Do you intend to submit the form data to a
method on a localUtility?

Rupert


___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


[Zope3-Users] Javascript and custom widgets

2006-02-09 Thread Rupert Redington
I'm missing something... again...

I've started writing some widgets for my current project, some of which
will make use of some javascript.

I'd like to load a script in the head of the page when such a widget is
being used (so that a window.onload function can parse the dom tree and
apply the relevant javascript to the widget). It seems a shame to add
such a script into the main template of my skin - since that will result
in the script running on every page, regardless of whether its needed.
Also that would deprive my widget of its spangly functions when being
used in another skin - such as rotterdam.

Like-wise I don't really want to write a custom template for the form.
The autoform machinery is so cool...

I hoped to find ZCML directive which would load a resource into a slot
for a particular browser:editForm/addForm. No such luck.

Looking around I found the pagelet directive that tiks uses to overcome
the same problem in places like its fckeditor widget - is this the way
forward? Is the pagelet likely to make it into the core?

What am I missing today?

Thanks in advance for any sage advice.

Rupert
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] passing data to nextURL()

2006-02-07 Thread Rupert Redington


> How would you do it in another framework? 
> 
> One solution would be to pass along a nextURL field name. Would that work for 
> you?
> 
> Regards,
> Stephan

You're right, of course, passing the return url in a hidden form field
is the usual solution. I've always felt it's slightly inelegant though -
whatever the framework.

I got excited when I came across nextURL(), thinking that there was
going to be some great magic which would do the job (I'm getting used to
finding magic - which I don't always grasp - doing great things in Zope3
"Revelation" ).

I'm not clear how to institute such a url passing scheme alongside the
schema driven form machinery. I can see that a custom nextURL() will be
needed, and that the form should include a field containing a value
derived from request.getHeader('HTTP_REFERER'). But where do I start in
order to make that field turn up in my forms... Would I need a custom
widget/field and a declaration in the interface I'm using for the form?

Thanks for taking the time, and thanks for your book...

R
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Best way to add a Principal to PAU

2006-02-07 Thread Rupert Redington
Florian Lindner wrote:
> Am Sonntag, 5. Februar 2006 22:37 schrieb Stephan Richter:
>> On Sunday 05 February 2006 12:34, Florian Lindner wrote:
>>> I've managed to add a principal to a principal folder inside a PAU:
>>>
>>>   pau = getUtility(IAuthentication)
>>>   pfolder = pau.keys()[0]
>>>   principal = InternalPrincipal("def", "pwd123","a title", "a
>>> description") pfolder["def"] = principal
>>>
>>> but I doubt that the most elegant way. How can I achieve do it more or
>>> less agnostic form the principal source (or a least from the name and
>>> ordinal postion inside PAU)?
>> Basically, your application should know the location of the Authentication
>> Utility and the name of the principal folder. Also note that the principal
>> class is principal folder specific.
> 
> Ok, so the way above is the way to go?
> 
> Why is the principal class folder specific?
> 
> BTW: Why does z.a.authentication.principalfolder.InternalPrincipal does not 
> implement z.security.interfaces.IPrincipal? Or let 
> z.a.authentication.principalfolder.IInternalPrincipal derive from IPrincipal?
> 
> Florian
> ___
> Zope3-users mailing list
> Zope3-users@zope.org
> http://mail.zope.org/mailman/listinfo/zope3-users

This:

from zope.interface import directlyProvides

pau = getUtility(IAuthentication)

for plugin in pau.authenticatorPlugins:
if directlyProvides(plugin, IMyMarkerInterface):
pfolder = plugin

Seems to me to avoid embarrassment when there are two authenticators in
the stack in pau and you can't guarantee the position of the one you want.

I think...

Rupert

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Still trying to figure out PAU

2006-02-03 Thread Rupert Redington
Florian Lindner wrote:
> Am Freitag, 3. Februar 2006 04:07 schrieb Gary Poster:
>> On Feb 2, 2006, at 4:41 PM, Florian Lindner wrote:
>>> Hello,
>>> I'm still desperately trying to figure out the
>>> PluggableAuthentication.
>> Since no one has replied, I'll try my "30-second remediation"
>> technique again. ;-)  That means I didn't really follow exactly what
>> you are doing, and I'm just trying for low-hanging fruit to help
>> you. :-)
> 
> :-)
> 
>>> I perform the following steps:
>>>
>>> 1) Create an instance of my folderish, possible site (named A),
>>> content
>>> object.
>>>
>>> 2) I create a site in it.
>>>
>>> 3) I add a PAU in the default software space
>>>
>>> 4) I add a SessionCredentialsPlugin and a PrincipalFolder as plugins.
>>>
>>> 5) I create a internal principal with "Title" =
>>> "zope.Manager" (tried also
>>> other ones). name = abc
>>>
>>> 6) In the SessionCredentialsPlugin I leave to "loginForm.html". I've a
>>> loginForm.html view in my A-object)
>>>
>>> 7) I register all components (SessionCreadentiasPlugin,
>>> PrincipalFolder and
>>> PAU)
>> So that means that http://127.0.0.1:8080/++etc++site/default/test.pau/
>> @@configure.html (or similar) has one credentials plugin in the right
>> column ("Session Credentials (a utility)") and one authenticator
>> plugin in the right column ("PrincipalFolder (a utility)" or
>> something like that).  Right?
>>
>> If not, make it so.  :-)
> 
> It was already like that, forgot to mention it.
> 
>> If that doesn't work, try making the right column of the Credentials
>> Plugins field be "No Challenge if Authenticated (a utility)" first
>> and then "Session Credentials (a utility)" second.  That's probably
>> what you want anyway.
> 
> Changed it a bit.
> 
> I'm not redirected to the loginForm.html but a "Not authorized" page. 
> Anything 
> else is the same. I wonder why I'm not authorized, because in the 
> authenticateCredentials() function the internal.title returns:
> 
> (Pdb) internal.title
> u'zope.Manager'
> 
> Which should be authorized for anything.
> 
> Hope you can hang the fruits a few centimeter lower...  ,-)
> 
> Thanks!
> 
> Florian

If this fruit is low enough for me I'll be very surprised, and you've
probably done this already, but:

Does the Principal you've added to your PAU authentication plugin have a
grant on the site/folder you're trying to access?

Rupert
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] "Forbidden Attribute" errors whilst adapting to schema

2006-02-03 Thread Rupert Redington
Dominik Huber wrote:

> I prefer the trusted adapter because they encapslulate the adapter
> inside a security proxy. Then the trusted
> adapter has full access to the underlying object. That simplifies the
> security story very much because you handle it on the adation level. If
> you use locatable and trusted adapters everything works like you would
> access a regular content object.

That makes sense - though I'm not clear about how to make an adapter
"locatable" - which I think is the root cause of my next problem :(

When I apply the techniques which worked (with your help) in my
adaptertest case to the marginally more complex case I'm working on I'm
denied access to the editForm - the error page which appears when I
decline to authenticate contains nothing but "You're not allowed in
here" and the name of the first schema field specified in my
browser:editForm...

I made an attempt to remedy this by having my adapter implement
ILocation - but all that gains me is a failure to find __parent__  -
which is fair enough - since I can't see where I'd have got one from...

I'm at a loss to know why one example works and the other doesn't.

> 
> Regular adapters do not provide an own security proxy but do wrap an
> security proxied
> content object. Everything coming from this security-proxied content
> object will get wrapped into a security-proxy too.
> Therefore your annotated object will be security-proxied. IMO it not
> possible to set permissions granularly to implementations on annotations
> level, because different application provide different permission
> declarations.
> 

I see - there doesn't seem much application for regular adapters in the
sort of thing I'm trying to do at the moment.

Thanks once again.

Rupert
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] "Forbidden Attribute" errors whilst adapting to schema

2006-02-03 Thread Rupert Redington
Dominik Huber wrote:
> Rupert Redington wrote:
> 
>>  >  for=".interfaces.ILink"
>>  provides=".interfaces.ILinkDetails"
>>  factory=".link.LinkDetails"
>>  trusted="True"
>>  />
>>  
>>
> if you use trusted adapters you have to declare an additional class or
> content directive for the adapter itself.:
> 
>  
>permission="zope.View"
>interface=".interfaces.ILinkDetails"
>/>
>permission="zope.ManageContent"
>set_schema=".interfaces.ILinkDetails"
>/>
>  
> 
> regards,
> dominik
> 

Thank you - thats an instafix.

I only added the "trusted" declaration to get round an earlier error in
which the adapter couldn't access the objects annotations...

Am I right in thinking that a trusted adapter isn't really necessary for
this sort of use? How would one then aviod being denied access to the
annotations?

Thanks again,

Rupert

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


[Zope3-Users] "Forbidden Attribute" errors whilst adapting to schema

2006-02-03 Thread Rupert Redington
Morning (if it is for you)...

I've been trying to write an adapter which stores data submitted by a
schema generated form into the annotations on an object. I've been
guided in this by both Stephan's and Philipp's books (though neither
provide an example of what I'm trying to do). My unit tests indicate
that my adapter functions correctly. But when I try to access a
browser:editForm for the schema I receive the traceback below. I've made
several attempts to work around/though the errors, but I soon find
myself out of my depth in a world of LocationProxys.

I've written the simplest example that I can - but I'm not sure that it
would be acceptable to attach a tarball to a mail to this list. I've put
it up here: http://www.neontribe.co.uk/~rupert/adaptertest.tar.bz2

Figuring that, since my unittests run, I've probably misconfigured
myself into a permissions problem I've also included the ZCML from my
example.

Thanks in advance for any advice


http://namespaces.zope.org/zope";
xmlns:i18n="http://namespaces.zope.org/i18n";
i18n_domain="adaptertest">

  

  




  

  


  




.browser/configure.zcml

http://namespaces.zope.org/zope";
xmlns:browser="http://namespaces.zope.org/browser";
i18n_domain="adaptertest">



  

  

  

  




Error type: zope.security.interfaces.ForbiddenAttribute
Error object: ('description', )

  File "/home/rupert/Zope3/lib/python/zope/publisher/publish.py", line
135, in publish
object = request.traverse(object)

  File "/home/rupert/Zope3/lib/python/zope/publisher/browser.py",
line 500, in traverse
ob = super(BrowserRequest, self).traverse(object)

  File "/home/rupert/Zope3/lib/python/zope/publisher/http.py", line
451, in traverse
ob = super(HTTPRequest, self).traverse(object)

  File "/home/rupert/Zope3/lib/python/zope/publisher/base.py", line
289, in traverse
subobject = publication.traverseName(

  File
"/home/rupert/Zope3/lib/python/zope/app/publication/publicationtraverse.py",
line 46, in traverseName
ob2 = namespaceLookup(ns, nm, ob, request)

  File
"/home/rupert/Zope3/lib/python/zope/app/traversing/namespace.py", line
121, in namespaceLookup
return traverser.traverse(name, ())

  File
"/home/rupert/Zope3/lib/python/zope/app/traversing/namespace.py", line
363, in traverse
name=name)

  File "/home/rupert/Zope3/lib/python/zope/component/__init__.py",
line 165, in queryMultiAdapter
return sitemanager.queryMultiAdapter(objects, interface, name, default)

  File "/home/rupert/Zope3/lib/python/zope/component/site.py", line
75, in queryMultiAdapter
default)

  File "/home/rupert/Zope3/lib/python/zope/interface/adapter.py",
line 475, in queryMultiAdapter
return factory(*objects)

  File
"/home/rupert/Zope3/lib/python/zope/app/form/browser/editview.py", line
64, in __init__
self._setUpWidgets()

  File
"/home/rupert/Zope3/lib/python/zope/app/form/browser/editview.py", line
69, in _setUpWidgets
names=self.fieldNames)

  File "/home/rupert/Zope3/lib/python/zope/app/form/utility.py",
line 187, in setUpEditWidgets
value = field.get(source)

  File
"/home/rupert/Zope3/lib/python/zope/schema/_bootstrapfields.py", line
171, in get
return getattr(object, self.__name__)

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


[Zope3-Users] passing data to nextURL()

2006-01-25 Thread Rupert Redington
I'm currently writing a blogging application in zope3, and enjoying the
learning curve after some years working with zope/plone.

I need for users to add comments to items (so I've got a content class
and the requisite browser:addform entries etc) all of which works fine.

My problem is that after adding a comment users are returned to a view
of the container to which the comment was added, whilst on the whole
I'll want them to return to the location they were at when they hit an
add-comment link.

my links are (currently) of the form:

http://localhost:8090/testblog/testpost/+/action.html?type_name=AddComment.html

and in this instance I'd want them to return to:

http://localhost:8090/testblog

But sadly for me the return url won't always be in the containment
hierarchy (imagine adding a comment to an aggregated page showing posts
from several blogs and returning to that aggregator rather than to the
blog which is the parent of the post commented on).

I can affect this behaviour to some extent using nextURL() but the best
I can manage is to construct a nextURL which is in some way connected to
the comment's location. (using Stephan's post to this list
http://www.mail-archive.com/zope3-users@zope.org/msg01048.html )

So far attempts to use the HTTP_REFERER from the request headers have
failed since by the time nextURL comes into play the trail has gone cold.

In what way (or ways) am I being wrongheaded and what would be a
zope3ish solution to this case?

Cheers,

Rupert

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users