Skip to content

Commit

Permalink
Fix password (#78)
Browse files Browse the repository at this point in the history
Fix password
  • Loading branch information
vsdudakov authored Nov 20, 2024
1 parent 4f90aa0 commit f9368ca
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 29 deletions.
6 changes: 6 additions & 0 deletions docs/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ def read_cls_docstring(cls):

def get_versions():
return [
{
"version": "0.2.15",
"changes": [
"Fix password logic for user.",
],
},
{
"version": "0.2.14",
"changes": [
Expand Down
23 changes: 21 additions & 2 deletions docs/index.html

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion examples/fastapi_sqlalchemy/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

@register(User, sqlalchemy_sessionmaker=sqlalchemy_sessionmaker)
class UserModelAdmin(SqlAlchemyModelAdmin):
exclude = ("password",)
list_display = ("id", "username", "is_superuser")
list_display_links = ("id", "username")
list_filter = ("id", "username", "is_superuser")
Expand Down
1 change: 0 additions & 1 deletion examples/fastapi_tortoiseorm/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

@register(User)
class UserModelAdmin(TortoiseModelAdmin):
exclude = ("password",)
list_display = ("id", "username", "is_superuser")
list_display_links = ("id", "username")
list_filter = ("id", "username", "is_superuser")
Expand Down
19 changes: 19 additions & 0 deletions fastadmin/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,25 @@ async def change_password(self, id: UUID | int, password: str) -> None:
"""
raise NotImplementedError

async def save_model(self, id: UUID | int | None, payload: dict) -> dict | None:
"""This method is used to save orm/db model object.
:params id: an id of object.
:params payload: a payload from request.
:return: A saved object or None.
"""
obj = await super().save_model(id, payload)
fields = self.get_model_fields_with_widget_types(with_m2m=False, with_upload=False)
password_fields = [field.name for field in fields if field.form_widget_type == WidgetType.PasswordInput]
if obj and id is None and password_fields:
# save hashed password for create
pk_name = self.get_model_pk_name(self.model_cls)
pk = obj[pk_name]
password_values = [payload[field] for field in password_fields if field in payload]
if password_values:
await self.change_password(pk, password_values[0])
return obj


class DashboardWidgetAdmin:
title: str
Expand Down
36 changes: 18 additions & 18 deletions fastadmin/static/index.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion frontend/src/components/password-input/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test("Renders PasswordInput", () => {
const queryClient = new QueryClient();
render(
<TestProviders client={queryClient}>
<PasswordInput parentId="test" passwordModalForm={true} />
<PasswordInput parentId="test" />
</TestProviders>,
);
});
8 changes: 3 additions & 5 deletions frontend/src/components/password-input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ import { patchFetcher } from "@/fetchers/fetchers";
import { handleError } from "@/helpers/forms";

export interface IPasswordInput {
parentId: string;
passwordModalForm?: boolean;
parentId?: string;
}

export const PasswordInput: React.FC<IPasswordInput> = ({
parentId,
passwordModalForm,
...props
}) => {
const { t: _t } = useTranslation("PasswordInput");
Expand Down Expand Up @@ -56,7 +54,7 @@ export const PasswordInput: React.FC<IPasswordInput> = ({
mutate(data);
};

if (!passwordModalForm) {
if (!parentId) {
return <Input.Password {...props} />;
}
return (
Expand All @@ -67,7 +65,7 @@ export const PasswordInput: React.FC<IPasswordInput> = ({
<EditOutlined />
</Button>
</Tooltip>
<Input.Password {...props} />
<Input.Password {...props} disabled />
</Space.Compact>
<Modal
open={open}
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "fastadmin"
version = "0.2.14"
version = "0.2.15"
description = "FastAdmin is an easy-to-use Admin Dashboard App for FastAPI/Flask/Django inspired by Django Admin."
authors = ["Seva D <vsdudakov@gmail.com>"]
license = "MIT"
Expand Down

0 comments on commit f9368ca

Please sign in to comment.