Back to index

plone3  3.1.7
storage.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # PlonePAS - Adapt PluggableAuthService for use in Plone
00004 # Copyright (C) 2005 Enfold Systems, Kapil Thangavelu, et al
00005 #
00006 # This software is subject to the provisions of the Zope Public License,
00007 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this
00008 # distribution.
00009 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00010 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00011 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00012 # FOR A PARTICULAR PURPOSE.
00013 #
00014 ##############################################################################
00015 """
00016 an archetypes storage that delegates to a pas property provider.
00017 
00018 main use.. cmfmember integration w/ properties providers
00019 
00020 """
00021 
00022 from AccessControl import ClassSecurityInfo
00023 from Products.Archetypes.public import IStorage
00024 from Products.PluggableAuthService.utils import classImplements
00025 from Products.PlonePAS.interfaces.propertysheets import IMutablePropertySheet
00026 
00027 class PASStorage(object):
00028 
00029     security = ClassSecurityInfo()
00030 
00031     def get(self, name, instance, **kwargs):
00032         user = instance.getUser()
00033         sheets = user.getOrderedSheets()
00034         for sheet in sheets:
00035             if sheet.hasProperty( name ):
00036                 return sheet.getProperty( name )
00037         raise AttributeError( name )
00038 
00039     def set(self, name, instance, value, **kwargs):
00040         user = instance.getUser()
00041         sheets = user.getOrderedSheets()
00042         for sheet in sheets:
00043             if sheet.hasProperty( name ):
00044                 if IMutablePropertySheet.providedBy( sheet ):
00045                     sheet.setProperty( name, value )
00046                 else:
00047                     raise RuntimeError("mutable property provider shadowed by read only provider")
00048 
00049 classImplements(PASStorage,
00050                 IStorage)