anchor.diff:      #{
           od_group => Groups, od_space => Spaces,
           od_handle_service => HServices, od_handle => Handles
  -    }.
  -
  -parents_to_aggregate_from(od_user) ->
  -    [od_space, od_group].
  -
  -
  -aggregate_from_parent(od_user, od_space, SpaceId) ->
  -    {ok, #document{value = #od_space{
  -        providers_supports = Providers,
  -        shares = Shares
  -    }}} = od_space:get(SpaceId),
  -    #{od_provider => element(1, Providers), od_share => Shares};
  -aggregate_from_parent(od_user, od_group, GroupId) ->
  -    {ok, #document{value = #od_group{
  +    };
  +extract_neighbours(top_down, #od_group{} = Group) ->
  +    #od_group{
  +        parents = Groups, spaces = Spaces,
  +        handle_services = HServices, handles = Handles
  +    } = Group,
  +    #{
  +        od_group => Groups, od_space => Spaces,
  +        od_handle_service => HServices, od_handle => Handles
  +    };
  +extract_neighbours(top_down, #od_space{}) ->
  +    #{}.
  +
  +
  +neighbours_with_eff_relations(bottom_up, od_group) ->
  +    [od_group];
  +neighbours_with_eff_relations(bottom_up, od_space) ->
  +    [od_group];
  +neighbours_with_eff_relations(bottom_up, od_share) ->
  +    [od_space];
  +neighbours_with_eff_relations(bottom_up, od_provider) ->
  +    [od_space];
  +neighbours_with_eff_relations(bottom_up, od_handle_service) ->
  +    [od_group];
  +neighbours_with_eff_relations(bottom_up, od_handle) ->
  +    [od_group];
  +
  +neighbours_with_eff_relations(top_down, od_user) ->
  +    [od_group, od_space];
  +neighbours_with_eff_relations(top_down, od_group) ->
  +    [od_group, od_space];
  +neighbours_with_eff_relations(top_down, od_space) ->
  +    [].
  +
  +
  +
  +eff_relations_of_neighbour(bottom_up, od_group, #od_group{} = Group, Privs) ->
  +    #od_group{eff_users = EffUsers, eff_children = EffGroups} = Group,
  +    #{
  +        od_user => override_privileges(EffUsers, Privs),
  +        od_group => override_privileges(EffGroups, Privs)
  +    };
  +eff_relations_of_neighbour(bottom_up, od_space, #od_group{} = Group, Privs) ->
  +    #od_group{eff_users = EffUsers, eff_children = EffGroups} = Group,
  +    #{
  +        od_user => override_privileges(EffUsers, Privs),
  +        od_group => override_privileges(EffGroups, Privs)
  +    };
  +eff_relations_of_neighbour(bottom_up, od_share, #od_space{} = Space, _) ->
  +    #od_space{eff_users = EffUsers, eff_groups = EffGroups} = Space,
  +    #{od_user => EffUsers, od_group => EffGroups};
  +eff_relations_of_neighbour(bottom_up, od_provider, #od_space{} = Space, _) ->
  +    #od_space{eff_users = EffUsers, eff_groups = EffGroups} = Space,
  +    #{od_user => EffUsers, od_group => EffGroups};
  +eff_relations_of_neighbour(bottom_up, od_handle_service, #od_group{} = Group, Privs) ->
  +    #od_group{eff_users = EffUsers, eff_children = EffGroups} = Group,
  +    #{
  +        od_user => override_privileges(EffUsers, Privs),
  +        od_group => override_privileges(EffGroups, Privs)
  +    };
  +eff_relations_of_neighbour(bottom_up, od_handle, #od_group{} = Group, Privs) ->
  +    #od_group{eff_users = EffUsers, eff_children = EffGroups} = Group,
  +    #{
  +        od_user => override_privileges(EffUsers, Privs),
  +        od_group => override_privileges(EffGroups, Privs)
  +    };
  +
  +eff_relations_of_neighbour(top_down, od_user, #od_group{} = Group, _) ->
  +    #od_group{
           eff_parents = EffGroups,
           eff_spaces = EffSpaces,
           eff_shares = EffShares,
           eff_providers = EffProviders,
           eff_handle_services = EffHServices,
           eff_handles = EffHandles
  -    }}} = od_group:get(GroupId),
  +    } = Group,
       #{
           od_group => EffGroups, od_space => EffSpaces,
           od_share => EffShares, od_provider => EffProviders,
           od_handle_service => EffHServices, od_handle => EffHandles
  -    }.
  -
  -
  -eff_relations(#od_user{} = User) ->
  +    };
  +eff_relations_of_neighbour(top_down, od_user, #od_space{} = Space, _) ->
  +    #od_space{providers_supports = Providers, shares = Shares} = Space,
  +    #{od_provider => element(1, Providers), od_share => Shares};
  +eff_relations_of_neighbour(top_down, od_group, #od_group{} = Group, _) ->
  +    #od_group{
  +        eff_parents = EffGroups,
  +        eff_spaces = EffSpaces,
  +        eff_shares = EffShares,
  +        eff_providers = EffProviders,
  +        eff_handle_services = EffHServices,
  +        eff_handles = EffHandles
  +    } = Group,
  +    #{
  +        od_group => EffGroups, od_space => EffSpaces,
  +        od_share => EffShares, od_provider => EffProviders,
  +        od_handle_service => EffHServices, od_handle => EffHandles
  +    };
  +eff_relations_of_neighbour(top_down, od_group, #od_space{} = Space, _) ->
  +    #od_space{providers_supports = Providers, shares = Shares} = Space,
  +    #{od_provider => element(1, lists:unzip(Providers)), od_share => Shares}.
  +
  +
  +eff_relations(bottom_up, #od_group{} = Group) ->
  +    #od_group{eff_users = EffUsers, eff_children = EffGroups} = Group,
  +    #{od_user => EffUsers, od_group => EffGroups};
  +eff_relations(bottom_up, #od_space{} = Space) ->
  +    #od_space{eff_users = EffUsers, eff_groups = EffGroups} = Space,
  +    #{od_user => EffUsers, od_group => EffGroups};
  +eff_relations(bottom_up, #od_share{} = Share) ->
  +    #od_share{eff_users = EffUsers, eff_groups = EffGroups} = Share,
  +    #{od_user => EffUsers, od_group => EffGroups};
  +eff_relations(bottom_up, #od_provider{} = Provider) ->
  +    #od_provider{eff_users = EffUsers, eff_groups = EffGroups} = Provider,
  +    #{od_user => EffUsers, od_group => EffGroups};
  +eff_relations(bottom_up, #od_handle_service{} = HService) ->
  +    #od_handle_service{eff_users = EffUsers, eff_groups = EffGroups} = HService,
  +    #{od_user => EffUsers, od_group => EffGroups};
  +eff_relations(bottom_up, #od_handle{} = Handle) ->
  +    #od_handle{eff_users = EffUsers, eff_groups = EffGroups} = Handle,
  +    #{od_user => EffUsers, od_group => EffGroups};
  +
  +eff_relations(top_down, #od_user{} = User) ->
       #od_user{
           eff_groups = EffGroups, eff_spaces = EffSpaces,
           eff_shares = EffShares, eff_providers = EffProviders,
  
positive.code: %%    end.
  
  
  did_relations_change(ProplistA, ProplistB) ->
      % to sa ordsets wiec dziala
      proplists:get_keys(ProplistA) =/= proplists:get_keys(ProplistB).
  
  
  override_privileges(PrivilegesProplist, NewPrivileges) ->
      lists:map(
          fun({Id, _}) ->
              {Id, NewPrivileges}
          end, PrivilegesProplist).
negative.code:             NewState = case {WhichWay, Flag} of
                  {bottom_up, true} ->
                      ?emergency("bottom-up dirty: ~p#~s", [Model, Id]),
                      EffGraphState#entity_graph_state{
                          bottom_up_dirty = lists:sort([{Priority, Model, Id} | BottomUpDirty])
                      };
                  {bottom_up, false} ->
                      ?emergency("bottom-up clean: ~s", [Id]),
                      EffGraphState#entity_graph_state{
                          bottom_up_dirty = lists:keydelete(Id, 3, BottomUpDirty)
                      };
                  {top_down, true} ->
                      ?emergency("top-down dirty: ~p#~s", [Model, Id]),
                      EffGraphState#entity_graph_state{
                          top_down_dirty = lists:sort([{Priority, Model, Id} | TopDownDirty])
                      };
                  {top_down, false} ->
                      ?emergency("top-down clean: ~s", [Id]),
                      EffGraphState#entity_graph_state{
                          top_down_dirty = lists:keydelete(Id, 3, TopDownDirty)
                      }
              end,
              {ok, NewState#entity_graph_state{dirty = true}}
          end),
      set_dirty_flag(WhichWay, Flag, Entity).
  
  