11from AccessControl import Unauthorized
2- from Products .CMFCore .utils import getToolByName
32from plone .memoize .view import memoize
43from plone .protect .interfaces import IDisableCSRFProtection
4+ from Products .CMFCore .utils import getToolByName
55from workflow .manager .actionmanager import ActionManager
6- from workflow .manager .permissions import (
7- allowed_guard_permissions ,
8- managed_permissions ,
9- )
6+ from workflow .manager .permissions import allowed_guard_permissions
7+ from workflow .manager .permissions import managed_permissions
108from zope .component import getMultiAdapter
9+ from zope .component import getUtility
1110from zope .interface import alsoProvides
1211from zope .schema .interfaces import IVocabularyFactory
13- from zope .component import getUtility
14- import json
1512
1613
1714class Base :
1815 """A stateless helper for workflow API services."""
1916
20- def __init__ (self , context , request , workflow_id = None , state_id = None , transition_id = None ):
17+ def __init__ (
18+ self , context , request , workflow_id = None , state_id = None , transition_id = None
19+ ):
2120 """
2221 Initialize with context, request, and specific IDs from the service.
2322 """
@@ -56,7 +55,11 @@ def selected_workflow(self):
5655 def selected_state (self ):
5756 """Gets the state object based on the IDs provided at initialization."""
5857 workflow = self .selected_workflow
59- if workflow and self ._state_id and self ._state_id in workflow .states .objectIds ():
58+ if (
59+ workflow
60+ and self ._state_id
61+ and self ._state_id in workflow .states .objectIds ()
62+ ):
6063 return workflow .states .get (self ._state_id )
6164 return None
6265
@@ -65,7 +68,11 @@ def selected_state(self):
6568 def selected_transition (self ):
6669 """Gets the transition object based on the IDs provided at initialization."""
6770 workflow = self .selected_workflow
68- if workflow and self ._transition_id and self ._transition_id in workflow .transitions .objectIds ():
71+ if (
72+ workflow
73+ and self ._transition_id
74+ and self ._transition_id in workflow .transitions .objectIds ()
75+ ):
6976 return workflow .transitions .get (self ._transition_id )
7077 return None
7178
@@ -135,30 +142,36 @@ def validate_csrf_token(self, token):
135142 (self .context , self .request ), name = "authenticator"
136143 )
137144 # Temporarily set the token in the request
138- original_token = self .request .form .get (' _authenticator' )
139- self .request .form [' _authenticator' ] = token
140-
145+ original_token = self .request .form .get (" _authenticator" )
146+ self .request .form [" _authenticator" ] = token
147+
141148 result = authenticator .verify ()
142-
149+
143150 # Restore original token
144151 if original_token is not None :
145- self .request .form [' _authenticator' ] = original_token
152+ self .request .form [" _authenticator" ] = original_token
146153 else :
147- self .request .form .pop (' _authenticator' , None )
148-
154+ self .request .form .pop (" _authenticator" , None )
155+
149156 return result
150157 except Exception :
151158 return False
152159
153160 def get_state (self , state_id ):
154161 """Safely gets a state by its ID from the selected workflow."""
155- if self .selected_workflow and state_id in self .selected_workflow .states .objectIds ():
162+ if (
163+ self .selected_workflow
164+ and state_id in self .selected_workflow .states .objectIds ()
165+ ):
156166 return self .selected_workflow .states [state_id ]
157167 return None
158168
159169 def get_transition (self , transition_id ):
160170 """Safely gets a transition by its ID from the selected workflow."""
161- if self .selected_workflow and transition_id in self .selected_workflow .transitions .objectIds ():
171+ if (
172+ self .selected_workflow
173+ and transition_id in self .selected_workflow .transitions .objectIds ()
174+ ):
162175 return self .selected_workflow .transitions [transition_id ]
163176 return None
164177
@@ -182,11 +195,12 @@ def allowed_guard_permissions(self):
182195 @memoize
183196 def assignable_types (self ):
184197 """Returns a list of all user-friendly content types."""
185- vocab_factory = getUtility (IVocabularyFactory ,
186- name = "plone.app.vocabularies.ReallyUserFriendlyTypes" )
198+ vocab_factory = getUtility (
199+ IVocabularyFactory , name = "plone.app.vocabularies.ReallyUserFriendlyTypes"
200+ )
187201 return sorted (
188202 [{"id" : v .value , "title" : v .title } for v in vocab_factory (self .context )],
189- key = lambda v : v [' title' ]
203+ key = lambda v : v [" title" ],
190204 )
191205
192206 def get_assigned_types_for (self , workflow_id ):
@@ -199,11 +213,11 @@ def get_assigned_types_for(self, workflow_id):
199213
200214 def getGroups (self ):
201215 """Gets a list of all groups in the portal."""
202- acl_users = getToolByName (self .context , ' acl_users' )
216+ acl_users = getToolByName (self .context , " acl_users" )
203217 return sorted (
204218 [
205- {'id' : g .getId (), ' title' : g .getProperty (' title' ) or g .getId ()}
219+ {"id" : g .getId (), " title" : g .getProperty (" title" ) or g .getId ()}
206220 for g in acl_users .source_groups .getGroups ()
207221 ],
208- key = lambda g : g [' title' ].lower ()
222+ key = lambda g : g [" title" ].lower (),
209223 )
0 commit comments