<commit_before>from django.dispatch import receiver
from django.db.models.signals import post_delete, post_save
from ipynbsrv.contract.backends import GroupBackend
from ipynbsrv.contract.errors import GroupBackendError, GroupNotFoundError
from ipynbsrv.core.helpers import get_internal_ldap_connected
from ipynbsrv.core.models import BackendGroup
from ipynbsrv.core.signals.signals import backend_group_created, \
    backend_group_deleted, backend_group_member_added, \
    backend_group_member_removed, backend_group_modified


@receiver(backend_group_member_added)
def add_member_to_internal_ldap_group(sender, group, user, **kwargs):
    """
    When ever a member is added to a group we need to sync the LDAP group.
    """
    if group is not None and user is not None:
        try:
            internal_ldap = get_internal_ldap_connected()
            internal_ldap.add_group_member(group.backend_pk, user.backend_pk)
        finally:
            try:
                internal_ldap.disconnect()
            except:
                pass


@receiver(backend_group_member_removed)
def remove_member_from_internal_ldap_group(sender, group, user, **kwargs):
    """
    When ever a member is removed to a group we need to sync the LDAP group.
    """
    if group is not None and user is not None:
        try:
            internal_ldap = get_internal_ldap_connected()
            internal_ldap.remove_group_member(group.backend_pk, user.backend_pk)
        finally:
            try:
                internal_ldap.disconnect()
            except:
                pass


@receiver(backend_group_created)
def create_on_internal_ldap(sender, group, **kwargs):
    """
    BackendGroup instances are used to represent external backends (e.g. LDAP) groups.

    If such a group is created, we should therefor create the group on the backend.
    """
    if group is not None:
        try:
            internal_ldap = get_internal_ldap_connected()
            created = internal_ldap.create_group(group.backend_id, group.backend_pk)<commit_msg>fix some grammar mistakes<commit_after>from django.dispatch import receiver
from django.db.models.signals import post_delete, post_save
from ipynbsrv.contract.backends import GroupBackend
from ipynbsrv.contract.errors import GroupBackendError, GroupNotFoundError
from ipynbsrv.core.helpers import get_internal_ldap_connected
from ipynbsrv.core.models import BackendGroup
from ipynbsrv.core.signals.signals import backend_group_created, \
    backend_group_deleted, backend_group_member_added, \
    backend_group_member_removed, backend_group_modified


@receiver(backend_group_member_added)
def add_member_to_internal_ldap_group(sender, group, user, **kwargs):
    """
    Whenever a member is added to a group we need to sync the LDAP group.
    """
    if group is not None and user is not None:
        try:
            internal_ldap = get_internal_ldap_connected()
            internal_ldap.add_group_member(group.backend_pk, user.backend_pk)
        finally:
            try:
                internal_ldap.disconnect()
            except:
                pass


@receiver(backend_group_member_removed)
def remove_member_from_internal_ldap_group(sender, group, user, **kwargs):
    """
    Whenever a member is removed from a group we need to sync the LDAP group.
    """
    if group is not None and user is not None:
        try:
            internal_ldap = get_internal_ldap_connected()
            internal_ldap.remove_group_member(group.backend_pk, user.backend_pk)
        finally:
            try:
                internal_ldap.disconnect()
            except:
                pass


@receiver(backend_group_created)
def create_on_internal_ldap(sender, group, **kwargs):
    """
    BackendGroup instances are used to represent external backends (e.g. LDAP) groups.

    If such a group is created, we should therefor create the group on the backend.
    """
    if group is not None:
        try:
            internal_ldap = get_internal_ldap_connected()
            created = internal_ldap.create_group(group.backend_id, group.backend_pk)
{'fraction_non_alphanumeric': 0.06402737047898338, 'fraction_numerical': 0.0, 'mean_word_length': 3.1177062374245472, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2964232', 'n_tokens_mistral': 1173, 'n_tokens_neox': 1170, 'n_words': 320}