prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  RestrictedMail notification
  > Restricted mail is used when sending mails to multiple users at once by selecting users/events/meetings, and then send the email to <restricted@abkaus.no> together with the token.
  
  The `restricted mail sent` should be sent to the proper email, not the `user.email` field. The address `user.email_address` should be used instead.
  
  If the `from_address` is not the same as the `user.email_address`, both should receive the mail.
  
  https://github.com/webkom/lego/blob/ccab14fbee223f16842ace6ca2ba0c2f3ac3ac86/lego/apps/restricted/notifications.py#L9
  
  </issue>
  <code>
  [start of lego/apps/restricted/serializers.py]
  1 from lego.apps.events.fields import PublicEventListField
  2 from lego.apps.meetings.fields import MeetingListField
  3 from lego.apps.restricted.models import RestrictedMail
  4 from lego.apps.users.fields import AbakusGroupListField, PublicUserListField
  5 from lego.utils.serializers import BasisModelSerializer
  6 
  7 
  8 class RestrictedMailListSerializer(BasisModelSerializer):
  9     class Meta:
  10         model = RestrictedMail
  11         fields = ("id", "from_address", "hide_sender", "used", "created_at", "weekly")
  12         read_only_fields = ("used", "created_at")
  13 
  14     def save(self, **kwargs):
  15         kwargs["token"] = RestrictedMail.create_token()
  16         return super().save(**kwargs)
  17 
  18 
  19 class RestrictedMailSerializer(RestrictedMailListSerializer):
  20     class Meta(RestrictedMailListSerializer.Meta):
  21         fields = RestrictedMailListSerializer.Meta.fields + (
  22             "users",
  23             "groups",
  24             "events",
  25             "meetings",
  26             "raw_addresses",
  27             "weekly",
  28             "hide_sender",
  29         )
  30 
  31 
  32 class RestrictedMailDetailSerializer(RestrictedMailSerializer):
  33     users = PublicUserListField({"read_only": True})
  34     groups = AbakusGroupListField({"read_only": True})
  35     events = PublicEventListField({"read_only": True})
  36     meetings = MeetingListField({"read_only": True})
  37 
  38     class Meta(RestrictedMailSerializer.Meta):
  39         fields = RestrictedMailSerializer.Meta.fields + ("token_query_param",)
  40
  [end of lego/apps/restricted/serializers.py]
  [start of lego/apps/restricted/notifications.py]
  1 from lego.apps.notifications.constants import RESTRICTED_MAIL_SENT
  2 from lego.apps.notifications.notification import Notification
  3 
  4 
  5 class RestrictedMailSentNotification(Notification):
  6 
  7     name = RESTRICTED_MAIL_SENT
  8 
  9     def generate_mail(self):
  10         return self._delay_mail(
  11             to_email=self.user.email,
  12             context={"first_name": self.user.first_name},
  13             subject="Begrenset epost sendt ut",
  14             plain_template="restricted/email/process_success.txt",
  15             html_template="restricted/email/process_success.html",
  16         )
  17
  [end of lego/apps/restricted/notifications.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/lego/apps/restricted/notifications.py b/lego/apps/restricted/notifications.py
  --- a/lego/apps/restricted/notifications.py
  +++ b/lego/apps/restricted/notifications.py
  @@ -8,7 +8,7 @@
   
       def generate_mail(self):
           return self._delay_mail(
  -            to_email=self.user.email,
  +            to_email=self.user.email.address,
               context={"first_name": self.user.first_name},
               subject="Begrenset epost sendt ut",
               plain_template="restricted/email/process_success.txt",
  diff --git a/lego/apps/restricted/serializers.py b/lego/apps/restricted/serializers.py
  --- a/lego/apps/restricted/serializers.py
  +++ b/lego/apps/restricted/serializers.py
  @@ -1,3 +1,7 @@
  +from functools import reduce
  +
  +from rest_framework import exceptions
  +
   from lego.apps.events.fields import PublicEventListField
   from lego.apps.meetings.fields import MeetingListField
   from lego.apps.restricted.models import RestrictedMail
  @@ -28,6 +32,18 @@
               "hide_sender",
           )
   
  +    def create(self, validated_data):
  +        groups = validated_data["groups"]
  +        events = validated_data["events"]
  +        MaxPermittedAmout = 500
  +        num = reduce((lambda a, b: a + b.number_of_users), groups, 0)
  +        num += reduce((lambda a, b: a + b.registration_count), events, 0)
  +        if num > MaxPermittedAmout:
  +            raise exceptions.ValidationError(
  +                f"The number of students in selected groups/events exceed the permitted amount which is {MaxPermittedAmout}"
  +            )
  +        return super().create(validated_data)
  +
   
   class RestrictedMailDetailSerializer(RestrictedMailSerializer):
       users = PublicUserListField({"read_only": True})
  
verification_info: {"golden_diff": "diff --git a/lego/apps/restricted/notifications.py b/lego/apps/restricted/notifications.py\n--- a/lego/apps/restricted/notifications.py\n+++ b/lego/apps/restricted/notifications.py\n@@ -8,7 +8,7 @@\n \n     def generate_mail(self):\n         return self._delay_mail(\n-            to_email=self.user.email,\n+            to_email=self.user.email.address,\n             context={\"first_name\": self.user.first_name},\n             subject=\"Begrenset epost sendt ut\",\n             plain_template=\"restricted/email/process_success.txt\",\ndiff --git a/lego/apps/restricted/serializers.py b/lego/apps/restricted/serializers.py\n--- a/lego/apps/restricted/serializers.py\n+++ b/lego/apps/restricted/serializers.py\n@@ -1,3 +1,7 @@\n+from functools import reduce\n+\n+from rest_framework import exceptions\n+\n from lego.apps.events.fields import PublicEventListField\n from lego.apps.meetings.fields import MeetingListField\n from lego.apps.restricted.models import RestrictedMail\n@@ -28,6 +32,18 @@\n             \"hide_sender\",\n         )\n \n+    def create(self, validated_data):\n+        groups = validated_data[\"groups\"]\n+        events = validated_data[\"events\"]\n+        MaxPermittedAmout = 500\n+        num = reduce((lambda a, b: a + b.number_of_users), groups, 0)\n+        num += reduce((lambda a, b: a + b.registration_count), events, 0)\n+        if num > MaxPermittedAmout:\n+            raise exceptions.ValidationError(\n+                f\"The number of students in selected groups/events exceed the permitted amount which is {MaxPermittedAmout}\"\n+            )\n+        return super().create(validated_data)\n+\n \n class RestrictedMailDetailSerializer(RestrictedMailSerializer):\n     users = PublicUserListField({\"read_only\": True})\n", "issue": "RestrictedMail notification\n> Restricted mail is used when sending mails to multiple users at once by selecting users/events/meetings, and then send the email to <restricted@abkaus.no> together with the token.\r\n\r\nThe `restricted mail sent` should be sent to the proper email, not the `user.email` field. The address `user.email_address` should be used instead.\r\n\r\nIf the `from_address` is not the same as the `user.email_address`, both should receive the mail.\r\n\r\nhttps://github.com/webkom/lego/blob/ccab14fbee223f16842ace6ca2ba0c2f3ac3ac86/lego/apps/restricted/notifications.py#L9\n", "before_files": [{"content": "from lego.apps.events.fields import PublicEventListField\nfrom lego.apps.meetings.fields import MeetingListField\nfrom lego.apps.restricted.models import RestrictedMail\nfrom lego.apps.users.fields import AbakusGroupListField, PublicUserListField\nfrom lego.utils.serializers import BasisModelSerializer\n\n\nclass RestrictedMailListSerializer(BasisModelSerializer):\n    class Meta:\n        model = RestrictedMail\n        fields = (\"id\", \"from_address\", \"hide_sender\", \"used\", \"created_at\", \"weekly\")\n        read_only_fields = (\"used\", \"created_at\")\n\n    def save(self, **kwargs):\n        kwargs[\"token\"] = RestrictedMail.create_token()\n        return super().save(**kwargs)\n\n\nclass RestrictedMailSerializer(RestrictedMailListSerializer):\n    class Meta(RestrictedMailListSerializer.Meta):\n        fields = RestrictedMailListSerializer.Meta.fields + (\n            \"users\",\n            \"groups\",\n            \"events\",\n            \"meetings\",\n            \"raw_addresses\",\n            \"weekly\",\n            \"hide_sender\",\n        )\n\n\nclass RestrictedMailDetailSerializer(RestrictedMailSerializer):\n    users = PublicUserListField({\"read_only\": True})\n    groups = AbakusGroupListField({\"read_only\": True})\n    events = PublicEventListField({\"read_only\": True})\n    meetings = MeetingListField({\"read_only\": True})\n\n    class Meta(RestrictedMailSerializer.Meta):\n        fields = RestrictedMailSerializer.Meta.fields + (\"token_query_param\",)\n", "path": "lego/apps/restricted/serializers.py"}, {"content": "from lego.apps.notifications.constants import RESTRICTED_MAIL_SENT\nfrom lego.apps.notifications.notification import Notification\n\n\nclass RestrictedMailSentNotification(Notification):\n\n    name = RESTRICTED_MAIL_SENT\n\n    def generate_mail(self):\n        return self._delay_mail(\n            to_email=self.user.email,\n            context={\"first_name\": self.user.first_name},\n            subject=\"Begrenset epost sendt ut\",\n            plain_template=\"restricted/email/process_success.txt\",\n            html_template=\"restricted/email/process_success.html\",\n        )\n", "path": "lego/apps/restricted/notifications.py"}]}