We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Error when trying to reset password of other user
## Steps to reproduce

1. Set up another Mathesar user (other than the one you're logged in as).

1. Edit the another user and try to reset their password.

1. Observe this error message:

    ![image](https://github.com/mathesar-foundation/mathesar/assets/42411/8968438c-bb80-4596-a8d7-deecc19010cc)
    
    An API request is made to `/api/ui/v0/users/2/password_reset/` which returns a Django error

    > AttributeError at /api/ui/v0/users/2/password_reset/
    >
    > 'PasswordResetSerializer' object has no attribute 'validate_password'

    <details>
    <summary>Traceback</summary>

    ```
    Environment:


    Request Method: POST
    Request URL: http://localhost:8000/api/ui/v0/users/2/password_reset/

    Django Version: 4.2.10
    Python Version: 3.9.19
    Installed Applications:
    ['django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'whitenoise.runserver_nostatic',
    'django.contrib.staticfiles',
    'rest_framework',
    'django_filters',
    'django_property_filter',
    'drf_spectacular',
    'mathesar']
    Installed Middleware:
    ['django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'mathesar.middleware.CursorClosedHandlerMiddleware',
    'mathesar.middleware.PasswordChangeNeededMiddleware',
    'django_userforeignkey.middleware.UserForeignKeyMiddleware',
    'django_request_cache.middleware.RequestCacheMiddleware']



    Traceback (most recent call last):
      File "/usr/local/lib/python3.9/site-packages/django/core/handlers/exception.py", line 55, in inner
        response = get_response(request)
      File "/usr/local/lib/python3.9/site-packages/django/core/handlers/base.py", line 197, in _get_response
        response = wrapped_callback(request, *callback_args, **callback_kwargs)
      File "/usr/local/lib/python3.9/site-packages/django/views/decorators/csrf.py", line 56, in wrapper_view
        return view_func(*args, **kwargs)
      File "/usr/local/lib/python3.9/site-packages/rest_framework/viewsets.py", line 125, in view
        return self.dispatch(request, *args, **kwargs)
      File "/usr/local/lib/python3.9/site-packages/rest_framework/views.py", line 509, in dispatch
        response = self.handle_exception(exc)
      File "/usr/local/lib/python3.9/site-packages/rest_framework/views.py", line 466, in handle_exception
        response = exception_handler(exc, context)
      File "/code/mathesar/exception_handlers.py", line 63, in mathesar_exception_handler
        raise exc
      File "/usr/local/lib/python3.9/site-packages/rest_framework/views.py", line 506, in dispatch
        response = handler(request, *args, **kwargs)
      File "/code/mathesar/api/ui/viewsets/users.py", line 29, in password_reset
        serializer.is_valid(raise_exception=True)
      File "/usr/local/lib/python3.9/site-packages/rest_framework/serializers.py", line 235, in is_valid
        raise ValidationError(self.errors)
      File "/code/mathesar/api/exceptions/mixins.py", line 98, in errors
        pretty_errors = self.build_pretty_errors(ugly_errors)
      File "/code/mathesar/api/exceptions/mixins.py", line 64, in build_pretty_errors
        pretty.extend(self.get_field_error_entries(errors[error_type], field))
      File "/usr/local/lib/python3.9/site-packages/rest_framework_friendly_errors/mixins.py", line 180, in get_field_error_entries
        return [self.get_field_error_entry(error, field) for error in errors]
      File "/usr/local/lib/python3.9/site-packages/rest_framework_friendly_errors/mixins.py", line 180, in <listcomp>
        return [self.get_field_error_entry(error, field) for error in errors]
      File "/usr/local/lib/python3.9/site-packages/rest_framework_friendly_errors/mixins.py", line 168, in get_field_error_entry
        validator = getattr(self, "validate_%s" % field.field_name)

    Exception Type: AttributeError at /api/ui/v0/users/2/password_reset/
    Exception Value: 'PasswordResetSerializer' object has no attribute 'validate_password'
    ```

    </details>

I can reproduce this on the latest develop branch as well as the most recent release (Mathesar 0.1.6).



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `mathesar/api/ui/serializers/users.py`
Content:
```
1 from django.contrib.auth.password_validation import validate_password
2 from rest_access_policy import FieldAccessMixin, PermittedPkRelatedField
3 from rest_framework import serializers
4 
5 from mathesar.api.db.permissions.database import DatabaseAccessPolicy
6 from mathesar.api.db.permissions.schema import SchemaAccessPolicy
7 from mathesar.api.exceptions.mixins import MathesarErrorMessageMixin
8 from mathesar.api.exceptions.validation_exceptions.exceptions import IncorrectOldPassword
9 from mathesar.api.ui.permissions.users import UserAccessPolicy
10 from mathesar.models.base import Database, Schema
11 from mathesar.models.users import User, DatabaseRole, SchemaRole
12 
13 
14 class NestedDatabaseRoleSerializer(MathesarErrorMessageMixin, serializers.ModelSerializer):
15     class Meta:
16         model = DatabaseRole
17         fields = ['id', 'database', 'role']
18 
19 
20 class NestedSchemaRoleSerializer(MathesarErrorMessageMixin, serializers.ModelSerializer):
21     class Meta:
22         model = SchemaRole
23         fields = ['id', 'schema', 'role']
24 
25 
26 class UserSerializer(MathesarErrorMessageMixin, FieldAccessMixin, serializers.ModelSerializer):
27     database_roles = NestedDatabaseRoleSerializer(many=True, required=False)
28     schema_roles = NestedSchemaRoleSerializer(many=True, required=False)
29     access_policy = UserAccessPolicy
30 
31     class Meta:
32         model = User
33         fields = [
34             'id',
35             'full_name',
36             'short_name',
37             'username',
38             'password',
39             'email',
40             'is_superuser',
41             'database_roles',
42             'schema_roles',
43             'display_language'
44         ]
45         extra_kwargs = {
46             'password': {'write_only': True},
47             'database_roles': {'read_only': True},
48             'schema_roles': {'read_only': True}
49         }
50 
51     def get_fields(self):
52         fields = super().get_fields()
53         request = self.context.get("request", None)
54         if not hasattr(request, 'parser_context'):
55             return fields
56         kwargs = request.parser_context.get('kwargs')
57         if kwargs:
58             user_pk = kwargs.get('pk')
59             if user_pk:
60                 if request.user.id == int(user_pk) or not request.user.is_superuser:
61                     fields["is_superuser"].read_only = True
62         return fields
63 
64     def create(self, validated_data):
65         password = validated_data.pop('password')
66         user = User(**validated_data)
67         user.password_change_needed = True
68         user.set_password(password)
69         user.save()
70         return user
71 
72 
73 class ChangePasswordSerializer(MathesarErrorMessageMixin, serializers.Serializer):
74     password = serializers.CharField(write_only=True, required=True, validators=[validate_password])
75     old_password = serializers.CharField(write_only=True, required=True)
76 
77     def validate_old_password(self, value):
78         user = self.context['request'].user
79         if user.check_password(value) is True:
80             return value
81         raise IncorrectOldPassword(field='old_password')
82 
83     def update(self, instance, validated_data):
84         instance.set_password(validated_data['password'])
85         instance.save()
86         return instance
87 
88 
89 class PasswordResetSerializer(MathesarErrorMessageMixin, serializers.Serializer):
90     password = serializers.CharField(write_only=True, required=True, validators=[validate_password])
91 
92 
93 class DatabaseRoleSerializer(MathesarErrorMessageMixin, serializers.ModelSerializer):
94     class Meta:
95         model = DatabaseRole
96         fields = ['id', 'user', 'database', 'role']
97 
98     # Restrict the list of databases to which the user has access to create a database role
99     # Refer https://rsinger86.github.io/drf-access-policy/policy_reuse/ for the usage of `PermittedPkRelatedField`
100     database = PermittedPkRelatedField(
101         access_policy=DatabaseAccessPolicy,
102         queryset=Database.current_objects.all()
103     )
104 
105 
106 class SchemaRoleSerializer(MathesarErrorMessageMixin, serializers.ModelSerializer):
107     class Meta:
108         model = SchemaRole
109         fields = ['id', 'user', 'schema', 'role']
110 
111     schema = PermittedPkRelatedField(
112         access_policy=SchemaAccessPolicy,
113         queryset=Schema.current_objects.all()
114     )
115
```
--- 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/mathesar/api/ui/serializers/users.py b/mathesar/api/ui/serializers/users.py
--- a/mathesar/api/ui/serializers/users.py
+++ b/mathesar/api/ui/serializers/users.py
@@ -1,4 +1,5 @@
 from django.contrib.auth.password_validation import validate_password
+from django.core.exceptions import ValidationError as DjangoValidationError
 from rest_access_policy import FieldAccessMixin, PermittedPkRelatedField
 from rest_framework import serializers
 
@@ -71,7 +72,7 @@
 
 
 class ChangePasswordSerializer(MathesarErrorMessageMixin, serializers.Serializer):
-    password = serializers.CharField(write_only=True, required=True, validators=[validate_password])
+    password = serializers.CharField(write_only=True, required=True)
     old_password = serializers.CharField(write_only=True, required=True)
 
     def validate_old_password(self, value):
@@ -80,6 +81,13 @@
             return value
         raise IncorrectOldPassword(field='old_password')
 
+    def validate_password(self, value):
+        try:
+            validate_password(value)
+        except DjangoValidationError as e:
+            raise e
+        return value
+
     def update(self, instance, validated_data):
         instance.set_password(validated_data['password'])
         instance.save()
@@ -87,7 +95,7 @@
 
 
 class PasswordResetSerializer(MathesarErrorMessageMixin, serializers.Serializer):
-    password = serializers.CharField(write_only=True, required=True, validators=[validate_password])
+    password = serializers.CharField(write_only=True, required=True)
 
 
 class DatabaseRoleSerializer(MathesarErrorMessageMixin, serializers.ModelSerializer):

{"golden_diff": "diff --git a/mathesar/api/ui/serializers/users.py b/mathesar/api/ui/serializers/users.py\n--- a/mathesar/api/ui/serializers/users.py\n+++ b/mathesar/api/ui/serializers/users.py\n@@ -1,4 +1,5 @@\n from django.contrib.auth.password_validation import validate_password\n+from django.core.exceptions import ValidationError as DjangoValidationError\n from rest_access_policy import FieldAccessMixin, PermittedPkRelatedField\n from rest_framework import serializers\n \n@@ -71,7 +72,7 @@\n \n \n class ChangePasswordSerializer(MathesarErrorMessageMixin, serializers.Serializer):\n-    password = serializers.CharField(write_only=True, required=True, validators=[validate_password])\n+    password = serializers.CharField(write_only=True, required=True)\n     old_password = serializers.CharField(write_only=True, required=True)\n \n     def validate_old_password(self, value):\n@@ -80,6 +81,13 @@\n             return value\n         raise IncorrectOldPassword(field='old_password')\n \n+    def validate_password(self, value):\n+        try:\n+            validate_password(value)\n+        except DjangoValidationError as e:\n+            raise e\n+        return value\n+\n     def update(self, instance, validated_data):\n         instance.set_password(validated_data['password'])\n         instance.save()\n@@ -87,7 +95,7 @@\n \n \n class PasswordResetSerializer(MathesarErrorMessageMixin, serializers.Serializer):\n-    password = serializers.CharField(write_only=True, required=True, validators=[validate_password])\n+    password = serializers.CharField(write_only=True, required=True)\n \n \n class DatabaseRoleSerializer(MathesarErrorMessageMixin, serializers.ModelSerializer):\n", "issue": "Error when trying to reset password of other user\n## Steps to reproduce\n\n1. Set up another Mathesar user (other than the one you're logged in as).\n\n1. Edit the another user and try to reset their password.\n\n1. Observe this error message:\n\n    ![image](https://github.com/mathesar-foundation/mathesar/assets/42411/8968438c-bb80-4596-a8d7-deecc19010cc)\n    \n    An API request is made to `/api/ui/v0/users/2/password_reset/` which returns a Django error\n\n    > AttributeError at /api/ui/v0/users/2/password_reset/\n    >\n    > 'PasswordResetSerializer' object has no attribute 'validate_password'\n\n    <details>\n    <summary>Traceback</summary>\n\n    ```\n    Environment:\n\n\n    Request Method: POST\n    Request URL: http://localhost:8000/api/ui/v0/users/2/password_reset/\n\n    Django Version: 4.2.10\n    Python Version: 3.9.19\n    Installed Applications:\n    ['django.contrib.admin',\n    'django.contrib.auth',\n    'django.contrib.contenttypes',\n    'django.contrib.sessions',\n    'django.contrib.messages',\n    'whitenoise.runserver_nostatic',\n    'django.contrib.staticfiles',\n    'rest_framework',\n    'django_filters',\n    'django_property_filter',\n    'drf_spectacular',\n    'mathesar']\n    Installed Middleware:\n    ['django.middleware.security.SecurityMiddleware',\n    'whitenoise.middleware.WhiteNoiseMiddleware',\n    'django.contrib.sessions.middleware.SessionMiddleware',\n    'django.middleware.locale.LocaleMiddleware',\n    'django.middleware.common.CommonMiddleware',\n    'django.middleware.csrf.CsrfViewMiddleware',\n    'django.contrib.auth.middleware.AuthenticationMiddleware',\n    'django.contrib.messages.middleware.MessageMiddleware',\n    'django.middleware.clickjacking.XFrameOptionsMiddleware',\n    'mathesar.middleware.CursorClosedHandlerMiddleware',\n    'mathesar.middleware.PasswordChangeNeededMiddleware',\n    'django_userforeignkey.middleware.UserForeignKeyMiddleware',\n    'django_request_cache.middleware.RequestCacheMiddleware']\n\n\n\n    Traceback (most recent call last):\n      File \"/usr/local/lib/python3.9/site-packages/django/core/handlers/exception.py\", line 55, in inner\n        response = get_response(request)\n      File \"/usr/local/lib/python3.9/site-packages/django/core/handlers/base.py\", line 197, in _get_response\n        response = wrapped_callback(request, *callback_args, **callback_kwargs)\n      File \"/usr/local/lib/python3.9/site-packages/django/views/decorators/csrf.py\", line 56, in wrapper_view\n        return view_func(*args, **kwargs)\n      File \"/usr/local/lib/python3.9/site-packages/rest_framework/viewsets.py\", line 125, in view\n        return self.dispatch(request, *args, **kwargs)\n      File \"/usr/local/lib/python3.9/site-packages/rest_framework/views.py\", line 509, in dispatch\n        response = self.handle_exception(exc)\n      File \"/usr/local/lib/python3.9/site-packages/rest_framework/views.py\", line 466, in handle_exception\n        response = exception_handler(exc, context)\n      File \"/code/mathesar/exception_handlers.py\", line 63, in mathesar_exception_handler\n        raise exc\n      File \"/usr/local/lib/python3.9/site-packages/rest_framework/views.py\", line 506, in dispatch\n        response = handler(request, *args, **kwargs)\n      File \"/code/mathesar/api/ui/viewsets/users.py\", line 29, in password_reset\n        serializer.is_valid(raise_exception=True)\n      File \"/usr/local/lib/python3.9/site-packages/rest_framework/serializers.py\", line 235, in is_valid\n        raise ValidationError(self.errors)\n      File \"/code/mathesar/api/exceptions/mixins.py\", line 98, in errors\n        pretty_errors = self.build_pretty_errors(ugly_errors)\n      File \"/code/mathesar/api/exceptions/mixins.py\", line 64, in build_pretty_errors\n        pretty.extend(self.get_field_error_entries(errors[error_type], field))\n      File \"/usr/local/lib/python3.9/site-packages/rest_framework_friendly_errors/mixins.py\", line 180, in get_field_error_entries\n        return [self.get_field_error_entry(error, field) for error in errors]\n      File \"/usr/local/lib/python3.9/site-packages/rest_framework_friendly_errors/mixins.py\", line 180, in <listcomp>\n        return [self.get_field_error_entry(error, field) for error in errors]\n      File \"/usr/local/lib/python3.9/site-packages/rest_framework_friendly_errors/mixins.py\", line 168, in get_field_error_entry\n        validator = getattr(self, \"validate_%s\" % field.field_name)\n\n    Exception Type: AttributeError at /api/ui/v0/users/2/password_reset/\n    Exception Value: 'PasswordResetSerializer' object has no attribute 'validate_password'\n    ```\n\n    </details>\n\nI can reproduce this on the latest develop branch as well as the most recent release (Mathesar 0.1.6).\n\n\n", "before_files": [{"content": "from django.contrib.auth.password_validation import validate_password\nfrom rest_access_policy import FieldAccessMixin, PermittedPkRelatedField\nfrom rest_framework import serializers\n\nfrom mathesar.api.db.permissions.database import DatabaseAccessPolicy\nfrom mathesar.api.db.permissions.schema import SchemaAccessPolicy\nfrom mathesar.api.exceptions.mixins import MathesarErrorMessageMixin\nfrom mathesar.api.exceptions.validation_exceptions.exceptions import IncorrectOldPassword\nfrom mathesar.api.ui.permissions.users import UserAccessPolicy\nfrom mathesar.models.base import Database, Schema\nfrom mathesar.models.users import User, DatabaseRole, SchemaRole\n\n\nclass NestedDatabaseRoleSerializer(MathesarErrorMessageMixin, serializers.ModelSerializer):\n    class Meta:\n        model = DatabaseRole\n        fields = ['id', 'database', 'role']\n\n\nclass NestedSchemaRoleSerializer(MathesarErrorMessageMixin, serializers.ModelSerializer):\n    class Meta:\n        model = SchemaRole\n        fields = ['id', 'schema', 'role']\n\n\nclass UserSerializer(MathesarErrorMessageMixin, FieldAccessMixin, serializers.ModelSerializer):\n    database_roles = NestedDatabaseRoleSerializer(many=True, required=False)\n    schema_roles = NestedSchemaRoleSerializer(many=True, required=False)\n    access_policy = UserAccessPolicy\n\n    class Meta:\n        model = User\n        fields = [\n            'id',\n            'full_name',\n            'short_name',\n            'username',\n            'password',\n            'email',\n            'is_superuser',\n            'database_roles',\n            'schema_roles',\n            'display_language'\n        ]\n        extra_kwargs = {\n            'password': {'write_only': True},\n            'database_roles': {'read_only': True},\n            'schema_roles': {'read_only': True}\n        }\n\n    def get_fields(self):\n        fields = super().get_fields()\n        request = self.context.get(\"request\", None)\n        if not hasattr(request, 'parser_context'):\n            return fields\n        kwargs = request.parser_context.get('kwargs')\n        if kwargs:\n            user_pk = kwargs.get('pk')\n            if user_pk:\n                if request.user.id == int(user_pk) or not request.user.is_superuser:\n                    fields[\"is_superuser\"].read_only = True\n        return fields\n\n    def create(self, validated_data):\n        password = validated_data.pop('password')\n        user = User(**validated_data)\n        user.password_change_needed = True\n        user.set_password(password)\n        user.save()\n        return user\n\n\nclass ChangePasswordSerializer(MathesarErrorMessageMixin, serializers.Serializer):\n    password = serializers.CharField(write_only=True, required=True, validators=[validate_password])\n    old_password = serializers.CharField(write_only=True, required=True)\n\n    def validate_old_password(self, value):\n        user = self.context['request'].user\n        if user.check_password(value) is True:\n            return value\n        raise IncorrectOldPassword(field='old_password')\n\n    def update(self, instance, validated_data):\n        instance.set_password(validated_data['password'])\n        instance.save()\n        return instance\n\n\nclass PasswordResetSerializer(MathesarErrorMessageMixin, serializers.Serializer):\n    password = serializers.CharField(write_only=True, required=True, validators=[validate_password])\n\n\nclass DatabaseRoleSerializer(MathesarErrorMessageMixin, serializers.ModelSerializer):\n    class Meta:\n        model = DatabaseRole\n        fields = ['id', 'user', 'database', 'role']\n\n    # Restrict the list of databases to which the user has access to create a database role\n    # Refer https://rsinger86.github.io/drf-access-policy/policy_reuse/ for the usage of `PermittedPkRelatedField`\n    database = PermittedPkRelatedField(\n        access_policy=DatabaseAccessPolicy,\n        queryset=Database.current_objects.all()\n    )\n\n\nclass SchemaRoleSerializer(MathesarErrorMessageMixin, serializers.ModelSerializer):\n    class Meta:\n        model = SchemaRole\n        fields = ['id', 'user', 'schema', 'role']\n\n    schema = PermittedPkRelatedField(\n        access_policy=SchemaAccessPolicy,\n        queryset=Schema.current_objects.all()\n    )\n", "path": "mathesar/api/ui/serializers/users.py"}], "after_files": [{"content": "from django.contrib.auth.password_validation import validate_password\nfrom django.core.exceptions import ValidationError as DjangoValidationError\nfrom rest_access_policy import FieldAccessMixin, PermittedPkRelatedField\nfrom rest_framework import serializers\n\nfrom mathesar.api.db.permissions.database import DatabaseAccessPolicy\nfrom mathesar.api.db.permissions.schema import SchemaAccessPolicy\nfrom mathesar.api.exceptions.mixins import MathesarErrorMessageMixin\nfrom mathesar.api.exceptions.validation_exceptions.exceptions import IncorrectOldPassword\nfrom mathesar.api.ui.permissions.users import UserAccessPolicy\nfrom mathesar.models.base import Database, Schema\nfrom mathesar.models.users import User, DatabaseRole, SchemaRole\n\n\nclass NestedDatabaseRoleSerializer(MathesarErrorMessageMixin, serializers.ModelSerializer):\n    class Meta:\n        model = DatabaseRole\n        fields = ['id', 'database', 'role']\n\n\nclass NestedSchemaRoleSerializer(MathesarErrorMessageMixin, serializers.ModelSerializer):\n    class Meta:\n        model = SchemaRole\n        fields = ['id', 'schema', 'role']\n\n\nclass UserSerializer(MathesarErrorMessageMixin, FieldAccessMixin, serializers.ModelSerializer):\n    database_roles = NestedDatabaseRoleSerializer(many=True, required=False)\n    schema_roles = NestedSchemaRoleSerializer(many=True, required=False)\n    access_policy = UserAccessPolicy\n\n    class Meta:\n        model = User\n        fields = [\n            'id',\n            'full_name',\n            'short_name',\n            'username',\n            'password',\n            'email',\n            'is_superuser',\n            'database_roles',\n            'schema_roles',\n            'display_language'\n        ]\n        extra_kwargs = {\n            'password': {'write_only': True},\n            'database_roles': {'read_only': True},\n            'schema_roles': {'read_only': True}\n        }\n\n    def get_fields(self):\n        fields = super().get_fields()\n        request = self.context.get(\"request\", None)\n        if not hasattr(request, 'parser_context'):\n            return fields\n        kwargs = request.parser_context.get('kwargs')\n        if kwargs:\n            user_pk = kwargs.get('pk')\n            if user_pk:\n                if request.user.id == int(user_pk) or not request.user.is_superuser:\n                    fields[\"is_superuser\"].read_only = True\n        return fields\n\n    def create(self, validated_data):\n        password = validated_data.pop('password')\n        user = User(**validated_data)\n        user.password_change_needed = True\n        user.set_password(password)\n        user.save()\n        return user\n\n\nclass ChangePasswordSerializer(MathesarErrorMessageMixin, serializers.Serializer):\n    password = serializers.CharField(write_only=True, required=True)\n    old_password = serializers.CharField(write_only=True, required=True)\n\n    def validate_old_password(self, value):\n        user = self.context['request'].user\n        if user.check_password(value) is True:\n            return value\n        raise IncorrectOldPassword(field='old_password')\n\n    def validate_password(self, value):\n        try:\n            validate_password(value)\n        except DjangoValidationError as e:\n            raise e\n        return value\n\n    def update(self, instance, validated_data):\n        instance.set_password(validated_data['password'])\n        instance.save()\n        return instance\n\n\nclass PasswordResetSerializer(MathesarErrorMessageMixin, serializers.Serializer):\n    password = serializers.CharField(write_only=True, required=True)\n\n\nclass DatabaseRoleSerializer(MathesarErrorMessageMixin, serializers.ModelSerializer):\n    class Meta:\n        model = DatabaseRole\n        fields = ['id', 'user', 'database', 'role']\n\n    # Restrict the list of databases to which the user has access to create a database role\n    # Refer https://rsinger86.github.io/drf-access-policy/policy_reuse/ for the usage of `PermittedPkRelatedField`\n    database = PermittedPkRelatedField(\n        access_policy=DatabaseAccessPolicy,\n        queryset=Database.current_objects.all()\n    )\n\n\nclass SchemaRoleSerializer(MathesarErrorMessageMixin, serializers.ModelSerializer):\n    class Meta:\n        model = SchemaRole\n        fields = ['id', 'user', 'schema', 'role']\n\n    schema = PermittedPkRelatedField(\n        access_policy=SchemaAccessPolicy,\n        queryset=Schema.current_objects.all()\n    )\n", "path": "mathesar/api/ui/serializers/users.py"}]}