We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Make muting work for deactivated users
Even after a user deactivated, it may be helpful to hide that user's messages, avatar, etc. We should therefore make it possible to mute deactivated users.

This will also fix a bug where if a user tries to mute a deactivated user, the action silently fails.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `zerver/views/muting.py`
Content:
```
1 import datetime
2 from typing import Optional
3 
4 from django.http import HttpRequest, HttpResponse
5 from django.utils.timezone import now as timezone_now
6 from django.utils.translation import gettext as _
7 
8 from zerver.lib.actions import do_mute_topic, do_mute_user, do_unmute_topic, do_unmute_user
9 from zerver.lib.exceptions import JsonableError
10 from zerver.lib.request import REQ, has_request_variables
11 from zerver.lib.response import json_success
12 from zerver.lib.streams import (
13     access_stream_by_id,
14     access_stream_by_name,
15     access_stream_for_unmute_topic_by_id,
16     access_stream_for_unmute_topic_by_name,
17     check_for_exactly_one_stream_arg,
18 )
19 from zerver.lib.topic_mutes import topic_is_muted
20 from zerver.lib.user_mutes import get_mute_object
21 from zerver.lib.users import access_user_by_id
22 from zerver.lib.validator import check_int
23 from zerver.models import UserProfile
24 
25 
26 def mute_topic(
27     user_profile: UserProfile,
28     stream_id: Optional[int],
29     stream_name: Optional[str],
30     topic_name: str,
31     date_muted: datetime.datetime,
32 ) -> HttpResponse:
33     if stream_name is not None:
34         (stream, sub) = access_stream_by_name(user_profile, stream_name)
35     else:
36         assert stream_id is not None
37         (stream, sub) = access_stream_by_id(user_profile, stream_id)
38 
39     if topic_is_muted(user_profile, stream.id, topic_name):
40         raise JsonableError(_("Topic already muted"))
41 
42     do_mute_topic(user_profile, stream, topic_name, date_muted)
43     return json_success()
44 
45 
46 def unmute_topic(
47     user_profile: UserProfile, stream_id: Optional[int], stream_name: Optional[str], topic_name: str
48 ) -> HttpResponse:
49     error = _("Topic is not muted")
50 
51     if stream_name is not None:
52         stream = access_stream_for_unmute_topic_by_name(user_profile, stream_name, error)
53     else:
54         assert stream_id is not None
55         stream = access_stream_for_unmute_topic_by_id(user_profile, stream_id, error)
56 
57     if not topic_is_muted(user_profile, stream.id, topic_name):
58         raise JsonableError(error)
59 
60     do_unmute_topic(user_profile, stream, topic_name)
61     return json_success()
62 
63 
64 @has_request_variables
65 def update_muted_topic(
66     request: HttpRequest,
67     user_profile: UserProfile,
68     stream_id: Optional[int] = REQ(json_validator=check_int, default=None),
69     stream: Optional[str] = REQ(default=None),
70     topic: str = REQ(),
71     op: str = REQ(),
72 ) -> HttpResponse:
73 
74     check_for_exactly_one_stream_arg(stream_id=stream_id, stream=stream)
75 
76     if op == "add":
77         return mute_topic(
78             user_profile=user_profile,
79             stream_id=stream_id,
80             stream_name=stream,
81             topic_name=topic,
82             date_muted=timezone_now(),
83         )
84     elif op == "remove":
85         return unmute_topic(
86             user_profile=user_profile,
87             stream_id=stream_id,
88             stream_name=stream,
89             topic_name=topic,
90         )
91 
92 
93 def mute_user(request: HttpRequest, user_profile: UserProfile, muted_user_id: int) -> HttpResponse:
94     if user_profile.id == muted_user_id:
95         raise JsonableError(_("Cannot mute self"))
96 
97     muted_user = access_user_by_id(user_profile, muted_user_id, allow_bots=False, for_admin=False)
98     date_muted = timezone_now()
99 
100     if get_mute_object(user_profile, muted_user) is not None:
101         raise JsonableError(_("User already muted"))
102 
103     do_mute_user(user_profile, muted_user, date_muted)
104     return json_success()
105 
106 
107 def unmute_user(
108     request: HttpRequest, user_profile: UserProfile, muted_user_id: int
109 ) -> HttpResponse:
110     muted_user = access_user_by_id(user_profile, muted_user_id, allow_bots=False, for_admin=False)
111     mute_object = get_mute_object(user_profile, muted_user)
112 
113     if mute_object is None:
114         raise JsonableError(_("User is not muted"))
115 
116     do_unmute_user(mute_object)
117     return json_success()
118
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/zerver/views/muting.py b/zerver/views/muting.py
--- a/zerver/views/muting.py
+++ b/zerver/views/muting.py
@@ -94,7 +94,9 @@
     if user_profile.id == muted_user_id:
         raise JsonableError(_("Cannot mute self"))
 
-    muted_user = access_user_by_id(user_profile, muted_user_id, allow_bots=False, for_admin=False)
+    muted_user = access_user_by_id(
+        user_profile, muted_user_id, allow_bots=False, allow_deactivated=True, for_admin=False
+    )
     date_muted = timezone_now()
 
     if get_mute_object(user_profile, muted_user) is not None:
@@ -107,7 +109,9 @@
 def unmute_user(
     request: HttpRequest, user_profile: UserProfile, muted_user_id: int
 ) -> HttpResponse:
-    muted_user = access_user_by_id(user_profile, muted_user_id, allow_bots=False, for_admin=False)
+    muted_user = access_user_by_id(
+        user_profile, muted_user_id, allow_bots=False, allow_deactivated=True, for_admin=False
+    )
     mute_object = get_mute_object(user_profile, muted_user)
 
     if mute_object is None:

{"golden_diff": "diff --git a/zerver/views/muting.py b/zerver/views/muting.py\n--- a/zerver/views/muting.py\n+++ b/zerver/views/muting.py\n@@ -94,7 +94,9 @@\n     if user_profile.id == muted_user_id:\n         raise JsonableError(_(\"Cannot mute self\"))\n \n-    muted_user = access_user_by_id(user_profile, muted_user_id, allow_bots=False, for_admin=False)\n+    muted_user = access_user_by_id(\n+        user_profile, muted_user_id, allow_bots=False, allow_deactivated=True, for_admin=False\n+    )\n     date_muted = timezone_now()\n \n     if get_mute_object(user_profile, muted_user) is not None:\n@@ -107,7 +109,9 @@\n def unmute_user(\n     request: HttpRequest, user_profile: UserProfile, muted_user_id: int\n ) -> HttpResponse:\n-    muted_user = access_user_by_id(user_profile, muted_user_id, allow_bots=False, for_admin=False)\n+    muted_user = access_user_by_id(\n+        user_profile, muted_user_id, allow_bots=False, allow_deactivated=True, for_admin=False\n+    )\n     mute_object = get_mute_object(user_profile, muted_user)\n \n     if mute_object is None:\n", "issue": "Make muting work for deactivated users\nEven after a user deactivated, it may be helpful to hide that user's messages, avatar, etc. We should therefore make it possible to mute deactivated users.\r\n\r\nThis will also fix a bug where if a user tries to mute a deactivated user, the action silently fails.\n", "before_files": [{"content": "import datetime\nfrom typing import Optional\n\nfrom django.http import HttpRequest, HttpResponse\nfrom django.utils.timezone import now as timezone_now\nfrom django.utils.translation import gettext as _\n\nfrom zerver.lib.actions import do_mute_topic, do_mute_user, do_unmute_topic, do_unmute_user\nfrom zerver.lib.exceptions import JsonableError\nfrom zerver.lib.request import REQ, has_request_variables\nfrom zerver.lib.response import json_success\nfrom zerver.lib.streams import (\n    access_stream_by_id,\n    access_stream_by_name,\n    access_stream_for_unmute_topic_by_id,\n    access_stream_for_unmute_topic_by_name,\n    check_for_exactly_one_stream_arg,\n)\nfrom zerver.lib.topic_mutes import topic_is_muted\nfrom zerver.lib.user_mutes import get_mute_object\nfrom zerver.lib.users import access_user_by_id\nfrom zerver.lib.validator import check_int\nfrom zerver.models import UserProfile\n\n\ndef mute_topic(\n    user_profile: UserProfile,\n    stream_id: Optional[int],\n    stream_name: Optional[str],\n    topic_name: str,\n    date_muted: datetime.datetime,\n) -> HttpResponse:\n    if stream_name is not None:\n        (stream, sub) = access_stream_by_name(user_profile, stream_name)\n    else:\n        assert stream_id is not None\n        (stream, sub) = access_stream_by_id(user_profile, stream_id)\n\n    if topic_is_muted(user_profile, stream.id, topic_name):\n        raise JsonableError(_(\"Topic already muted\"))\n\n    do_mute_topic(user_profile, stream, topic_name, date_muted)\n    return json_success()\n\n\ndef unmute_topic(\n    user_profile: UserProfile, stream_id: Optional[int], stream_name: Optional[str], topic_name: str\n) -> HttpResponse:\n    error = _(\"Topic is not muted\")\n\n    if stream_name is not None:\n        stream = access_stream_for_unmute_topic_by_name(user_profile, stream_name, error)\n    else:\n        assert stream_id is not None\n        stream = access_stream_for_unmute_topic_by_id(user_profile, stream_id, error)\n\n    if not topic_is_muted(user_profile, stream.id, topic_name):\n        raise JsonableError(error)\n\n    do_unmute_topic(user_profile, stream, topic_name)\n    return json_success()\n\n\n@has_request_variables\ndef update_muted_topic(\n    request: HttpRequest,\n    user_profile: UserProfile,\n    stream_id: Optional[int] = REQ(json_validator=check_int, default=None),\n    stream: Optional[str] = REQ(default=None),\n    topic: str = REQ(),\n    op: str = REQ(),\n) -> HttpResponse:\n\n    check_for_exactly_one_stream_arg(stream_id=stream_id, stream=stream)\n\n    if op == \"add\":\n        return mute_topic(\n            user_profile=user_profile,\n            stream_id=stream_id,\n            stream_name=stream,\n            topic_name=topic,\n            date_muted=timezone_now(),\n        )\n    elif op == \"remove\":\n        return unmute_topic(\n            user_profile=user_profile,\n            stream_id=stream_id,\n            stream_name=stream,\n            topic_name=topic,\n        )\n\n\ndef mute_user(request: HttpRequest, user_profile: UserProfile, muted_user_id: int) -> HttpResponse:\n    if user_profile.id == muted_user_id:\n        raise JsonableError(_(\"Cannot mute self\"))\n\n    muted_user = access_user_by_id(user_profile, muted_user_id, allow_bots=False, for_admin=False)\n    date_muted = timezone_now()\n\n    if get_mute_object(user_profile, muted_user) is not None:\n        raise JsonableError(_(\"User already muted\"))\n\n    do_mute_user(user_profile, muted_user, date_muted)\n    return json_success()\n\n\ndef unmute_user(\n    request: HttpRequest, user_profile: UserProfile, muted_user_id: int\n) -> HttpResponse:\n    muted_user = access_user_by_id(user_profile, muted_user_id, allow_bots=False, for_admin=False)\n    mute_object = get_mute_object(user_profile, muted_user)\n\n    if mute_object is None:\n        raise JsonableError(_(\"User is not muted\"))\n\n    do_unmute_user(mute_object)\n    return json_success()\n", "path": "zerver/views/muting.py"}], "after_files": [{"content": "import datetime\nfrom typing import Optional\n\nfrom django.http import HttpRequest, HttpResponse\nfrom django.utils.timezone import now as timezone_now\nfrom django.utils.translation import gettext as _\n\nfrom zerver.lib.actions import do_mute_topic, do_mute_user, do_unmute_topic, do_unmute_user\nfrom zerver.lib.exceptions import JsonableError\nfrom zerver.lib.request import REQ, has_request_variables\nfrom zerver.lib.response import json_success\nfrom zerver.lib.streams import (\n    access_stream_by_id,\n    access_stream_by_name,\n    access_stream_for_unmute_topic_by_id,\n    access_stream_for_unmute_topic_by_name,\n    check_for_exactly_one_stream_arg,\n)\nfrom zerver.lib.topic_mutes import topic_is_muted\nfrom zerver.lib.user_mutes import get_mute_object\nfrom zerver.lib.users import access_user_by_id\nfrom zerver.lib.validator import check_int\nfrom zerver.models import UserProfile\n\n\ndef mute_topic(\n    user_profile: UserProfile,\n    stream_id: Optional[int],\n    stream_name: Optional[str],\n    topic_name: str,\n    date_muted: datetime.datetime,\n) -> HttpResponse:\n    if stream_name is not None:\n        (stream, sub) = access_stream_by_name(user_profile, stream_name)\n    else:\n        assert stream_id is not None\n        (stream, sub) = access_stream_by_id(user_profile, stream_id)\n\n    if topic_is_muted(user_profile, stream.id, topic_name):\n        raise JsonableError(_(\"Topic already muted\"))\n\n    do_mute_topic(user_profile, stream, topic_name, date_muted)\n    return json_success()\n\n\ndef unmute_topic(\n    user_profile: UserProfile, stream_id: Optional[int], stream_name: Optional[str], topic_name: str\n) -> HttpResponse:\n    error = _(\"Topic is not muted\")\n\n    if stream_name is not None:\n        stream = access_stream_for_unmute_topic_by_name(user_profile, stream_name, error)\n    else:\n        assert stream_id is not None\n        stream = access_stream_for_unmute_topic_by_id(user_profile, stream_id, error)\n\n    if not topic_is_muted(user_profile, stream.id, topic_name):\n        raise JsonableError(error)\n\n    do_unmute_topic(user_profile, stream, topic_name)\n    return json_success()\n\n\n@has_request_variables\ndef update_muted_topic(\n    request: HttpRequest,\n    user_profile: UserProfile,\n    stream_id: Optional[int] = REQ(json_validator=check_int, default=None),\n    stream: Optional[str] = REQ(default=None),\n    topic: str = REQ(),\n    op: str = REQ(),\n) -> HttpResponse:\n\n    check_for_exactly_one_stream_arg(stream_id=stream_id, stream=stream)\n\n    if op == \"add\":\n        return mute_topic(\n            user_profile=user_profile,\n            stream_id=stream_id,\n            stream_name=stream,\n            topic_name=topic,\n            date_muted=timezone_now(),\n        )\n    elif op == \"remove\":\n        return unmute_topic(\n            user_profile=user_profile,\n            stream_id=stream_id,\n            stream_name=stream,\n            topic_name=topic,\n        )\n\n\ndef mute_user(request: HttpRequest, user_profile: UserProfile, muted_user_id: int) -> HttpResponse:\n    if user_profile.id == muted_user_id:\n        raise JsonableError(_(\"Cannot mute self\"))\n\n    muted_user = access_user_by_id(\n        user_profile, muted_user_id, allow_bots=False, allow_deactivated=True, for_admin=False\n    )\n    date_muted = timezone_now()\n\n    if get_mute_object(user_profile, muted_user) is not None:\n        raise JsonableError(_(\"User already muted\"))\n\n    do_mute_user(user_profile, muted_user, date_muted)\n    return json_success()\n\n\ndef unmute_user(\n    request: HttpRequest, user_profile: UserProfile, muted_user_id: int\n) -> HttpResponse:\n    muted_user = access_user_by_id(\n        user_profile, muted_user_id, allow_bots=False, allow_deactivated=True, for_admin=False\n    )\n    mute_object = get_mute_object(user_profile, muted_user)\n\n    if mute_object is None:\n        raise JsonableError(_(\"User is not muted\"))\n\n    do_unmute_user(mute_object)\n    return json_success()\n", "path": "zerver/views/muting.py"}]}