We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
common_data should contain the current user data
## Description
`common_data` should contain the information of the current logged in user.

--- 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/views.py`
Content:
```
1 from django.conf import settings
2 from django.contrib.auth.decorators import login_required
3 from django.shortcuts import render, redirect, get_object_or_404
4 from rest_framework import status
5 from rest_framework.decorators import api_view
6 from rest_framework.response import Response
7 
8 from mathesar.api.serializers.databases import DatabaseSerializer, TypeSerializer
9 from mathesar.api.serializers.schemas import SchemaSerializer
10 from mathesar.api.serializers.tables import TableSerializer
11 from mathesar.api.serializers.queries import QuerySerializer
12 from mathesar.database.types import UIType
13 from mathesar.models.base import Database, Schema, Table
14 from mathesar.models.query import UIQuery
15 from mathesar.state import reset_reflection
16 
17 
18 def get_schema_list(request, database):
19     schema_serializer = SchemaSerializer(
20         Schema.objects.filter(database=database),
21         many=True,
22         context={'request': request}
23     )
24     return schema_serializer.data
25 
26 
27 def get_database_list(request):
28     database_serializer = DatabaseSerializer(
29         Database.objects.all(),
30         many=True,
31         context={'request': request}
32     )
33     return database_serializer.data
34 
35 
36 def get_table_list(request, schema):
37     if schema is None:
38         return []
39     table_serializer = TableSerializer(
40         Table.objects.filter(schema=schema),
41         many=True,
42         context={'request': request}
43     )
44     return table_serializer.data
45 
46 
47 def get_queries_list(request, schema):
48     if schema is None:
49         return []
50     query_serializer = QuerySerializer(
51         UIQuery.objects.filter(base_table__schema=schema),
52         many=True,
53         context={'request': request}
54     )
55     return query_serializer.data
56 
57 
58 def get_ui_type_list(request, database):
59     if database is None:
60         return []
61     type_serializer = TypeSerializer(
62         UIType,
63         many=True,
64         context={'request': request}
65     )
66     return type_serializer.data
67 
68 
69 def get_common_data(request, database, schema=None):
70     return {
71         'current_db': database.name if database else None,
72         'current_schema': schema.id if schema else None,
73         'schemas': get_schema_list(request, database),
74         'databases': get_database_list(request),
75         'tables': get_table_list(request, schema),
76         'queries': get_queries_list(request, schema),
77         'abstract_types': get_ui_type_list(request, database),
78         'live_demo_mode': getattr(settings, 'MATHESAR_LIVE_DEMO', False),
79     }
80 
81 
82 def get_current_database(request, db_name):
83     """Get database from passed name, with fall back behavior."""
84     if db_name is not None:
85         current_database = get_object_or_404(Database, name=db_name)
86     else:
87         request_database_name = request.GET.get('database')
88         try:
89             if request_database_name is not None:
90                 # Try to get the database named specified in the request
91                 current_database = Database.objects.get(name=request_database_name)
92             else:
93                 # Try to get the first database available
94                 current_database = Database.objects.order_by('id').first()
95         except Database.DoesNotExist:
96             current_database = None
97     return current_database
98 
99 
100 def get_current_schema(request, schema_id, database):
101     # if there's a schema ID passed in, try to retrieve the schema, or return a 404 error.
102     if schema_id is not None:
103         return get_object_or_404(Schema, id=schema_id)
104     else:
105         try:
106             # Try to get the first schema in the DB
107             return Schema.objects.filter(database=database).order_by('id').first()
108         except Schema.DoesNotExist:
109             return None
110 
111 
112 def render_schema(request, database, schema):
113     # if there's no schema available, redirect to the schemas page.
114     if not schema:
115         return redirect('schemas', db_name=database.name)
116     else:
117         # We are redirecting so that the correct URL is passed to the frontend.
118         return redirect('schema_home', db_name=database.name, schema_id=schema.id)
119 
120 
121 @login_required
122 @api_view(['POST'])
123 def reflect_all(_):
124     reset_reflection()
125     return Response(status=status.HTTP_200_OK)
126 
127 
128 @login_required
129 def home(request):
130     database = get_current_database(request, None)
131     return redirect('schemas', db_name=database.name)
132 
133 
134 @login_required
135 def schema_home(request, db_name, schema_id, **kwargs):
136     database = get_current_database(request, db_name)
137     schema = get_current_schema(request, schema_id, database)
138     return render(request, 'mathesar/index.html', {
139         'common_data': get_common_data(request, database, schema)
140     })
141 
142 
143 @login_required
144 def schemas(request, db_name):
145     database = get_current_database(request, db_name)
146     return render(request, 'mathesar/index.html', {
147         'common_data': get_common_data(request, database, None)
148     })
149
```

Path: `mathesar/api/ui/viewsets/users.py`
Content:
```
1 from django.contrib.auth import get_user_model
2 from rest_access_policy import AccessViewSetMixin
3 from rest_framework import status, viewsets
4 from rest_framework.decorators import action
5 from rest_framework.exceptions import MethodNotAllowed
6 from rest_framework.generics import get_object_or_404
7 from rest_framework.response import Response
8 
9 from mathesar.api.ui.permissions.database_role import DatabaseRoleAccessPolicy
10 from mathesar.api.ui.permissions.schema_role import SchemaRoleAccessPolicy
11 from mathesar.api.ui.serializers.users import (
12     ChangePasswordSerializer, PasswordResetSerializer, UserSerializer, DatabaseRoleSerializer,
13     SchemaRoleSerializer,
14 )
15 from mathesar.api.pagination import DefaultLimitOffsetPagination
16 from mathesar.api.ui.permissions.users import UserAccessPolicy
17 from mathesar.models.users import User, DatabaseRole, SchemaRole
18 
19 
20 class UserViewSet(AccessViewSetMixin, viewsets.ModelViewSet):
21     queryset = User.objects.all().order_by('id')
22     serializer_class = UserSerializer
23     pagination_class = DefaultLimitOffsetPagination
24     access_policy = UserAccessPolicy
25 
26     @action(methods=['post'], detail=True)
27     def password_reset(self, request, pk=None):
28         serializer = PasswordResetSerializer(data=request.data, context={'request': request})
29         serializer.is_valid(raise_exception=True)
30         user = get_object_or_404(get_user_model(), pk=pk)
31         password = serializer.validated_data["password"]
32         user.set_password(password)
33         # Make sure we redirect user to change password set by the admin on login
34         user.password_change_needed = True
35         user.save()
36         return Response(status=status.HTTP_200_OK)
37 
38     @action(methods=['post'], detail=False)
39     def password_change(self, request):
40         serializer = ChangePasswordSerializer(
41             instance=request.user,
42             data=request.data,
43             context={'request': request}
44         )
45         serializer.is_valid(raise_exception=True)
46         serializer.save()
47         return Response(status=status.HTTP_200_OK)
48 
49 
50 class DatabaseRoleViewSet(AccessViewSetMixin, viewsets.ModelViewSet):
51     queryset = DatabaseRole.objects.all().order_by('id')
52     serializer_class = DatabaseRoleSerializer
53     pagination_class = DefaultLimitOffsetPagination
54     access_policy = DatabaseRoleAccessPolicy
55 
56     def get_queryset(self):
57         return self.access_policy.scope_queryset(
58             self.request, super().get_queryset()
59         )
60 
61     def update(self, request, pk=None):
62         raise MethodNotAllowed(request.method)
63 
64     def partial_update(self, request, pk=None):
65         raise MethodNotAllowed(request.method)
66 
67 
68 class SchemaRoleViewSet(AccessViewSetMixin, viewsets.ModelViewSet):
69     queryset = SchemaRole.objects.all().order_by('id')
70     serializer_class = SchemaRoleSerializer
71     pagination_class = DefaultLimitOffsetPagination
72     access_policy = SchemaRoleAccessPolicy
73 
74     def get_queryset(self):
75         return self.access_policy.scope_queryset(
76             self.request, super().get_queryset()
77         )
78 
79     def update(self, request, pk=None):
80         raise MethodNotAllowed(request.method)
81 
82     def partial_update(self, request, pk=None):
83         raise MethodNotAllowed(request.method)
84
```
--- 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/viewsets/users.py b/mathesar/api/ui/viewsets/users.py
--- a/mathesar/api/ui/viewsets/users.py
+++ b/mathesar/api/ui/viewsets/users.py
@@ -14,11 +14,11 @@
 )
 from mathesar.api.pagination import DefaultLimitOffsetPagination
 from mathesar.api.ui.permissions.users import UserAccessPolicy
-from mathesar.models.users import User, DatabaseRole, SchemaRole
+from mathesar.models.users import DatabaseRole, SchemaRole
 
 
 class UserViewSet(AccessViewSetMixin, viewsets.ModelViewSet):
-    queryset = User.objects.all().order_by('id')
+    queryset = get_user_model().objects.all().order_by('id')
     serializer_class = UserSerializer
     pagination_class = DefaultLimitOffsetPagination
     access_policy = UserAccessPolicy
diff --git a/mathesar/views.py b/mathesar/views.py
--- a/mathesar/views.py
+++ b/mathesar/views.py
@@ -9,6 +9,7 @@
 from mathesar.api.serializers.schemas import SchemaSerializer
 from mathesar.api.serializers.tables import TableSerializer
 from mathesar.api.serializers.queries import QuerySerializer
+from mathesar.api.ui.serializers.users import UserSerializer
 from mathesar.database.types import UIType
 from mathesar.models.base import Database, Schema, Table
 from mathesar.models.query import UIQuery
@@ -66,6 +67,15 @@
     return type_serializer.data
 
 
+def get_user_data(request):
+    user_serializer = UserSerializer(
+        request.user,
+        many=False,
+        context={'request': request}
+    )
+    return user_serializer.data
+
+
 def get_common_data(request, database, schema=None):
     return {
         'current_db': database.name if database else None,
@@ -75,6 +85,7 @@
         'tables': get_table_list(request, schema),
         'queries': get_queries_list(request, schema),
         'abstract_types': get_ui_type_list(request, database),
+        'user': get_user_data(request),
         'live_demo_mode': getattr(settings, 'MATHESAR_LIVE_DEMO', False),
     }

{"golden_diff": "diff --git a/mathesar/api/ui/viewsets/users.py b/mathesar/api/ui/viewsets/users.py\n--- a/mathesar/api/ui/viewsets/users.py\n+++ b/mathesar/api/ui/viewsets/users.py\n@@ -14,11 +14,11 @@\n )\n from mathesar.api.pagination import DefaultLimitOffsetPagination\n from mathesar.api.ui.permissions.users import UserAccessPolicy\n-from mathesar.models.users import User, DatabaseRole, SchemaRole\n+from mathesar.models.users import DatabaseRole, SchemaRole\n \n \n class UserViewSet(AccessViewSetMixin, viewsets.ModelViewSet):\n-    queryset = User.objects.all().order_by('id')\n+    queryset = get_user_model().objects.all().order_by('id')\n     serializer_class = UserSerializer\n     pagination_class = DefaultLimitOffsetPagination\n     access_policy = UserAccessPolicy\ndiff --git a/mathesar/views.py b/mathesar/views.py\n--- a/mathesar/views.py\n+++ b/mathesar/views.py\n@@ -9,6 +9,7 @@\n from mathesar.api.serializers.schemas import SchemaSerializer\n from mathesar.api.serializers.tables import TableSerializer\n from mathesar.api.serializers.queries import QuerySerializer\n+from mathesar.api.ui.serializers.users import UserSerializer\n from mathesar.database.types import UIType\n from mathesar.models.base import Database, Schema, Table\n from mathesar.models.query import UIQuery\n@@ -66,6 +67,15 @@\n     return type_serializer.data\n \n \n+def get_user_data(request):\n+    user_serializer = UserSerializer(\n+        request.user,\n+        many=False,\n+        context={'request': request}\n+    )\n+    return user_serializer.data\n+\n+\n def get_common_data(request, database, schema=None):\n     return {\n         'current_db': database.name if database else None,\n@@ -75,6 +85,7 @@\n         'tables': get_table_list(request, schema),\n         'queries': get_queries_list(request, schema),\n         'abstract_types': get_ui_type_list(request, database),\n+        'user': get_user_data(request),\n         'live_demo_mode': getattr(settings, 'MATHESAR_LIVE_DEMO', False),\n     }\n", "issue": "common_data should contain the current user data\n## Description\r\n`common_data` should contain the information of the current logged in user.\n", "before_files": [{"content": "from django.conf import settings\nfrom django.contrib.auth.decorators import login_required\nfrom django.shortcuts import render, redirect, get_object_or_404\nfrom rest_framework import status\nfrom rest_framework.decorators import api_view\nfrom rest_framework.response import Response\n\nfrom mathesar.api.serializers.databases import DatabaseSerializer, TypeSerializer\nfrom mathesar.api.serializers.schemas import SchemaSerializer\nfrom mathesar.api.serializers.tables import TableSerializer\nfrom mathesar.api.serializers.queries import QuerySerializer\nfrom mathesar.database.types import UIType\nfrom mathesar.models.base import Database, Schema, Table\nfrom mathesar.models.query import UIQuery\nfrom mathesar.state import reset_reflection\n\n\ndef get_schema_list(request, database):\n    schema_serializer = SchemaSerializer(\n        Schema.objects.filter(database=database),\n        many=True,\n        context={'request': request}\n    )\n    return schema_serializer.data\n\n\ndef get_database_list(request):\n    database_serializer = DatabaseSerializer(\n        Database.objects.all(),\n        many=True,\n        context={'request': request}\n    )\n    return database_serializer.data\n\n\ndef get_table_list(request, schema):\n    if schema is None:\n        return []\n    table_serializer = TableSerializer(\n        Table.objects.filter(schema=schema),\n        many=True,\n        context={'request': request}\n    )\n    return table_serializer.data\n\n\ndef get_queries_list(request, schema):\n    if schema is None:\n        return []\n    query_serializer = QuerySerializer(\n        UIQuery.objects.filter(base_table__schema=schema),\n        many=True,\n        context={'request': request}\n    )\n    return query_serializer.data\n\n\ndef get_ui_type_list(request, database):\n    if database is None:\n        return []\n    type_serializer = TypeSerializer(\n        UIType,\n        many=True,\n        context={'request': request}\n    )\n    return type_serializer.data\n\n\ndef get_common_data(request, database, schema=None):\n    return {\n        'current_db': database.name if database else None,\n        'current_schema': schema.id if schema else None,\n        'schemas': get_schema_list(request, database),\n        'databases': get_database_list(request),\n        'tables': get_table_list(request, schema),\n        'queries': get_queries_list(request, schema),\n        'abstract_types': get_ui_type_list(request, database),\n        'live_demo_mode': getattr(settings, 'MATHESAR_LIVE_DEMO', False),\n    }\n\n\ndef get_current_database(request, db_name):\n    \"\"\"Get database from passed name, with fall back behavior.\"\"\"\n    if db_name is not None:\n        current_database = get_object_or_404(Database, name=db_name)\n    else:\n        request_database_name = request.GET.get('database')\n        try:\n            if request_database_name is not None:\n                # Try to get the database named specified in the request\n                current_database = Database.objects.get(name=request_database_name)\n            else:\n                # Try to get the first database available\n                current_database = Database.objects.order_by('id').first()\n        except Database.DoesNotExist:\n            current_database = None\n    return current_database\n\n\ndef get_current_schema(request, schema_id, database):\n    # if there's a schema ID passed in, try to retrieve the schema, or return a 404 error.\n    if schema_id is not None:\n        return get_object_or_404(Schema, id=schema_id)\n    else:\n        try:\n            # Try to get the first schema in the DB\n            return Schema.objects.filter(database=database).order_by('id').first()\n        except Schema.DoesNotExist:\n            return None\n\n\ndef render_schema(request, database, schema):\n    # if there's no schema available, redirect to the schemas page.\n    if not schema:\n        return redirect('schemas', db_name=database.name)\n    else:\n        # We are redirecting so that the correct URL is passed to the frontend.\n        return redirect('schema_home', db_name=database.name, schema_id=schema.id)\n\n\n@login_required\n@api_view(['POST'])\ndef reflect_all(_):\n    reset_reflection()\n    return Response(status=status.HTTP_200_OK)\n\n\n@login_required\ndef home(request):\n    database = get_current_database(request, None)\n    return redirect('schemas', db_name=database.name)\n\n\n@login_required\ndef schema_home(request, db_name, schema_id, **kwargs):\n    database = get_current_database(request, db_name)\n    schema = get_current_schema(request, schema_id, database)\n    return render(request, 'mathesar/index.html', {\n        'common_data': get_common_data(request, database, schema)\n    })\n\n\n@login_required\ndef schemas(request, db_name):\n    database = get_current_database(request, db_name)\n    return render(request, 'mathesar/index.html', {\n        'common_data': get_common_data(request, database, None)\n    })\n", "path": "mathesar/views.py"}, {"content": "from django.contrib.auth import get_user_model\nfrom rest_access_policy import AccessViewSetMixin\nfrom rest_framework import status, viewsets\nfrom rest_framework.decorators import action\nfrom rest_framework.exceptions import MethodNotAllowed\nfrom rest_framework.generics import get_object_or_404\nfrom rest_framework.response import Response\n\nfrom mathesar.api.ui.permissions.database_role import DatabaseRoleAccessPolicy\nfrom mathesar.api.ui.permissions.schema_role import SchemaRoleAccessPolicy\nfrom mathesar.api.ui.serializers.users import (\n    ChangePasswordSerializer, PasswordResetSerializer, UserSerializer, DatabaseRoleSerializer,\n    SchemaRoleSerializer,\n)\nfrom mathesar.api.pagination import DefaultLimitOffsetPagination\nfrom mathesar.api.ui.permissions.users import UserAccessPolicy\nfrom mathesar.models.users import User, DatabaseRole, SchemaRole\n\n\nclass UserViewSet(AccessViewSetMixin, viewsets.ModelViewSet):\n    queryset = User.objects.all().order_by('id')\n    serializer_class = UserSerializer\n    pagination_class = DefaultLimitOffsetPagination\n    access_policy = UserAccessPolicy\n\n    @action(methods=['post'], detail=True)\n    def password_reset(self, request, pk=None):\n        serializer = PasswordResetSerializer(data=request.data, context={'request': request})\n        serializer.is_valid(raise_exception=True)\n        user = get_object_or_404(get_user_model(), pk=pk)\n        password = serializer.validated_data[\"password\"]\n        user.set_password(password)\n        # Make sure we redirect user to change password set by the admin on login\n        user.password_change_needed = True\n        user.save()\n        return Response(status=status.HTTP_200_OK)\n\n    @action(methods=['post'], detail=False)\n    def password_change(self, request):\n        serializer = ChangePasswordSerializer(\n            instance=request.user,\n            data=request.data,\n            context={'request': request}\n        )\n        serializer.is_valid(raise_exception=True)\n        serializer.save()\n        return Response(status=status.HTTP_200_OK)\n\n\nclass DatabaseRoleViewSet(AccessViewSetMixin, viewsets.ModelViewSet):\n    queryset = DatabaseRole.objects.all().order_by('id')\n    serializer_class = DatabaseRoleSerializer\n    pagination_class = DefaultLimitOffsetPagination\n    access_policy = DatabaseRoleAccessPolicy\n\n    def get_queryset(self):\n        return self.access_policy.scope_queryset(\n            self.request, super().get_queryset()\n        )\n\n    def update(self, request, pk=None):\n        raise MethodNotAllowed(request.method)\n\n    def partial_update(self, request, pk=None):\n        raise MethodNotAllowed(request.method)\n\n\nclass SchemaRoleViewSet(AccessViewSetMixin, viewsets.ModelViewSet):\n    queryset = SchemaRole.objects.all().order_by('id')\n    serializer_class = SchemaRoleSerializer\n    pagination_class = DefaultLimitOffsetPagination\n    access_policy = SchemaRoleAccessPolicy\n\n    def get_queryset(self):\n        return self.access_policy.scope_queryset(\n            self.request, super().get_queryset()\n        )\n\n    def update(self, request, pk=None):\n        raise MethodNotAllowed(request.method)\n\n    def partial_update(self, request, pk=None):\n        raise MethodNotAllowed(request.method)\n", "path": "mathesar/api/ui/viewsets/users.py"}], "after_files": [{"content": "from django.conf import settings\nfrom django.contrib.auth.decorators import login_required\nfrom django.shortcuts import render, redirect, get_object_or_404\nfrom rest_framework import status\nfrom rest_framework.decorators import api_view\nfrom rest_framework.response import Response\n\nfrom mathesar.api.serializers.databases import DatabaseSerializer, TypeSerializer\nfrom mathesar.api.serializers.schemas import SchemaSerializer\nfrom mathesar.api.serializers.tables import TableSerializer\nfrom mathesar.api.serializers.queries import QuerySerializer\nfrom mathesar.api.ui.serializers.users import UserSerializer\nfrom mathesar.database.types import UIType\nfrom mathesar.models.base import Database, Schema, Table\nfrom mathesar.models.query import UIQuery\nfrom mathesar.state import reset_reflection\n\n\ndef get_schema_list(request, database):\n    schema_serializer = SchemaSerializer(\n        Schema.objects.filter(database=database),\n        many=True,\n        context={'request': request}\n    )\n    return schema_serializer.data\n\n\ndef get_database_list(request):\n    database_serializer = DatabaseSerializer(\n        Database.objects.all(),\n        many=True,\n        context={'request': request}\n    )\n    return database_serializer.data\n\n\ndef get_table_list(request, schema):\n    if schema is None:\n        return []\n    table_serializer = TableSerializer(\n        Table.objects.filter(schema=schema),\n        many=True,\n        context={'request': request}\n    )\n    return table_serializer.data\n\n\ndef get_queries_list(request, schema):\n    if schema is None:\n        return []\n    query_serializer = QuerySerializer(\n        UIQuery.objects.filter(base_table__schema=schema),\n        many=True,\n        context={'request': request}\n    )\n    return query_serializer.data\n\n\ndef get_ui_type_list(request, database):\n    if database is None:\n        return []\n    type_serializer = TypeSerializer(\n        UIType,\n        many=True,\n        context={'request': request}\n    )\n    return type_serializer.data\n\n\ndef get_user_data(request):\n    user_serializer = UserSerializer(\n        request.user,\n        many=False,\n        context={'request': request}\n    )\n    return user_serializer.data\n\n\ndef get_common_data(request, database, schema=None):\n    return {\n        'current_db': database.name if database else None,\n        'current_schema': schema.id if schema else None,\n        'schemas': get_schema_list(request, database),\n        'databases': get_database_list(request),\n        'tables': get_table_list(request, schema),\n        'queries': get_queries_list(request, schema),\n        'abstract_types': get_ui_type_list(request, database),\n        'user': get_user_data(request),\n        'live_demo_mode': getattr(settings, 'MATHESAR_LIVE_DEMO', False),\n    }\n\n\ndef get_current_database(request, db_name):\n    \"\"\"Get database from passed name, with fall back behavior.\"\"\"\n    if db_name is not None:\n        current_database = get_object_or_404(Database, name=db_name)\n    else:\n        request_database_name = request.GET.get('database')\n        try:\n            if request_database_name is not None:\n                # Try to get the database named specified in the request\n                current_database = Database.objects.get(name=request_database_name)\n            else:\n                # Try to get the first database available\n                current_database = Database.objects.order_by('id').first()\n        except Database.DoesNotExist:\n            current_database = None\n    return current_database\n\n\ndef get_current_schema(request, schema_id, database):\n    # if there's a schema ID passed in, try to retrieve the schema, or return a 404 error.\n    if schema_id is not None:\n        return get_object_or_404(Schema, id=schema_id)\n    else:\n        try:\n            # Try to get the first schema in the DB\n            return Schema.objects.filter(database=database).order_by('id').first()\n        except Schema.DoesNotExist:\n            return None\n\n\ndef render_schema(request, database, schema):\n    # if there's no schema available, redirect to the schemas page.\n    if not schema:\n        return redirect('schemas', db_name=database.name)\n    else:\n        # We are redirecting so that the correct URL is passed to the frontend.\n        return redirect('schema_home', db_name=database.name, schema_id=schema.id)\n\n\n@login_required\n@api_view(['POST'])\ndef reflect_all(_):\n    reset_reflection()\n    return Response(status=status.HTTP_200_OK)\n\n\n@login_required\ndef home(request):\n    database = get_current_database(request, None)\n    return redirect('schemas', db_name=database.name)\n\n\n@login_required\ndef schema_home(request, db_name, schema_id, **kwargs):\n    database = get_current_database(request, db_name)\n    schema = get_current_schema(request, schema_id, database)\n    return render(request, 'mathesar/index.html', {\n        'common_data': get_common_data(request, database, schema)\n    })\n\n\n@login_required\ndef schemas(request, db_name):\n    database = get_current_database(request, db_name)\n    return render(request, 'mathesar/index.html', {\n        'common_data': get_common_data(request, database, None)\n    })\n", "path": "mathesar/views.py"}, {"content": "from django.contrib.auth import get_user_model\nfrom rest_access_policy import AccessViewSetMixin\nfrom rest_framework import status, viewsets\nfrom rest_framework.decorators import action\nfrom rest_framework.exceptions import MethodNotAllowed\nfrom rest_framework.generics import get_object_or_404\nfrom rest_framework.response import Response\n\nfrom mathesar.api.ui.permissions.database_role import DatabaseRoleAccessPolicy\nfrom mathesar.api.ui.permissions.schema_role import SchemaRoleAccessPolicy\nfrom mathesar.api.ui.serializers.users import (\n    ChangePasswordSerializer, PasswordResetSerializer, UserSerializer, DatabaseRoleSerializer,\n    SchemaRoleSerializer,\n)\nfrom mathesar.api.pagination import DefaultLimitOffsetPagination\nfrom mathesar.api.ui.permissions.users import UserAccessPolicy\nfrom mathesar.models.users import DatabaseRole, SchemaRole\n\n\nclass UserViewSet(AccessViewSetMixin, viewsets.ModelViewSet):\n    queryset = get_user_model().objects.all().order_by('id')\n    serializer_class = UserSerializer\n    pagination_class = DefaultLimitOffsetPagination\n    access_policy = UserAccessPolicy\n\n    @action(methods=['post'], detail=True)\n    def password_reset(self, request, pk=None):\n        serializer = PasswordResetSerializer(data=request.data, context={'request': request})\n        serializer.is_valid(raise_exception=True)\n        user = get_object_or_404(get_user_model(), pk=pk)\n        password = serializer.validated_data[\"password\"]\n        user.set_password(password)\n        # Make sure we redirect user to change password set by the admin on login\n        user.password_change_needed = True\n        user.save()\n        return Response(status=status.HTTP_200_OK)\n\n    @action(methods=['post'], detail=False)\n    def password_change(self, request):\n        serializer = ChangePasswordSerializer(\n            instance=request.user,\n            data=request.data,\n            context={'request': request}\n        )\n        serializer.is_valid(raise_exception=True)\n        serializer.save()\n        return Response(status=status.HTTP_200_OK)\n\n\nclass DatabaseRoleViewSet(AccessViewSetMixin, viewsets.ModelViewSet):\n    queryset = DatabaseRole.objects.all().order_by('id')\n    serializer_class = DatabaseRoleSerializer\n    pagination_class = DefaultLimitOffsetPagination\n    access_policy = DatabaseRoleAccessPolicy\n\n    def get_queryset(self):\n        return self.access_policy.scope_queryset(\n            self.request, super().get_queryset()\n        )\n\n    def update(self, request, pk=None):\n        raise MethodNotAllowed(request.method)\n\n    def partial_update(self, request, pk=None):\n        raise MethodNotAllowed(request.method)\n\n\nclass SchemaRoleViewSet(AccessViewSetMixin, viewsets.ModelViewSet):\n    queryset = SchemaRole.objects.all().order_by('id')\n    serializer_class = SchemaRoleSerializer\n    pagination_class = DefaultLimitOffsetPagination\n    access_policy = SchemaRoleAccessPolicy\n\n    def get_queryset(self):\n        return self.access_policy.scope_queryset(\n            self.request, super().get_queryset()\n        )\n\n    def update(self, request, pk=None):\n        raise MethodNotAllowed(request.method)\n\n    def partial_update(self, request, pk=None):\n        raise MethodNotAllowed(request.method)\n", "path": "mathesar/api/ui/viewsets/users.py"}]}