[Zope-CMF] overrideDiscussionFor() in discussion tool

Alec Mitchell apm13 at columbia.edu
Sun May 9 01:29:17 EDT 2004


On Saturday 08 May 2004 11:36 am, Dieter Maurer wrote:
> Indeed.
> Moreover, "hasattr" looks for class variables, too.
>
> >Perhaps this is a bug?
>
> Probably.
>
> You can try to replace "hasattr(content, 'allow_discussion')"
> by "content.__dict__.has_key('allow_discussion')".
>
> This expects the "DiscussionTool" to carefully avoid
> acquiring "allow_discussion").

Why not 'ask for forgiveness instead of permission', skip the attribute check, 
and just do:

try:
    del content.allow_discussion
except KeyError, AttributeError:
    pass

I've also found that the explicit permission check earlier in that same 
function can be very inconvenient:

In Archetypes this function is called during construction, before the initial 
workflow state has been set.  As a result, if the creator doesn't have 
'ModifyPortalContent' on the parent object then the call fails, even when the 
default workflow state for the new object grants that permission to the user.  

I think it is not unusual to allow users to add content to a folder which they 
cannot modify (i.e. the title and metadata for the parent folder should be 
unalterable, but new content may be added and edited according to workflow); 
this permission check causes problems for that use case.  Perhaps Archetypes 
should just enclose the call to 'overrideDiscussionFor' in a try block (it is 
perhaps mistakenly calling the function too early in construction), but I 
think it might make more sense to check for 'AddPortalContent' or 
'ModifyPortalContent' in the function itself.

Alec Mitchell



More information about the Zope-CMF mailing list