Back to index

plone3  3.1.7
permission.py
Go to the documentation of this file.
00001 #  ATContentTypes http://plone.org/products/atcontenttypes/
00002 #  Archetypes reimplementation of the CMF core types
00003 #  Copyright (c) 2003-2006 AT Content Types development team
00004 #
00005 #  This program is free software; you can redistribute it and/or modify
00006 #  it under the terms of the GNU General Public License as published by
00007 #  the Free Software Foundation; either version 2 of the License, or
00008 #  (at your option) any later version.
00009 #
00010 #  This program is distributed in the hope that it will be useful,
00011 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 #  GNU General Public License for more details.
00014 #
00015 #  You should have received a copy of the GNU General Public License
00016 #  along with this program; if not, write to the Free Software
00017 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 #
00019 """
00020 """
00021 __author__  = 'Christian Heimes <tiran@cheimes.de>'
00022 __docformat__ = 'restructuredtext'
00023 
00024 from Products.CMFCore.permissions import setDefaultRoles
00025 from Products.Archetypes.atapi import listTypes
00026 from Products.ATContentTypes.config import PROJECTNAME
00027 from Products.ATContentTypes.interfaces import IATTopic
00028 from Products.ATContentTypes.interfaces import IATTopicCriterion
00029 
00030 TYPE_ROLES = ('Manager', 'Owner')
00031 TOPIC_ROLES = ('Manager',)
00032 CHANGE_TOPIC_ROLES = TOPIC_ROLES + ('Owner',)
00033 CRITERION_ROLES = ('Manager',)
00034 
00035 # Gathering Topic and Event related permissions into one place
00036 AddTopics = 'Add portal topics'
00037 setDefaultRoles(AddTopics, TOPIC_ROLES)
00038 
00039 ChangeTopics = 'Change portal topics'
00040 setDefaultRoles(ChangeTopics, CHANGE_TOPIC_ROLES)
00041 
00042 ChangeEvents = 'Change portal events'
00043 setDefaultRoles(ChangeEvents, ('Manager', 'Owner',))
00044 
00045 ModifyConstrainTypes = "Modify constrain types"
00046 setDefaultRoles(ModifyConstrainTypes, ('Manager', 'Owner'))
00047 
00048 ModifyViewTemplate = "Modify view template"
00049 setDefaultRoles(ModifyViewTemplate, ('Manager', 'Owner'))
00050 
00051 ViewHistory = "ATContentTypes: View history"
00052 setDefaultRoles(ViewHistory, ('Manager', ))
00053 
00054 UploadViaURL = "ATContentTypes: Upload via url"
00055 setDefaultRoles(UploadViaURL, ('Manager', ))
00056 
00057 permissions = {}
00058 def wireAddPermissions():
00059     """Creates a list of add permissions for all types in this project
00060     
00061     Must be called **after** all types are registered!
00062     """
00063     global permissions
00064     atct_types = listTypes(PROJECTNAME)
00065     for atct in atct_types:
00066         if IATTopic.isImplementedByInstancesOf(atct['klass']):
00067             permission = AddTopics 
00068         elif IATTopicCriterion.isImplementedByInstancesOf(atct['klass']):
00069             permission = "%s Topic: Add %s" % (PROJECTNAME, atct['portal_type'])
00070             setDefaultRoles(permission, CRITERION_ROLES)
00071         else:
00072             permission = "%s: Add %s" % (PROJECTNAME, atct['portal_type'])
00073             setDefaultRoles(permission, TYPE_ROLES)
00074         
00075         permissions[atct['portal_type']] = permission
00076     return permissions