Пример #1
0
def save_reference_number_prefix(obj, event):
    if IDontIssueDossierReferenceNumber.providedBy(obj.REQUEST):
        return

    if IObjectRemovedEvent.providedBy(event):
        return

    parent = aq_parent(aq_inner(obj))
    prefix_adapter = IReferenceNumberPrefix(parent)
    if not prefix_adapter.get_number(obj):
        prefix_adapter.set_number(obj)

    # because we can't control the order of event handlers we have to sync
    # all containing tasks manually
    catalog = api.portal.get_tool('portal_catalog')
    tasks = catalog({
        'path': '/'.join(obj.getPhysicalPath()),
        'object_provides': 'opengever.task.task.ITask',
        'depth': -1
    })
    for task in tasks:
        TaskSqlSyncer(task.getObject(), None).sync()

    # And also proposals
    proposals = catalog({
        'path': '/'.join(obj.getPhysicalPath()),
        'object_provides': 'opengever.meeting.proposal.IProposal',
        'depth': -1
    })
    for proposal in proposals:
        ProposalSqlSyncer(proposal.getObject(), None).sync()

    obj.reindexObject(idxs=['reference'])
Пример #2
0
def lifecycle_logger(obj, event):
    """Log content type life cycle events like object creation,
    modification and removal.
    """
    name = IFingerPointingSettings.__identifier__ + '.audit_lifecycle'
    try:
        audit_lifecycle = api.portal.get_registry_record(name, default=False)
    except ComponentLookupError:  # Plone site removed
        return

    if not audit_lifecycle:
        return

    user, ip = get_request_information()

    if IObjectAddedEvent.providedBy(event):
        action = 'create'
    elif IObjectModifiedEvent.providedBy(event):
        action = 'modify'
    elif IObjectRemovedEvent.providedBy(event):
        action = 'remove'
    else:  # should never happen
        action = '-'

    extras = 'object=' + repr(obj)
    log_info(AUDIT_MESSAGE.format(user, ip, action, extras))
Пример #3
0
def lifecycle_logger(obj, event):
    """Log content type life cycle events like object creation,
    modification and removal.
    """
    # subscriber is registered even if package has not yet been installed
    # ignore any error caused by missing registry records
    try:
        record = IFingerPointingSettings.__identifier__ + '.audit_lifecycle'
        audit_lifecycle = api.portal.get_registry_record(record)
    except (ComponentLookupError, InvalidParameterError):
        return

    if audit_lifecycle:
        user, ip = get_request_information()

        if IObjectCreatedEvent.providedBy(event):
            action = 'create'
            extras = u'object={0}'.format(repr(obj))
        if IObjectModifiedEvent.providedBy(event):
            action = 'modify'
            extras = u'object={0}'.format(repr(obj))
        if IObjectRemovedEvent.providedBy(event):
            action = 'remove'
            extras = u'object={0}'.format(repr(obj))

        log_info(AUDIT_MESSAGE.format(user, ip, action, extras))
Пример #4
0
def save_reference_number_prefix(obj, event):
    if IDontIssueDossierReferenceNumber.providedBy(obj.REQUEST):
        return

    if IObjectRemovedEvent.providedBy(event):
        return

    parent = aq_parent(aq_inner(obj))
    prefix_adapter = IReferenceNumberPrefix(parent)
    if not prefix_adapter.get_number(obj):
        prefix_adapter.set_number(obj)

    # because we can't control the order of event handlers we have to sync
    # all containing tasks manually
    catalog = api.portal.get_tool('portal_catalog')
    tasks = catalog({
        'path': '/'.join(obj.getPhysicalPath()),
        'object_provides': 'opengever.task.task.ITask',
        'depth': -1})
    for task in tasks:
        TaskSqlSyncer(task.getObject(), None).sync()

    # And also proposals
    proposals = catalog({
        'path': '/'.join(obj.getPhysicalPath()),
        'object_provides': 'opengever.meeting.proposal.IProposal',
        'depth': -1})
    for proposal in proposals:
        ProposalSqlSyncer(proposal.getObject(), None).sync()

    obj.reindexObject(idxs=['reference'])
