Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Public Attributes | Static Private Attributes
CMFDefault.DefaultWorkflow.DefaultWorkflowDefinition Class Reference
Inheritance diagram for CMFDefault.DefaultWorkflow.DefaultWorkflowDefinition:
Inheritance graph
[legend]
Collaboration diagram for CMFDefault.DefaultWorkflow.DefaultWorkflowDefinition:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def getReviewStateOf
def getCatalogVariablesFor
def listObjectActions
def listGlobalActions
def isActionSupported
def doActionFor
def isInfoSupported
def getInfoFor
def setReviewStateOf
def notifyCreated
def notifyBefore
def notifySuccess
def notifyException
def updateRoleMappingsFor

Public Attributes

 id

Static Public Attributes

string meta_type = 'CMF Default Workflow'
string id = 'default_workflow'
string title = 'Simple Review / Publish Policy'
tuple security = ClassSecurityInfo()

Static Private Attributes

 __implements__ = z2IWorkflowDefinition

Detailed Description

Default workflow definition.

Definition at line 41 of file DefaultWorkflow.py.


Constructor & Destructor Documentation

Definition at line 55 of file DefaultWorkflow.py.

00055 
00056     def __init__(self, id):
00057         self.id = id


Member Function Documentation

def CMFDefault.DefaultWorkflow.DefaultWorkflowDefinition.doActionFor (   self,
  ob,
  action,
  comment = '' 
)
Allows the user to request a workflow action.  This method
must perform its own security checks.

Definition at line 182 of file DefaultWorkflow.py.

00182 
00183     def doActionFor(self, ob, action, comment=''):
00184         '''
00185         Allows the user to request a workflow action.  This method
00186         must perform its own security checks.
00187         '''
00188         allow_review = _checkPermission(ReviewPortalContent, ob)
00189         allow_request = _checkPermission(RequestReview, ob)
00190         review_state = self.getReviewStateOf(ob)
00191         tool = aq_parent(aq_inner(self))
00192 
00193         if action == 'submit':
00194             if not allow_request:
00195                 raise AccessControl_Unauthorized('Not authorized')
00196             elif review_state != 'private':
00197                 raise AccessControl_Unauthorized('Already in submit state')
00198             self.setReviewStateOf(ob, 'pending', action, comment)
00199 
00200         elif action == 'retract':
00201             if not allow_request:
00202                 raise AccessControl_Unauthorized('Not authorized')
00203             elif review_state == 'private':
00204                 raise AccessControl_Unauthorized('Already private')
00205             content_creator = ob.Creator()
00206             pm = getToolByName(self, 'portal_membership')
00207             current_user = pm.getAuthenticatedMember().getId()
00208             if (content_creator != current_user) and not allow_review:
00209                 raise AccessControl_Unauthorized('Not creator or reviewer')
00210             self.setReviewStateOf(ob, 'private', action, comment)
00211 
00212         elif action == 'publish':
00213             if not allow_review:
00214                 raise AccessControl_Unauthorized('Not authorized')
00215             self.setReviewStateOf(ob, 'published', action, comment)
00216 
00217         elif action == 'reject':
00218             if not allow_review:
00219                 raise AccessControl_Unauthorized('Not authorized')
00220             self.setReviewStateOf(ob, 'private', action, comment)

Here is the call graph for this function:

Allows this workflow to make workflow-specific variables
available to the catalog, making it possible to implement
queues in a simple way.
Returns a mapping containing the catalog variables
that apply to ob.

Definition at line 73 of file DefaultWorkflow.py.

00073 
00074     def getCatalogVariablesFor(self, ob):
00075         '''
00076         Allows this workflow to make workflow-specific variables
00077         available to the catalog, making it possible to implement
00078         queues in a simple way.
00079         Returns a mapping containing the catalog variables
00080         that apply to ob.
00081         '''
00082         return {'review_state': self.getReviewStateOf(ob)}

Here is the call graph for this function:

def CMFDefault.DefaultWorkflow.DefaultWorkflowDefinition.getInfoFor (   self,
  ob,
  name,
  default 
)
Allows the user to request information provided by the
workflow.  This method must perform its own security checks.

Definition at line 229 of file DefaultWorkflow.py.

00229 
00230     def getInfoFor(self, ob, name, default):
00231         '''
00232         Allows the user to request information provided by the
00233         workflow.  This method must perform its own security checks.
00234         '''
00235         # Treat this as public.
00236         if name == 'review_state':
00237             return self.getReviewStateOf(ob)
00238 
00239         allow_review = _checkPermission(ReviewPortalContent, ob)
00240         allow_request = _checkPermission(RequestReview, ob)
00241         if not allow_review and not allow_request:
00242             return default
00243 
00244         elif name == 'review_history':
00245             tool = aq_parent(aq_inner(self))
00246             history = tool.getHistoryOf(self.getId(), ob)
00247             # Make copies for security.
00248             return tuple(map(lambda dict: dict.copy(), history))

