Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setupAdminClient(portal, event):
client = queryUtility(IAdminClient)
if client is None:
settings = getUtility(IRegistry)
try:
jid = settings['jarn.xmpp.adminJID']
jdomain = settings['jarn.xmpp.xmppDomain']
password = settings['jarn.xmpp.adminPassword']
pubsub_jid = settings['jarn.xmpp.pubsubJID']
except KeyError:
return
client = AdminClient(jid, jdomain, password, pubsub_jid)
gsm = getGlobalSiteManager()
gsm.registerUtility(client, IAdminClient)
def checkAdminClientConnected():
else:
dynamic_fti = queryAdapter(fti, IDynamicViewTypeInformation)
if dynamic_fti is not None:
page = dynamic_fti.getDefaultPage(context, check_exists=True)
if page is not None:
return page
# 3.1 Test for default_page attribute in folder, no acquisition
pages = getattr(aq_base(context), 'default_page', [])
if isinstance(pages, six.string_types):
pages = [pages]
for page in pages:
if page and page in ids:
return page
portal = queryUtility(ISiteRoot)
# Might happen during portal creation
if portal is None:
return
# 3.2 Test for default page in portal, acquire
for page in pages:
if portal.unrestrictedTraverse(page, None):
return page
# 4. Test for default sitewide default_page setting
registry = getUtility(IRegistry)
for page in registry.get('plone.default_page', []):
if page in ids:
return page
def discuss_older_docs(context, do_commit=True):
"""Add document discussion on pre-existing documents.
This only adds a 'created' message, since we cannot reconstruct
the publication date and actor.
"""
if context is not None:
# Backport ondelete_archive in order not to fail
# if some documents have been deleted (see quaive/ploneintranet #354)
ondelete_archive(context)
logger.info("Adding streams to older content")
mtool = queryUtility(IMicroblogTool)
haveseen = [x for x in mtool._content_uuid_mapping.keys()]
ctool = api.portal.get_tool('portal_catalog')
i = 0
for brain in ctool.unrestrictedSearchResults(
{'portal_type': [
'Document', 'File', 'Image', 'Event', 'News Item']}):
if brain.UID in haveseen:
continue
created = brain.created
if isinstance(created, DateTime):
created = created.asdatetime()
obj = brain.getObject()
pi_api.microblog.statusupdate.create(
content_context=obj,
action_verb=u'created',
tags=obj.Subject() or None,
def settings(self):
"""Compose a string that contains all registry settings that are
needed for the discussion control panel.
"""
registry = queryUtility(IRegistry)
settings = registry.forInterface(IDiscussionSettings, check=False)
wftool = getToolByName(self.context, "portal_workflow", None)
wf = wftool.getChainForPortalType('Discussion Item')
output = []
# Globally enabled
if settings.globally_enabled:
output.append("globally_enabled")
# Comment moderation
if 'one_state_workflow' not in wf and \
'comment_review_workflow' not in wf:
output.append("moderation_custom")
# p.a.discussion > 2.0 only
#elif settings.moderation_enabled:
# output.append("moderation_enabled")
def getManager(self):
if self.manager is None:
self.manager = queryUtility(ISolrConnectionManager)
return self.manager
members.setLanguage(language)
members.reindexObject()
if wftool.getInfoFor(members, 'review_state') != 'published':
wftool.doActionFor(members, 'publish')
# add index_html to Members area
if 'index_html' not in members.objectIds():
addPy = members.manage_addProduct['PythonScripts'].manage_addPythonScript
addPy('index_html')
index_html = getattr(members, 'index_html')
index_html.write(member_indexhtml)
index_html.ZPythonScript_setTitle('User Search')
# Block all right column portlets by default
manager = queryUtility(IPortletManager, name='plone.rightcolumn')
if manager is not None:
assignable = queryMultiAdapter((members, manager), ILocalPortletAssignmentManager)
assignable.setBlacklistStatus('context', True)
assignable.setBlacklistStatus('group', True)
assignable.setBlacklistStatus('content_type', True)
def protected_field(self, field):
field_identifier = u'{0}.{1}'.format(
field.__module__,
field.__class__.__name__,
)
field_factory = queryUtility(IFieldFactory, name=field_identifier)
return field_factory and field_factory.protected(field)
def getSettings(self, key=None):
"""
"""
fieldclass = component.queryUtility(interfaces.IPlominoField, self.FieldType, None)
if fieldclass is None:
if hasattr(fields, self.FieldType.lower()):
fieldinterface = getattr(getattr(fields, self.FieldType.lower()), "I"+self.FieldType.capitalize()+"Field")
else:
fieldinterface = getattr(getattr(fields, "base"), "IBaseField")
else:
fieldinterface = fieldclass.plomino_field_parameters['interface']
if key is None:
return fieldinterface(self)
else:
return getattr(fieldinterface(self), key, None)
def __call__(self):
"""
Returns the number of tasks in the sanitation-tasks queue
"""
try:
PostOnly(self.context.REQUEST)
except:
logger.error(traceback.format_exc())
return json.dumps({'count': 0})
try:
CheckAuthenticator(self.request.form)
except:
logger.error(traceback.format_exc())
return json.dumps({'count': 0})
task_queue = queryUtility(ITaskQueue, name='sanitation-tasks')
count = len(task_queue) if task_queue is not None else 0
return json.dumps({'count': count})
def get_resource_directory():
"""Obtain the Plomino persistent resource directory, creating it if
necessary.
"""
persistentDirectory = queryUtility(IResourceDirectory, name="persistent")
if not persistentDirectory:
return None
if PLOMINO_RESOURCE_NAME not in persistentDirectory:
persistentDirectory.makeDirectory(PLOMINO_RESOURCE_NAME)
return persistentDirectory[PLOMINO_RESOURCE_NAME]