Back to index

plone3  3.1.7
VersionSupport.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
00004 # 
00005 # This software is subject to the provisions of the Zope Public License,
00006 # Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
00007 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00008 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00009 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00010 # FOR A PARTICULAR PURPOSE
00011 # 
00012 ##############################################################################
00013 
00014 __version__='$Revision: 1.4 $'[11:-2]
00015 
00016 import ExtensionClass, AccessControl, Acquisition
00017 from Globals import DTMLFile, InitializeClass
00018 from Utility import VersionControlError, isAVersionableResource
00019 from Utility import use_vc_permission
00020 
00021 
00022 class VersionSupport(ExtensionClass.Base):
00023     """Mixin class to support version-controllable resources."""
00024 
00025     manage_options=(
00026         {'label': 'Version Control', 'action':'versionControlMain',
00027          'help':  ('ZopeVersionControl', 'VersionControl.stx'),
00028          'filter': isAVersionableResource,
00029          },
00030         )
00031 
00032     security = AccessControl.ClassSecurityInfo()
00033 
00034     security.declareProtected('View management screens', 'versionControlMain')
00035     versionControlMain = DTMLFile('dtml/VersionControlMain', globals())
00036 
00037     security.declareProtected('View management screens', 'versionControlLog')
00038     versionControlLog = DTMLFile('dtml/VersionControlLog', globals())
00039 
00040     security.declarePrivate('haveRepository')
00041     def haveRepository(self):
00042         try: result = self.getRepository()
00043         except VersionControlError:
00044             return 0
00045         return 1
00046 
00047     security.declarePrivate('getRepository')
00048     def getRepository(self):
00049         # We currently only allow a single repository in a given context.
00050         if hasattr(self, '_v_repository'):
00051             return self._v_repository
00052         try:    items = self.superValues('Repository')
00053         except: items = self.aq_inner.aq_parent.superValues('Repository')
00054         result = items and items[0] or None
00055         if result is None:
00056             raise VersionControlError(
00057                 'No versioning repository was found.'
00058                 )
00059         self._v_repository = result
00060         return result
00061 
00062 
00063     security.declarePublic('isAVersionableResource')
00064     def isAVersionableResource(self, object):
00065         return self.getRepository().isAVersionableResource(self)
00066 
00067     security.declarePublic('isUnderVersionControl')
00068     def isUnderVersionControl(self):
00069         return hasattr(self, '__vc_info__')
00070 
00071     security.declarePublic('isResourceUpToDate')
00072     def isResourceUpToDate(self):
00073         return self.getRepository().isResourceUpToDate(self)
00074 
00075     security.declarePublic('isResourceChanged')
00076     def isResourceChanged(self):
00077         return self.getRepository().isResourceChanged(self)
00078 
00079     security.declarePublic('getVersionInfo')
00080     def getVersionInfo(self):
00081         return self.getRepository().getVersionInfo(self)
00082 
00083     security.declareProtected(use_vc_permission, 'applyVersionControl')
00084     def applyVersionControl(self, REQUEST=None):
00085         """Place a resource under version control."""
00086         repository = self.getRepository()
00087         object = repository.applyVersionControl(self)
00088         if REQUEST is not None:
00089             message="The resource has been placed under version control."
00090             return object.versionControlMain(
00091                 object, REQUEST,
00092                 manage_tabs_message=message
00093                 )
00094 
00095     security.declareProtected(use_vc_permission, 'checkoutResource')
00096     def checkoutResource(self, REQUEST=None):
00097         """Checkout a version-controlled resource."""
00098         repository = self.getRepository()
00099         object = repository.checkoutResource(self)
00100         if REQUEST is not None:
00101             message="The resource has been checked out."
00102             return object.versionControlMain(
00103                 object, REQUEST,
00104                 manage_tabs_message=message
00105                 )
00106 
00107     security.declareProtected(use_vc_permission, 'checkinResource')
00108     def checkinResource(self, message='', REQUEST=None):
00109         """Checkout a version-controlled resource."""
00110         repository = self.getRepository()
00111         object = repository.checkinResource(self, message)
00112         version = object.getVersionInfo().version_id
00113         if REQUEST is not None:
00114             message="The resource has been checked in [version %s]." % version
00115             return object.versionControlMain(
00116                 object, REQUEST,
00117                 manage_tabs_message=message
00118                 )
00119 
00120     security.declareProtected(use_vc_permission, 'uncheckoutResource')
00121     def uncheckoutResource(self, REQUEST=None):
00122         """Uncheckout a version-controlled resource."""
00123         repository = self.getRepository()
00124         object = repository.uncheckoutResource(self)
00125         version = object.getVersionInfo().version_id
00126         if REQUEST is not None:
00127             message="The resource has been reverted to version %s." % version
00128             return object.versionControlMain(
00129                 object, REQUEST,
00130                 manage_tabs_message=message
00131                 )
00132 
00133     security.declareProtected(use_vc_permission, 'updateResource')
00134     def updateResource(self, selector, REQUEST=None):
00135         """Update a version-controlled resource."""
00136         repository = self.getRepository()
00137         if selector == 'LATEST_VERSION':
00138             selector = None
00139         object = repository.updateResource(self, selector)
00140         version = object.getVersionInfo().version_id
00141         if REQUEST is not None:
00142             message="The resource has been updated to version %s." % version
00143             return object.versionControlMain(
00144                 object, REQUEST,
00145                 manage_tabs_message=message
00146                 )
00147 
00148     security.declareProtected(use_vc_permission, 'labelResource')
00149     def labelResource(self, label, force=0, REQUEST=None):
00150         """Label a version-controlled resource."""
00151         repository = self.getRepository()
00152         object = repository.labelResource(self, label, force)
00153         if REQUEST is not None:
00154             message="The label has been applied to this resource."
00155             return object.versionControlMain(
00156                 object, REQUEST,
00157                 manage_tabs_message=message
00158                 )
00159 
00160     security.declareProtected(use_vc_permission, 'getVersionIds')
00161     def getVersionIds(self):
00162         return self.getRepository().getVersionIds(self)
00163 
00164     security.declareProtected(use_vc_permission, 'getLabelsForHistory')
00165     def getLabelsForHistory(self):
00166         return self.getRepository().getLabelsForHistory(self)
00167 
00168     security.declareProtected(use_vc_permission, 'getLabelsForVersion')
00169     def getLabelsForVersion(self):
00170         return self.getRepository().getLabelsForVersion(self)
00171 
00172     security.declareProtected(use_vc_permission, 'getLogEntries')
00173     def getLogEntries(self):
00174         return self.getRepository().getLogEntries(self)
00175 
00176 
00177 InitializeClass(VersionSupport)
00178 
00179