Пример #5
0
def object_moved_or_added(context, event):
    if isinstance(event, ObjectAddedEvent):
        # Don't consider moving or removing an object a "touch". Mass-moves
        # would immediately fill up the touched log, and removals should not
        # be tracked anyway.
        if should_track_touches(context):
            notify(ObjectTouchedEvent(context))

    if IObjectRemovedEvent.providedBy(event):
        return

    # Update object security after moving or copying.
    # Specifically, this is needed for the case where an object is moved out
    # of a location where a Placeful Workflow Policy applies to a location
    # where it doesn't.
    #
    #  Plone then no longer provides the placeful workflow for that object,
    # but doesn't automatically update the object's security.
    #
    # We use ftw.upgrade's update_security_for() here to correctly
    # recalculate security, but do the reindexing ourselves because otherwise
    # Plone will do it recursively (unnecessarily so).
    changed = update_security_for(context, reindex_security=False)
    if changed:
        catalog = api.portal.get_tool('portal_catalog')
        catalog.reindexObject(context, idxs=CatalogAware._cmf_security_indexes,
                              update_metadata=0)
Пример #6
0
def document_moved_or_added(context, event):
    if IObjectRemovedEvent.providedBy(event):
        return

    if context.REQUEST.get(DISABLE_DOCPROPERTY_UPDATE_FLAG):
        return

    _update_docproperties(context)
Пример #7
0
def update_moved_doc_properties(context, event):
    if IObjectRemovedEvent.providedBy(event):
        return

    if context.REQUEST.get(DISABLE_DOCPROPERTY_UPDATE_FLAG):
        return

    _update_docproperties(context)
Пример #8
0
def updateMembersFolderId(ob, event):
    if IObjectAddedEvent.providedBy(event):
        return
    if IObjectRemovedEvent.providedBy(event):
        return
    if ob != event.object:  # pragma: no cover
        return
    # The members folder has been renamed
    registerMembersFolderId(ob, event)
Пример #9
0
def updateMembersFolderId(ob, event):
    if IObjectAddedEvent.providedBy(event):
        return
    if IObjectRemovedEvent.providedBy(event):
        return
    if ob != event.object: # pragma: no cover
        return
    # The members folder has been renamed
    registerMembersFolderId(ob, event)
Пример #10
0
def object_moved_or_added(context, event):
    if isinstance(event, ObjectAddedEvent):
        # Don't consider moving or removing an object a "touch". Mass-moves
        # would immediately fill up the touched log, and removals should not
        # be tracked anyway.
        if should_track_touches(context):
            notify(ObjectTouchedEvent(context))

        # If an object has been copy & pasted, we need to reindex some fields.
        # The IObjectCopiedEvent is too early to do that though, because at
        # that point the object doesn't have a full AQ chain yet. We therefore
        # just mark it during IObjectCopiedEvent, and do the reindexing here.
        if getattr(context, '_v_object_has_been_copied', False):
            context.reindexObject(idxs=reindex_after_copy)

    if IObjectRemovedEvent.providedBy(event):
        return

    # Update object security after moving or copying.
    # Specifically, this is needed for the case where an object is moved out
    # of a location where a Placeful Workflow Policy applies to a location
    # where it doesn't.
    #
    #  Plone then no longer provides the placeful workflow for that object,
    # but doesn't automatically update the object's security.
    #
    # We use ftw.upgrade's update_security_for() here to correctly
    # recalculate security, but do the reindexing ourselves because otherwise
    # Plone will do it recursively (unnecessarily so).
    changed = update_security_for(context, reindex_security=False)
    if changed:
        reindex_object_security_without_children(context)

    # There are several indices that need updating when a dossier is moved.
    # first make sure obj was actually moved and not created
    if not event.oldParent or not event.newParent:
        return

    # When an object is moved, its containing_dossier needs reindexing.
    to_reindex = ['containing_dossier']
    # containing_subdossier is really only used for documents,
    # while is_subdossier is only meaningful for dossiers.
    if IDossierMarker.providedBy(context):
        was_subdossier = IDossierMarker.providedBy(event.oldParent)
        is_subdossier = IDossierMarker.providedBy(event.newParent)
        if was_subdossier != is_subdossier:
            to_reindex.append('is_subdossier')

    if context.portal_type in TYPES_WITH_CONTAINING_SUBDOSSIER_INDEX:
        to_reindex.append('containing_subdossier')

    context.reindexObject(idxs=to_reindex)

    # synchronize with model if necessary
    if ITask.providedBy(context):
        sync_task(context, event)
Пример #11
0
def moved_event(event):
    # only execute moved event if it's not a added or removed event since
    # those are handled elsewhere and they base off of this event class
    if (IObjectAddedEvent.providedBy(event) or
            IObjectRemovedEvent.providedBy(event)):
        return

    obj = event.object
    if not (IContentish.providedBy(obj) or IComment.providedBy(obj)):
        return
    execute_event(obj, event)
