prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Group Sync when changing a User
  Currently the group syncer is only run when a group is updated (saved). If a user is added to (or removed from) a group, the syncer won't run. 
  
  Fix:
  Connect to the signal sent by User.groups m2m-relation when a user is saved, like described here: https://docs.djangoproject.com/en/dev/ref/signals/#m2m-changed
  
  This is to be done in `apps/authentication/signals.py`.
  
  
  </issue>
  <code>
  [start of apps/authentication/signals.py]
  1 # -*- coding: utf-8 -*-
  2 from django.contrib.auth.models import Group
  3 from django.db.models.signals import post_save
  4 from django.dispatch import receiver
  5 
  6 from apps.authentication.tasks import SynchronizeGroups
  7 
  8 
  9 @receiver(post_save, sender=Group)
  10 def trigger_group_syncer(sender, instance, created, **kwargs):
  11     """
  12     :param sender: The model that triggered this hook
  13     :param instance: The model instance triggering this hook
  14     :param created: True if the instance was created, False if the instance was updated
  15 
  16     Calls the SynchronizeGroups Task if a group is updated. (Not if it's the initial creation of a group)
  17     """
  18 
  19     if created:
  20         # If a new instance is created, we do not need to trigger group sync.
  21         pass
  22     else:
  23         SynchronizeGroups.run()
  24
  [end of apps/authentication/signals.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/apps/authentication/signals.py b/apps/authentication/signals.py
  --- a/apps/authentication/signals.py
  +++ b/apps/authentication/signals.py
  @@ -1,13 +1,17 @@
   # -*- coding: utf-8 -*-
  +from django.contrib.auth import get_user_model
   from django.contrib.auth.models import Group
  -from django.db.models.signals import post_save
  +from django.db.models.signals import m2m_changed, post_save
   from django.dispatch import receiver
   
   from apps.authentication.tasks import SynchronizeGroups
   
   
  +User = get_user_model()
  +
  +
   @receiver(post_save, sender=Group)
  -def trigger_group_syncer(sender, instance, created, **kwargs):
  +def trigger_group_syncer(sender, instance, created=False, **kwargs):
       """
       :param sender: The model that triggered this hook
       :param instance: The model instance triggering this hook
  @@ -21,3 +25,5 @@
           pass
       else:
           SynchronizeGroups.run()
  +
  +m2m_changed.connect(trigger_group_syncer, sender=User.groups.through)
  
verification_info: {"golden_diff": "diff --git a/apps/authentication/signals.py b/apps/authentication/signals.py\n--- a/apps/authentication/signals.py\n+++ b/apps/authentication/signals.py\n@@ -1,13 +1,17 @@\n # -*- coding: utf-8 -*-\n+from django.contrib.auth import get_user_model\n from django.contrib.auth.models import Group\n-from django.db.models.signals import post_save\n+from django.db.models.signals import m2m_changed, post_save\n from django.dispatch import receiver\n \n from apps.authentication.tasks import SynchronizeGroups\n \n \n+User = get_user_model()\n+\n+\n @receiver(post_save, sender=Group)\n-def trigger_group_syncer(sender, instance, created, **kwargs):\n+def trigger_group_syncer(sender, instance, created=False, **kwargs):\n     \"\"\"\n     :param sender: The model that triggered this hook\n     :param instance: The model instance triggering this hook\n@@ -21,3 +25,5 @@\n         pass\n     else:\n         SynchronizeGroups.run()\n+\n+m2m_changed.connect(trigger_group_syncer, sender=User.groups.through)\n", "issue": "Group Sync when changing a User\nCurrently the group syncer is only run when a group is updated (saved). If a user is added to (or removed from) a group, the syncer won't run. \n\nFix:\nConnect to the signal sent by User.groups m2m-relation when a user is saved, like described here: https://docs.djangoproject.com/en/dev/ref/signals/#m2m-changed\n\nThis is to be done in `apps/authentication/signals.py`.\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\nfrom django.contrib.auth.models import Group\nfrom django.db.models.signals import post_save\nfrom django.dispatch import receiver\n\nfrom apps.authentication.tasks import SynchronizeGroups\n\n\n@receiver(post_save, sender=Group)\ndef trigger_group_syncer(sender, instance, created, **kwargs):\n    \"\"\"\n    :param sender: The model that triggered this hook\n    :param instance: The model instance triggering this hook\n    :param created: True if the instance was created, False if the instance was updated\n\n    Calls the SynchronizeGroups Task if a group is updated. (Not if it's the initial creation of a group)\n    \"\"\"\n\n    if created:\n        # If a new instance is created, we do not need to trigger group sync.\n        pass\n    else:\n        SynchronizeGroups.run()\n", "path": "apps/authentication/signals.py"}]}