Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Zope: CMF

Should object paste check FTI?

 

 

Zope cmf RSS feed   Index | Next | Previous | View Threaded


wichert at wiggy

Jan 11, 2013, 5:20 AM

Post #1 of 4 (291 views)
Permalink
Should object paste check FTI?

PortalFolderBase overrides _verifyObjectPaste to add some extra checks on top of OFS's CopyContainer to check if content may be pasted: it copies the permission checking (why doesn't it call the base class for that?) and adds code to check for allowed types. There is one check missing there that is checked when creating new object: the FTI may block creation of new content as well through its isConstructionAllowed method. Is there any reason _verifyObjectPaste check this as well? This should be simple to do:

portal_type = getattr(aq_base(obj), 'portal_type', None)
if portal_type:
fti = queryUtility(ITypeInformation, name=portal_type)
if fti is not None and not fti.isConstructionAllowed(self):
raise ValueError('You can not add the copied content here.')

This allows for much more control over content pasting.

Wichert.


wichert at wiggy

Jan 11, 2013, 5:29 AM

Post #2 of 4 (261 views)
Permalink
Re: Should object paste check FTI? [In reply to]

On Jan 11, 2013, at 14:20 , Wichert Akkerman <wichert [at] wiggy> wrote:

> PortalFolderBase overrides _verifyObjectPaste to add some extra checks on top of OFS's CopyContainer to check if content may be pasted: it copies the permission checking (why doesn't it call the base class for that?) and adds code to check for allowed types. There is one check missing there that is checked when creating new object: the FTI may block creation of new content as well through its isConstructionAllowed method. Is there any reason _verifyObjectPaste check this as well? This should be simple to do:
>
> portal_type = getattr(aq_base(obj), 'portal_type', None)
> if portal_type:
> fti = queryUtility(ITypeInformation, name=portal_type)
> if fti is not None and not fti.isConstructionAllowed(self):
> raise ValueError('You can not add the copied content here.')

The change is actually much simpler: replace the current workflow guard check with a call to objType.isConstructionAllowed(self). The FTI checks for workflow guards already so you won't need to duplicate that code anymore either.

Wichert.


y.2013 at wcm-solutions

Jan 11, 2013, 7:11 AM

Post #3 of 4 (266 views)
Permalink
Re: Should object paste check FTI? [In reply to]

Hi!


Wichert Akkerman wrote:
>> PortalFolderBase overrides _verifyObjectPaste to add some extra checks
>> on top of OFS's CopyContainer to check if content may be pasted: it
>> copies the permission checking (why doesn't it call the base class for
>> that?)

It does call the base class *if* support for the deprecated
multi-factories is not required.

>> and adds code to check for allowed types. There is one check
>> missing there that is checked when creating new object: the FTI may
>> block creation of new content as well through
>> its isConstructionAllowed method. Is there any reason
>> _verifyObjectPaste check this as well? This should be simple to do:
>>
>> portal_type = getattr(aq_base(obj), 'portal_type', None)
>> if portal_type:
>> fti = queryUtility(ITypeInformation, name=portal_type)
>> if fti is not None and not fti.isConstructionAllowed(self):
>> raise ValueError('You can not add the copied content here.')
>
> The change is actually much simpler: replace the current workflow guard
> check with a call to objType.isConstructionAllowed(self). The FTI checks
> for workflow guards already so you won't need to duplicate that code
> anymore either.

isConstructionAllowed just returns a boolean value, _verifyObjectPaste
tells you what went wrong. Maybe there should be a new method that
raises errors and can be used by isConstructionAllowed and
_verifyObjectPaste?


Cheers,

Yuppie

_______________________________________________
Zope-CMF maillist - Zope-CMF [at] zope
https://mail.zope.org/mailman/listinfo/zope-cmf

See https://bugs.launchpad.net/zope-cmf/ for bug reports and feature requests


wichert at wiggy

Jan 11, 2013, 7:34 AM

Post #4 of 4 (265 views)
Permalink
Re: Should object paste check FTI? [In reply to]

On Jan 11, 2013, at 16:11 , yuppie <y.2013 [at] wcm-solutions> wrote:

> Hi!
>
>
> Wichert Akkerman wrote:
>>> PortalFolderBase overrides _verifyObjectPaste to add some extra checks
>>> on top of OFS's CopyContainer to check if content may be pasted: it
>>> copies the permission checking (why doesn't it call the base class for
>>> that?)
>
> It does call the base class *if* support for the deprecated multi-factories is not required.
>
>>> and adds code to check for allowed types. There is one check
>>> missing there that is checked when creating new object: the FTI may
>>> block creation of new content as well through
>>> its isConstructionAllowed method. Is there any reason
>>> _verifyObjectPaste check this as well? This should be simple to do:
>>>
>>> portal_type = getattr(aq_base(obj), 'portal_type', None)
>>> if portal_type:
>>> fti = queryUtility(ITypeInformation, name=portal_type)
>>> if fti is not None and not fti.isConstructionAllowed(self):
>>> raise ValueError('You can not add the copied content here.')
>>
>> The change is actually much simpler: replace the current workflow guard
>> check with a call to objType.isConstructionAllowed(self). The FTI checks
>> for workflow guards already so you won't need to duplicate that code
>> anymore either.
>
> isConstructionAllowed just returns a boolean value, _verifyObjectPaste tells you what went wrong. Maybe there should be a new method that raises errors and can be used by isConstructionAllowed and _verifyObjectPaste?

Is the ValueError currently raised by _verifyObjectPaste displayed? OFS itself uses a CopyError(MessageDialog(…)) construct, but that isn't very practical for UIs anywhere as far as I know (I'm not counting the default Zope2 error page).

Wichert.
_______________________________________________
Zope-CMF maillist - Zope-CMF [at] zope
https://mail.zope.org/mailman/listinfo/zope-cmf

See https://bugs.launchpad.net/zope-cmf/ for bug reports and feature requests

Zope cmf RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.