# Path: invenio_communities/communities/services/permissions.py
# class IfRestrictedBase(Generator):
# class IfRestricted(IfRestrictedBase):
# class IfPolicyClosed(IfRestrictedBase):
# class CommunityOwners(Generator):
# class CommunityPermissionPolicy(BasePermissionPolicy):
#     def __init__(self, field_getter,
#                  field_name, then_value, else_value, then_, else_):
#     def generators(self, record):
#     def needs(self, record=None, **kwargs):
#     def excludes(self, record=None, **kwargs):
#     def make_query(self, generators, **kwargs):
#     def query_filter(self, **kwargs):
#     def __init__(self, field, then_, else_):
#     def __init__(self, field, then_, else_):
#     def needs(self, record=None, **kwargs):
#     def query_filter(self, identity=None, **kwargs):


from elasticsearch_dsl import Q
from invenio_cache import current_cache
from invenio_records_resources.services.errors import PermissionDeniedError
from .communities.services.permissions import CommunityNeed
        return

    # Cache keys
    #
    # The cache of communities must be invalidated on:
    # 1) on creation of a community (likely this one is modelled via membership
    #    in the future).
    # 2) add/remove/change of membership
    #
    # We construct the cache key for each membership entity (e.g. user,
    # role, system role). This way, once a membership is added/removed/updated
    # we can cache the list of associated communities for this entity.
    # Once a user logs in, we get the cache for each of the membership
    # entities and combine it into a single list.

    # Currently, only users are supported (no roles or system roles)
    cache_key = identity_cache_key(identity)
    communities = current_cache.get(cache_key)
    if communities is None:
        try:
            communities = []
            for c in search_communities(service, identity):
                communities.append(str(c.uuid))
            current_cache.set(cache_key, communities, timeout=24*3600)
        except PermissionDeniedError:
            communities = []


    # Add community needs to identity
    for c_id in communities:

# Path: invenio_communities/communities/services/permissions.py
# class IfRestrictedBase(Generator):
# class IfRestricted(IfRestrictedBase):
# class IfPolicyClosed(IfRestrictedBase):
# class CommunityOwners(Generator):
# class CommunityPermissionPolicy(BasePermissionPolicy):
#     def __init__(self, field_getter,
#                  field_name, then_value, else_value, then_, else_):
#     def generators(self, record):
#     def needs(self, record=None, **kwargs):
#     def excludes(self, record=None, **kwargs):
#     def make_query(self, generators, **kwargs):
#     def query_filter(self, **kwargs):
#     def __init__(self, field, then_, else_):
#     def __init__(self, field, then_, else_):
#     def needs(self, record=None, **kwargs):
#     def query_filter(self, identity=None, **kwargs):


# Path: invenio_communities/utils.py
from elasticsearch_dsl import Q
from invenio_cache import current_cache
from invenio_records_resources.services.errors import PermissionDeniedError
from .communities.services.permissions import CommunityNeed

        return

    # Cache keys
    #
    # The cache of communities must be invalidated on:
    # 1) on creation of a community (likely this one is modelled via membership
    #    in the future).
    # 2) add/remove/change of membership
    #
    # We construct the cache key for each membership entity (e.g. user,
    # role, system role). This way, once a membership is added/removed/updated
    # we can cache the list of associated communities for this entity.
    # Once a user logs in, we get the cache for each of the membership
    # entities and combine it into a single list.

    # Currently, only users are supported (no roles or system roles)
    cache_key = identity_cache_key(identity)
    communities = current_cache.get(cache_key)
    if communities is None:
        try:
            communities = []
            for c in search_communities(service, identity):
                communities.append(str(c.uuid))
            current_cache.set(cache_key, communities, timeout=24*3600)
        except PermissionDeniedError:
            communities = []


    # Add community needs to identity
    for c_id in communities:

        identity.provides.add(CommunityNeed(c_id))