Back to index

plone3  3.1.7
control.py
Go to the documentation of this file.
00001 ##################################################################
00002 #
00003 # (C) Copyright 2006 ObjectRealms, LLC
00004 # All Rights Reserved
00005 #
00006 # This file is part of iterate.
00007 #
00008 # iterate is free software; you can redistribute it and/or modify
00009 # it under the terms of the GNU General Public License as published by
00010 # the Free Software Foundation; either version 2 of the License, or
00011 # (at your option) any later version.
00012 #
00013 # iterate is distributed in the hope that it will be useful,
00014 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 # GNU General Public License for more details.
00017 #
00018 # You should have received a copy of the GNU General Public License
00019 # along with iterate; if not, write to the Free Software
00020 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 ##################################################################
00022 
00023 from plone.memoize.view import memoize
00024 
00025 from AccessControl import getSecurityManager
00026 from Acquisition import aq_inner
00027 from Products.Five.browser import BrowserView
00028 from Products.Archetypes.interfaces import IReferenceable
00029 
00030 from plone.app.iterate import interfaces
00031 from plone.app.iterate.relation import WorkingCopyRelation
00032 from plone.app.iterate import permissions
00033 
00034 class Control(BrowserView):
00035     """Information about whether iterate can operate.
00036     
00037     This is a public view, referenced in action condition expressions.
00038     """
00039     
00040     @memoize
00041     def checkin_allowed(self):
00042         """Check if a checkin is allowed
00043         """
00044         context = aq_inner(self.context)
00045         
00046         if not interfaces.IIterateAware.providedBy(context):
00047             return False
00048     
00049         if not getSecurityManager().checkPermission(permissions.CheckinPermission, context):
00050             return False
00051         
00052         if not IReferenceable.providedBy(context):
00053             return False
00054 
00055         archiver = interfaces.IObjectArchiver(context)
00056         if not archiver.isVersionable():
00057             return False
00058 
00059         # check to see it is checkout
00060         if not len(context.getReferences(WorkingCopyRelation.relationship)) > 0:
00061             return False
00062         
00063         return True
00064         
00065     @memoize
00066     def checkout_allowed(self):
00067         """Check if a checkout is allowed.
00068         """
00069         context = aq_inner(self.context)
00070         
00071         if not interfaces.IIterateAware.providedBy(context):
00072             return False
00073         
00074         if not getSecurityManager().checkPermission(permissions.CheckoutPermission, context):
00075             return False
00076 
00077         if not IReferenceable.providedBy(context):
00078             return False
00079 
00080         archiver = interfaces.IObjectArchiver(context)
00081         if not archiver.isVersionable():
00082             return False
00083 
00084         # check if there is an existing checkout
00085         if len(context.getBRefs(WorkingCopyRelation.relationship)) > 0:
00086             return False
00087         
00088         # check if its is a checkout
00089         if len(context.getRefs(WorkingCopyRelation.relationship)) > 0:
00090             return False
00091         
00092         return True
00093         
00094     @memoize
00095     def cancel_allowed(self):
00096         """Check to see if the user can cancel the checkout on the given working copy
00097         """
00098         return self.checkin_allowed()