Back to index

plone3  3.1.7
showEditableBorder.py
Go to the documentation of this file.
00001 ## Script (Python) "showEditableBorder"
00002 ##bind container=container
00003 ##bind context=context
00004 ##bind namespace=
00005 ##bind script=script
00006 ##bind subpath=traverse_subpath
00007 ##parameters=template_id=None, allowed_types=None, actions=None
00008 ##title=returns whether or not current template displays *editable* border
00009 ##
00010 
00011 #    TODO: This is an ugly hack.  So it might as well
00012 #    be explained.  Traditionally in CMF actions
00013 #    are lumped in by categories.  workflow/object/folder and more.
00014 #    well.  to show a green border means that the user can
00015 #    interact with the content.  We have to sort of 'action scrap'
00016 #    since 'view' is a action by default anonymous can see we need
00017 #    to make sure 'view' isnt the only action they can do on the object
00018 #    Also we check to see if PUBLISHED method (we have access to because
00019 #    it did publish) is in the actions somewhere.
00020 #
00021 #    Alot of this could be refactored if Actions could do filter for you
00022 #    but I cant suggest right now.  Something like 'I want to query'
00023 #    only actions that are declared for a type in the types tool. It would
00024 #    be convient to be able to get actions from the ActionProviders as well
00025 #    as the portal_actions (aggregate of all ActionProviders)
00026 #
00027 #    This hack can go away if we implement something like CMFViews.
00028 #    We should extend FSMetadata.py for a [plone] section that each
00029 #    template could define explicitly if they want to show their border.
00030 #    But its too late in the game for such a large change.
00031 #    border=None or False or border=True, no border attribute should
00032 #    calculate using the arcane rules below *wink*
00033 
00034 REQUEST=context.REQUEST
00035 
00036 if actions is None:
00037     raise AttributeError, 'You must pass in the filtered actions'
00038     
00039 if REQUEST.has_key('disable_border'): #short circuit
00040     return 0
00041 if REQUEST.has_key('enable_border'): #short circuit
00042     return 1
00043 
00044 from Products.CMFPlone.utils import log
00045 
00046 mtool = context.portal_membership
00047 checkPerm = mtool.checkPermission
00048 
00049 if checkPerm('Modify portal content', context) or\
00050        checkPerm('Add portal content', context)  or\
00051        checkPerm('Review portal content', context):
00052     return 1
00053 
00054 if mtool.isAnonymousUser():
00055     return 0
00056 
00057 if actions.get('workflow', ()):
00058     return 1
00059 
00060 for action in actions.get('object', []):
00061     if action.get('id', '')!='view':
00062         return 1
00063 
00064 for action in actions.get('batch', []):
00065     return 1
00066 
00067 if template_id is None and hasattr(REQUEST['PUBLISHED'], 'getId'):
00068     template_id=REQUEST['PUBLISHED'].getId()
00069 
00070 idActions = {}
00071 for obj in actions.get('object', ()) + actions.get('folder', ()):
00072     idActions[obj.get('id', '')] = 1
00073 
00074 if idActions.has_key('edit') :
00075     if (idActions.has_key(template_id) or \
00076         template_id in ['synPropertiesForm', 'folder_contents', 'folder_listing']) :
00077         return 1
00078 
00079 if context.portal_workflow.getTransitionsFor(context, context):
00080     return 1
00081 
00082 if allowed_types is None:
00083     allowed_types = context.getAllowedTypes()
00084 
00085 # Check to see if the user is able to add content or change workflow state
00086 if allowed_types:
00087     return 1
00088 
00089 return 0