Definition at line 59 of file DefaultWorkflow.py.

00059 
00060     def getReviewStateOf(self, ob):
00061         tool = aq_parent(aq_inner(self))
00062         status = tool.getStatusOf(self.getId(), ob)
00063         if status is not None:
00064             review_state = status['review_state']
00065         else:
00066             if hasattr(aq_base(ob), 'review_state'):
00067                 # Backward compatibility.
00068                 review_state = ob.review_state
00069             else:
00070                 review_state = 'private'
00071         return review_state

Here is the caller graph for this function:

Returns a true value if the given action name is supported.

Definition at line 175 of file DefaultWorkflow.py.

00175 
00176     def isActionSupported(self, ob, action, **kw):
00177         '''
00178         Returns a true value if the given action name is supported.
00179         '''
00180         return (action in ('submit', 'retract', 'publish', 'reject',))

Returns a true value if the given info name is supported.

Definition at line 222 of file DefaultWorkflow.py.

00222 
00223     def isInfoSupported(self, ob, name):
00224         '''
00225         Returns a true value if the given info name is supported.
00226         '''
00227         return (name in ('review_state', 'review_history'))

Allows this workflow to include actions to be displayed
in the actions box.  Called on every request.

Returns the actions to be displayed to the user.

Definition at line 147 of file DefaultWorkflow.py.

00147 
00148     def listGlobalActions(self, info):
00149         '''
00150         Allows this workflow to include actions to be displayed
00151         in the actions box.  Called on every request.
00152 
00153         Returns the actions to be displayed to the user.
00154         '''
00155         if info.isAnonymous:
00156             return None
00157 
00158         actions = []
00159         catalog = getToolByName(self, 'portal_catalog', None)
00160         if catalog is None:
00161             return actions
00162 
00163         pending = len(catalog.searchResults(review_state='pending'))
00164         if pending > 0:
00165             actions.append(
00166                 {'name': 'Pending review (%d)' % pending,
00167                  'url': info.portal_url +
00168                  '/search?review_state=pending',
00169                  'permissions': (ReviewPortalContent, ),
00170                  'category': 'global'}
00171                 )
00172 
00173         return actions

Here is the call graph for this function:

Allows this workflow to
include actions to be displayed in the actions box.
Called only when this workflow is applicable to
info.object.
Returns the actions to be displayed to the user.

Definition at line 84 of file DefaultWorkflow.py.

00084 
00085     def listObjectActions(self, info):
00086         '''
00087         Allows this workflow to
00088         include actions to be displayed in the actions box.
00089         Called only when this workflow is applicable to
00090         info.object.
00091         Returns the actions to be displayed to the user.
00092         '''
00093         if info.isAnonymous:
00094             return None
00095 
00096         # The following operation is quite expensive.
00097         # We don't need to perform it if the user
00098         # doesn't have the required permission.
00099         content = info.object
00100         content_url = info.object_url
00101         content_creator = content.Creator()
00102         pm = getToolByName(self, 'portal_membership')
00103         current_user = pm.getAuthenticatedMember().getId()
00104         review_state = self.getReviewStateOf(content)
00105         actions = []
00106 
00107         allow_review = _checkPermission(ReviewPortalContent, content)
00108         allow_request = _checkPermission(RequestReview, content)
00109 
00110         append_action = (lambda name, p, url=content_url, a=actions.append:
00111                          a({'name': name,
00112                             'url': url + '/' + p,
00113                             'permissions': (),
00114                             'category': 'workflow'}))
00115 
00116         show_reject = 0
00117         show_retract = 0
00118 
00119         if review_state == 'private':
00120             if allow_review:
00121                 append_action('Publish', 'content_publish_form')
00122             elif allow_request:
00123                 append_action('Submit', 'content_submit_form')
00124 
00125         elif review_state == 'pending':
00126             if content_creator == current_user and allow_request:
00127                 show_retract = 1
00128             if allow_review:
00129                 append_action('Publish', 'content_publish_form')
00130                 show_reject = 1
00131 
00132         elif review_state == 'published':
00133             if content_creator == current_user and allow_request:
00134                 show_retract = 1
00135             if allow_review:
00136                 show_reject = 1
00137 
00138         if show_retract:
00139             append_action('Retract', 'content_retract_form')
00140         if show_reject:
00141             append_action('Reject', 'content_reject_form')
00142         if allow_review or allow_request:
00143             append_action('Status history', 'content_status_history')
00144 
00145         return actions