Пример #12
0
def document_moved_or_added(context, event):
    if IObjectRemovedEvent.providedBy(event):
        return

    if context.REQUEST.get(DISABLE_DOCPROPERTY_UPDATE_FLAG):
        return

    if IObjectAddedEvent.providedBy(event):
        # Be strict when adding new documents to GEVER, lenient on moving
        # ones that already made it into the system
        _update_docproperties(context, raise_on_error=True)
    else:
        _update_docproperties(context, raise_on_error=False)
Пример #13
0
def document_moved_or_added(context, event):
    if IObjectRemovedEvent.providedBy(event):
        return

    if context.REQUEST.get(DISABLE_DOCPROPERTY_UPDATE_FLAG):
        return

    if IObjectAddedEvent.providedBy(event):
        # Be strict when adding new documents to GEVER, lenient on moving
        # ones that already made it into the system
        _update_docproperties(context, raise_on_error=True)
    else:
        _update_docproperties(context, raise_on_error=False)
Пример #14
0
def object_moved_or_added(context, event):
    if isinstance(event, ObjectAddedEvent):
        # Don't consider moving or removing an object a "touch". Mass-moves
        # would immediately fill up the touched log, and removals should not
        # be tracked anyway.
        if should_track_touches(context):
            notify(ObjectTouchedEvent(context))

    if IObjectRemovedEvent.providedBy(event):
        return

    # Update object security after moving or copying.
    # Specifically, this is needed for the case where an object is moved out
    # of a location where a Placeful Workflow Policy applies to a location
    # where it doesn't.
    #
    #  Plone then no longer provides the placeful workflow for that object,
    # but doesn't automatically update the object's security.
    #
    # We use ftw.upgrade's update_security_for() here to correctly
    # recalculate security, but do the reindexing ourselves because otherwise
    # Plone will do it recursively (unnecessarily so).
    changed = update_security_for(context, reindex_security=False)
    if changed:
        reindex_object_security_without_children(context)

    # There are several indices that need updating when a dossier is moved.
    # first make sure obj was actually moved and not created
    if not event.oldParent or not event.newParent:
        return

    # When an object is moved, its containing_dossier needs reindexing.
    to_reindex = ['containing_dossier']
    # containing_subdossier is really only used for documents,
    # while is_subdossier is only meaningful for dossiers.
    if IDossierMarker.providedBy(context):
        was_subdossier = IDossierMarker.providedBy(event.oldParent)
        is_subdossier = IDossierMarker.providedBy(event.newParent)
        if was_subdossier != is_subdossier:
            to_reindex.append('is_subdossier')

    if context.portal_type in TYPES_WITH_CONTAINING_SUBDOSSIER_INDEX:
        to_reindex.append('containing_subdossier')

    context.reindexObject(idxs=to_reindex)

    # synchronize with model if necessary
    if ITask.providedBy(context):
        sync_task(context, event)
Пример #15
0
def save_reference_number_prefix(obj, event):
    if IObjectRemovedEvent.providedBy(event):
        return

    parent = aq_parent(aq_inner(obj))
    prefix_adapter = IReferenceNumberPrefix(parent)
    if not prefix_adapter.get_number(obj):
        prefix_adapter.set_number(obj)

    # because we can't control the order of event handlers we have to sync
    # all containing tasks manually
    catalog = api.portal.get_tool("portal_catalog")
    tasks = catalog(
        {"path": "/".join(obj.getPhysicalPath()), "object_provides": "opengever.task.task.ITask", "depth": -1}
    )
    for task in tasks:
        TaskSqlSyncer(task.getObject(), None).sync()

    obj.reindexObject(idxs=["reference"])
Пример #16
0
def object_moved_or_added(context, event):
    if IObjectRemovedEvent.providedBy(event):
        return

    # Update object security after moving or copying.
    # Specifically, this is needed for the case where an object is moved out
    # of a location where a Placeful Workflow Policy applies to a location
    # where it doesn't.
    #
    #  Plone then no longer provides the placeful workflow for that object,
    # but doesn't automatically update the object's security.
    #
    # We use ftw.upgrade's update_security_for() here to correctly
    # recalculate security, but do the reindexing ourselves because otherwise
    # Plone will do it recursively (unnecessarily so).
    changed = update_security_for(context, reindex_security=False)
    if changed:
        catalog = api.portal.get_tool('portal_catalog')
        catalog.reindexObject(context,
                              idxs=CatalogAware._cmf_security_indexes,
                              update_metadata=0)