def set_local_roles(resource,
                    new_local_roles: dict,
                    registry: Registry = None):
    """Set the :term:`local role`s mapping to ``new_local_roles``.

    :param new_local_roles: Mapping from :term:`groupid`/:term:`userid` to
                            a set of :term:`role`s for the `resource`:

                            {'system.Everyone': {'role:reader'}}

    If the resource's `local roles` and the ``new_local_roles`` differ,
    set the ``new_local_roles`` via setattr and send a
    :class:`adhocracy_core.interfaces.ILocalRolesModified` to notify others.
    """
    _assert_values_have_set_type(new_local_roles)
    old_local_roles = getattr(resource, '__local_roles__', None)
    if new_local_roles == old_local_roles:
        return None
    else:
        resource.__local_roles__ = new_local_roles
    if registry is None:
        registry = get_current_registry()
    event = LocalRolesModified(resource, new_local_roles, old_local_roles,
                               registry)
    registry.notify(event)
Beispiel #2
0
 def send_back_reference_removal_notificatons(self, references: [Reference],
                                              registry: Registry):
     """Send SheetBackReferenceRemoved to reference targets."""
     for reference in references:
         event = SheetBackReferenceRemoved(reference.target,
                                           reference.isheet, reference,
                                           registry)
         registry.notify(event)
Beispiel #3
0
def _set_local_roles(resource, new_local_roles: dict, registry: Registry):
    old_local_roles = getattr(resource, '__local_roles__', None)
    if new_local_roles == old_local_roles:
        return
    else:
        resource.__local_roles__ = new_local_roles
    event = LocalRolesModified(resource, new_local_roles, old_local_roles,
                               registry)
    registry.notify(event)
Beispiel #4
0
 def send_back_reference_removal_notificatons(self,
                                              references: [Reference],
                                              registry: Registry):
     """Send SheetBackReferenceRemoved to reference targets."""
     for reference in references:
         event = SheetBackReferenceRemoved(reference.target,
                                           reference.isheet,
                                           reference,
                                           registry)
         registry.notify(event)
Beispiel #5
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
Beispiel #6
0
def set_local_roles(resource, new_local_roles: dict, registry: Registry=None):
    """Set the :term:`local role`s mapping to ``new_local_roles``.

    :param new_local_roles: Mapping from :term:`groupid`/:term:`userid` to
                            a set of :term:`role`s for the `resource`:

                            {'system.Everyone': {'role:reader'}}

    If the resource's `local roles` and the ``new_local_roles`` differ,
    set the ``new_local_roles`` via setattr and send a
    :class:`adhocracy_core.interfaces.ILocalRolesModified` to notify others.
    """
    _assert_values_have_set_type(new_local_roles)
    old_local_roles = getattr(resource, '__local_roles__', None)
    if new_local_roles == old_local_roles:
        return None
    else:
        resource.__local_roles__ = new_local_roles
    if registry is None:
        registry = get_current_registry()
    event = LocalRolesModified(resource, new_local_roles, old_local_roles,
                               registry)
    registry.notify(event)
Beispiel #7
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