# Path: cavedb/middleware.py
# def get_current_user():
#     return getattr(THREAD_LOCALS, 'user', None)


from django.contrib.auth.models import AnonymousUser
from cavedb.middleware import get_current_user
# SPDX-License-Identifier: Apache-2.0


def is_bulletin_generation_allowed(bulletin_id):
    if isinstance(get_current_user(), AnonymousUser):
        return False

    profile = get_current_user().caveuserprofile
    return profile.can_generate_docs and \
               profile.bulletins.get_queryset().filter(id=bulletin_id).count() > 0


def is_global_generation_allowed():
    if isinstance(get_current_user(), AnonymousUser):
        return False


# Path: cavedb/middleware.py
# def get_current_user():
#     return getattr(THREAD_LOCALS, 'user', None)


# Path: cavedb/perms.py
from django.contrib.auth.models import AnonymousUser
from cavedb.middleware import get_current_user

# SPDX-License-Identifier: Apache-2.0


def is_bulletin_generation_allowed(bulletin_id):
    if isinstance(get_current_user(), AnonymousUser):
        return False

    profile = get_current_user().caveuserprofile
    return profile.can_generate_docs and \
               profile.bulletins.get_queryset().filter(id=bulletin_id).count() > 0


def is_global_generation_allowed():
    if isinstance(get_current_user(), AnonymousUser):
        return False


    profile = get_current_user().caveuserprofile