Ejemplo n.º 1
0
 def test_create_root_with_initial_content(self, registry):
     from adhocracy_core.resources.root import IRootPool
     from adhocracy_core.utils import find_graph
     from substanced.util import find_objectmap
     from substanced.util import find_catalog
     from substanced.util import find_service
     inst = registry.content.create(IRootPool.__identifier__)
     assert IRootPool.providedBy(inst)
     assert find_objectmap(inst) is not None
     assert find_graph(inst) is not None
     assert find_graph(inst)._objectmap is not None
     assert find_catalog(inst, 'system') is not None
     assert find_catalog(inst, 'adhocracy') is not None
     assert find_service(inst, 'principals', 'users') is not None
     assert find_service(inst, 'locations') is not None
Ejemplo n.º 2
0
 def test_create_root_with_initial_content(self, registry):
     from adhocracy_core.resources.root import IRootPool
     from adhocracy_core.utils import find_graph
     from substanced.util import find_objectmap
     from substanced.util import find_catalog
     from substanced.util import find_service
     inst = registry.content.create(IRootPool.__identifier__)
     assert IRootPool.providedBy(inst)
     assert find_objectmap(inst) is not None
     assert find_graph(inst) is not None
     assert find_graph(inst)._objectmap is not None
     assert find_catalog(inst, 'system') is not None
     assert find_catalog(inst, 'adhocracy') is not None
     assert find_service(inst, 'principals', 'users') is not None
     assert find_service(inst, 'locations') is not None
Ejemplo n.º 3
0
def _mark_referenced_resources_as_changed(resource: IResource, registry: Registry):
    graph = find_graph(resource)
    resource_and_descendants = list_resource_with_descendants(resource)
    for res in resource_and_descendants:
        references = graph.get_references(res)
        for ref in references:
            _add_changelog_backrefs_for_resource(ref.target, registry)
Ejemplo n.º 4
0
def change_bplan_officeworker_email_representation(root, registry):
    """Change bplan officeworker email representation."""
    from substanced.util import find_objectmap
    from adhocracy_core.utils import find_graph
    from adhocracy_meinberlin.resources.bplan import IProcess
    from adhocracy_meinberlin.sheets.bplan import IProcessSettings
    from adhocracy_meinberlin.sheets.bplan import IProcessPrivateSettings
    from adhocracy_meinberlin.sheets.bplan import OfficeWorkerUserReference
    migrate_new_sheet(root, IProcess, IProcessPrivateSettings)
    catalogs = find_service(root, 'catalogs')
    bplaene = _search_for_interfaces(catalogs, IProcess)
    objectmap = find_objectmap(root)
    graph = find_graph(root)
    for bplan in bplaene:
        process_settings_ref = graph.get_references_for_isheet(
            bplan,
            IProcessSettings)
        if 'office_worker' in process_settings_ref:
            office_worker = process_settings_ref['office_worker'][0]
            private_settings = registry.content.get_sheet(
                bplan,
                IProcessPrivateSettings)
            private_settings.set({'office_worker_email': office_worker.email})
            objectmap.disconnect(bplan, office_worker,
                                 OfficeWorkerUserReference)
Ejemplo n.º 5
0
def _mark_referenced_resources_as_changed(resource: IResource,
                                          registry: Registry):
    graph = find_graph(resource)
    resource_and_descendants = list_resource_with_descendants(resource)
    for res in resource_and_descendants:
        references = graph.get_references(res)
        for ref in references:
            _add_changelog_backrefs_for_resource(ref.target, registry)
Ejemplo n.º 6
0
def filter_by_tag(resources: list, tag_name: str) -> list:
    """Filter a list of resources by returning only those with a given tag."""
    result = []
    if not resources:
        return result
    graph = find_graph(resources[0])
    for resource in resources:
        tags = graph.get_back_reference_sources(resource, TagElementsReference)
        for tag in tags:
            if tag.__name__ == tag_name:
                result.append(resource)
                break
    return result
Ejemplo n.º 7
0
def filter_by_tag(resources: list, tag_name: str) -> list:
    """Filter a list of resources by returning only those with a given tag."""
    result = []
    if not resources:
        return result
    graph = find_graph(resources[0])
    for resource in resources:
        tags = graph.get_back_reference_sources(resource, TagElementsReference)
        for tag in tags:
            if tag.__name__ == tag_name:
                result.append(resource)
                break
    return result
Ejemplo n.º 8
0
    def remove(self, name, send_events: bool=True, registry: Registry=None,
               **kwargs):
        """Delete subresource `name` from database.

        :raises KeyError: if `name` is not a valid subresource name
        """
        subresource = self[name]
        registry = registry or get_current_registry(self)
        if send_events:  # pragma: no branch
            event = ResourceWillBeDeleted(object=subresource,
                                          parent=self,
                                          registry=registry)
            registry.notify(event)
        graph = find_graph(subresource)
        references = graph.get_refernces_for_removal_notificaton(subresource)
        res = super().remove(name,
                             registry=registry,
                             send_events=send_events,
                             **kwargs)
        graph.send_back_reference_removal_notificatons(references, registry)
        return res
Ejemplo n.º 9
0
def _notify_referencing_resources_about_new_version(old_version,
                                                    new_version,
                                                    root_versions,
                                                    registry,
                                                    creator,
                                                    is_batchmode,
                                                    ):
    graph = find_graph(old_version)
    references = graph.get_back_references(old_version,
                                           base_reftype=SheetToSheet)
    for source, isheet, isheet_field, target in references:
        event = SheetReferenceNewVersion(source,
                                         isheet,
                                         isheet_field,
                                         old_version,
                                         new_version,
                                         registry,
                                         creator,
                                         root_versions=root_versions,
                                         is_batchmode=is_batchmode,
                                         )
        registry.notify(event)
Ejemplo n.º 10
0
def _notify_referencing_resources_about_new_version(old_version,
                                                    new_version,
                                                    root_versions,
                                                    registry,
                                                    creator,
                                                    is_batchmode,
                                                    ):
    graph = find_graph(old_version)
    references = graph.get_back_references(old_version,
                                           base_reftype=SheetToSheet)
    for source, isheet, isheet_field, target in references:
        event = SheetReferenceNewVersion(source,
                                         isheet,
                                         isheet_field,
                                         old_version,
                                         new_version,
                                         registry,
                                         creator,
                                         root_versions=root_versions,
                                         is_batchmode=is_batchmode,
                                         )
        registry.notify(event)
Ejemplo n.º 11
0
def change_bplan_officeworker_email_representation(root, registry):
    """Change bplan officeworker email representation."""
    from substanced.util import find_objectmap
    from adhocracy_core.utils import find_graph
    from adhocracy_meinberlin.resources.bplan import IProcess
    from adhocracy_meinberlin.sheets.bplan import IProcessSettings
    from adhocracy_meinberlin.sheets.bplan import IProcessPrivateSettings
    from adhocracy_meinberlin.sheets.bplan import OfficeWorkerUserReference
    migrate_new_sheet(root, IProcess, IProcessPrivateSettings)
    catalogs = find_service(root, 'catalogs')
    bplaene = _search_for_interfaces(catalogs, IProcess)
    objectmap = find_objectmap(root)
    graph = find_graph(root)
    for bplan in bplaene:
        process_settings_ref = graph.get_references_for_isheet(
            bplan, IProcessSettings)
        if 'office_worker' in process_settings_ref:
            office_worker = process_settings_ref['office_worker'][0]
            private_settings = registry.content.get_sheet(
                bplan, IProcessPrivateSettings)
            private_settings.set({'office_worker_email': office_worker.email})
            objectmap.disconnect(bplan, office_worker,
                                 OfficeWorkerUserReference)
Ejemplo n.º 12
0
    def remove(self,
               name,
               send_events: bool = True,
               registry: Registry = None,
               **kwargs):
        """Delete subresource `name` from database.

        :raises KeyError: if `name` is not a valid subresource name
        """
        subresource = self[name]
        registry = registry or get_current_registry(self)
        if send_events:  # pragma: no branch
            event = ResourceWillBeDeleted(object=subresource,
                                          parent=self,
                                          registry=registry)
            registry.notify(event)
        graph = find_graph(subresource)
        references = graph.get_refernces_for_removal_notificaton(subresource)
        res = super().remove(name,
                             registry=registry,
                             send_events=send_events,
                             **kwargs)
        graph.send_back_reference_removal_notificatons(references, registry)
        return res
Ejemplo n.º 13
0
def index_tag(resource, default) -> [str]:
    """Return value for the tag index."""
    graph = find_graph(resource)
    tags = graph.get_back_reference_sources(resource, TagElementsReference)
    tagnames = [tag.__name__ for tag in tags]
    return tagnames if tagnames else default
Ejemplo n.º 14
0
def test_find_graph_graph_does_not_exists():
    from adhocracy_core.utils import find_graph
    child = testing.DummyResource()
    assert find_graph(child) is None
Ejemplo n.º 15
0
 def _graph(self):
     return find_graph(self)
Ejemplo n.º 16
0
def index_tag(resource, default) -> [str]:
    """Return value for the tag index."""
    graph = find_graph(resource)
    tags = graph.get_back_reference_sources(resource, TagElementsReference)
    tagnames = [tag.__name__ for tag in tags]
    return tagnames if tagnames else default
Ejemplo n.º 17
0
 def _graph(self):
     graph = find_graph(self.context)
     return graph
Ejemplo n.º 18
0
def test_find_graph_graph_exists():
    from adhocracy_core.utils import find_graph
    dummy_graph = object()
    parent = testing.DummyResource(__graph__=dummy_graph)
    child = testing.DummyResource(__parent__=parent)
    assert find_graph(child) is dummy_graph
Ejemplo n.º 19
0
def _is_in_root_version_subtree(event: ISheetReferenceNewVersion) -> bool:
    if event.root_versions == []:
        return True
    graph = find_graph(event.object)
    return graph.is_in_subtree(event.object, event.root_versions)
Ejemplo n.º 20
0
def test_find_graph_graph_exists():
    from adhocracy_core.utils import find_graph
    dummy_graph = object()
    parent = testing.DummyResource(__graph__=dummy_graph)
    child = testing.DummyResource(__parent__=parent)
    assert find_graph(child) is dummy_graph
Ejemplo n.º 21
0
 def _graph(self):
     graph = find_graph(self.context)
     return graph
Ejemplo n.º 22
0
 def _graph(self):
     return find_graph(self)
Ejemplo n.º 23
0
def _is_in_root_version_subtree(event: ISheetReferenceNewVersion) -> bool:
    if event.root_versions == []:
        return True
    graph = find_graph(event.object)
    return graph.is_in_subtree(event.object, event.root_versions)
Ejemplo n.º 24
0
def test_find_graph_graph_does_not_exists():
    from adhocracy_core.utils import find_graph
    child = testing.DummyResource()
    assert find_graph(child) is None