Here is the call graph for this function:

Notifies this workflow of an action before it happens,
allowing veto by exception.  Unless an exception is thrown, either
a notifySuccess() or notifyException() can be expected later on.
The action usually corresponds to a method name.

Definition at line 274 of file DefaultWorkflow.py.

00274 
00275     def notifyBefore(self, ob, action):
00276         '''
00277         Notifies this workflow of an action before it happens,
00278         allowing veto by exception.  Unless an exception is thrown, either
00279         a notifySuccess() or notifyException() can be expected later on.
00280         The action usually corresponds to a method name.
00281         '''
00282         pass

Notifies this workflow after an object has been created
and put in its new place.

Definition at line 265 of file DefaultWorkflow.py.

00265 
00266     def notifyCreated(self, ob):
00267         '''
00268         Notifies this workflow after an object has been created
00269         and put in its new place.
00270         '''
00271         self.setReviewStateOf( ob, 'private', 'created', '' )
00272         self.notifySuccess(ob, 'created', '')

Here is the call graph for this function:

def CMFDefault.DefaultWorkflow.DefaultWorkflowDefinition.notifyException (   self,
  ob,
  action,
  exc 
)
Notifies this workflow that an action failed.

Definition at line 291 of file DefaultWorkflow.py.

00291 
00292     def notifyException(self, ob, action, exc):
00293         '''
00294         Notifies this workflow that an action failed.
00295         '''
00296         pass

def CMFDefault.DefaultWorkflow.DefaultWorkflowDefinition.notifySuccess (   self,
  ob,
  action,
  result 
)
Notifies this workflow that an action has taken place.

Definition at line 284 of file DefaultWorkflow.py.

00284 
00285     def notifySuccess(self, ob, action, result):
00286         '''
00287         Notifies this workflow that an action has taken place.
00288         '''
00289         pass

Here is the caller graph for this function:

def CMFDefault.DefaultWorkflow.DefaultWorkflowDefinition.setReviewStateOf (   self,
  ob,
  review_state,
  action,
  comment 
)

Definition at line 250 of file DefaultWorkflow.py.

00250 
00251     def setReviewStateOf(self, ob, review_state, action, comment):
00252         tool = aq_parent(aq_inner(self))
00253         pm = getToolByName(self, 'portal_membership')
00254         current_user = pm.getAuthenticatedMember().getId()
00255         status = {
00256             'actor': current_user,
00257             'action': action,
00258             'review_state': review_state,
00259             'time': DateTime(),
00260             'comments': comment,
00261             }
00262         tool.setStatusOf(self.getId(), ob, status)
00263         self.updateRoleMappingsFor(ob)

Here is the caller graph for this function:

Changes the object permissions according to the current
review_state.

Definition at line 298 of file DefaultWorkflow.py.

00298 
00299     def updateRoleMappingsFor(self, ob):
00300         '''
00301         Changes the object permissions according to the current
00302         review_state.
00303         '''
00304         review_state = self.getReviewStateOf(ob)
00305         if review_state == 'private':
00306             anon_view = 0
00307             owner_modify = 1
00308             reviewer_view = 0
00309         elif review_state == 'pending':
00310             anon_view = 0
00311             owner_modify = 0  # Require a retraction for editing.
00312             reviewer_view = 1
00313         elif review_state == 'published':
00314             anon_view = 1
00315             owner_modify = 0
00316             reviewer_view = 1
00317         else:   # This object is in an unknown state
00318             anon_view = 0
00319             owner_modify = 1
00320             reviewer_view = 0
00321 
00322         # Modify role to permission mappings directly.
00323 
00324         new_map = { View: {'Anonymous': anon_view,
00325                            'Reviewer': reviewer_view,
00326                            'Owner': 1}
00327                   , ModifyPortalContent: {'Owner': owner_modify}
00328                   }
00329         return _modifyPermissionMappings(ob, new_map)
00330 
00331 InitializeClass(DefaultWorkflowDefinition)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 47 of file DefaultWorkflow.py.

string CMFDefault.DefaultWorkflow.DefaultWorkflowDefinition.id = 'default_workflow' [static]

Definition at line 50 of file DefaultWorkflow.py.

Definition at line 56 of file DefaultWorkflow.py.

string CMFDefault.DefaultWorkflow.DefaultWorkflowDefinition.meta_type = 'CMF Default Workflow' [static]

Definition at line 49 of file DefaultWorkflow.py.

Definition at line 53 of file DefaultWorkflow.py.

string CMFDefault.DefaultWorkflow.DefaultWorkflowDefinition.title = 'Simple Review / Publish Policy' [static]

Definition at line 51 of file DefaultWorkflow.py.


The documentation for this class was generated from the following file: