Skip to content

Commit f9368ca

Browse files
authored
Fix password (#78)
Fix password
1 parent 4f90aa0 commit f9368ca

9 files changed

Lines changed: 69 additions & 29 deletions

File tree

docs/build.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ def read_cls_docstring(cls):
3939

4040
def get_versions():
4141
return [
42+
{
43+
"version": "0.2.15",
44+
"changes": [
45+
"Fix password logic for user.",
46+
],
47+
},
4248
{
4349
"version": "0.2.14",
4450
"changes": [

docs/index.html

Lines changed: 21 additions & 2 deletions
Large diffs are not rendered by default.

examples/fastapi_sqlalchemy/example.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
@register(User, sqlalchemy_sessionmaker=sqlalchemy_sessionmaker)
1212
class UserModelAdmin(SqlAlchemyModelAdmin):
13-
exclude = ("password",)
1413
list_display = ("id", "username", "is_superuser")
1514
list_display_links = ("id", "username")
1615
list_filter = ("id", "username", "is_superuser")

examples/fastapi_tortoiseorm/example.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
@register(User)
1212
class UserModelAdmin(TortoiseModelAdmin):
13-
exclude = ("password",)
1413
list_display = ("id", "username", "is_superuser")
1514
list_display_links = ("id", "username")
1615
list_filter = ("id", "username", "is_superuser")

fastadmin/models/base.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,25 @@ async def change_password(self, id: UUID | int, password: str) -> None:
621621
"""
622622
raise NotImplementedError
623623

624+
async def save_model(self, id: UUID | int | None, payload: dict) -> dict | None:
625+
"""This method is used to save orm/db model object.
626+
627+
:params id: an id of object.
628+
:params payload: a payload from request.
629+
:return: A saved object or None.
630+
"""
631+
obj = await super().save_model(id, payload)
632+
fields = self.get_model_fields_with_widget_types(with_m2m=False, with_upload=False)
633+
password_fields = [field.name for field in fields if field.form_widget_type == WidgetType.PasswordInput]
634+
if obj and id is None and password_fields:
635+
# save hashed password for create
636+
pk_name = self.get_model_pk_name(self.model_cls)
637+
pk = obj[pk_name]
638+
password_values = [payload[field] for field in password_fields if field in payload]
639+
if password_values:
640+
await self.change_password(pk, password_values[0])
641+
return obj
642+
624643

625644
class DashboardWidgetAdmin:
626645
title: str

fastadmin/static/index.min.js

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/src/components/password-input/index.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ test("Renders PasswordInput", () => {
99
const queryClient = new QueryClient();
1010
render(
1111
<TestProviders client={queryClient}>
12-
<PasswordInput parentId="test" passwordModalForm={true} />
12+
<PasswordInput parentId="test" />
1313
</TestProviders>,
1414
);
1515
});

frontend/src/components/password-input/index.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@ import { patchFetcher } from "@/fetchers/fetchers";
1717
import { handleError } from "@/helpers/forms";
1818

1919
export interface IPasswordInput {
20-
parentId: string;
21-
passwordModalForm?: boolean;
20+
parentId?: string;
2221
}
2322

2423
export const PasswordInput: React.FC<IPasswordInput> = ({
2524
parentId,
26-
passwordModalForm,
2725
...props
2826
}) => {
2927
const { t: _t } = useTranslation("PasswordInput");
@@ -56,7 +54,7 @@ export const PasswordInput: React.FC<IPasswordInput> = ({
5654
mutate(data);
5755
};
5856

59-
if (!passwordModalForm) {
57+
if (!parentId) {
6058
return <Input.Password {...props} />;
6159
}
6260
return (
@@ -67,7 +65,7 @@ export const PasswordInput: React.FC<IPasswordInput> = ({
6765
<EditOutlined />
6866
</Button>
6967
</Tooltip>
70-
<Input.Password {...props} />
68+
<Input.Password {...props} disabled />
7169
</Space.Compact>
7270
<Modal
7371
open={open}

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "fastadmin"
3-
version = "0.2.14"
3+
version = "0.2.15"
44
description = "FastAdmin is an easy-to-use Admin Dashboard App for FastAPI/Flask/Django inspired by Django Admin."
55
authors = ["Seva D <vsdudakov@gmail.com>"]
66
license = "MIT"

0 commit comments

Comments
 (0)