-
Notifications
You must be signed in to change notification settings - Fork 0
Add: clear user password history #874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c321197
add: reset user pwd history task_523
milov-dmitriy d94a6dd
refactor: rename route task_523
milov-dmitriy b0b95e9
tests: fix task_523
milov-dmitriy 946c67a
Merge remote-tracking branch 'origin/dev' into add_user_password_hist…
milov-dmitriy 973176b
fix: PR comments task_523
milov-dmitriy f4c6fb1
Merge remote-tracking branch 'origin/dev' into add_user_password_hist…
milov-dmitriy 9974c43
fix: PR comments task_523
milov-dmitriy 4f90710
fix: file docstring task_523
milov-dmitriy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
app/alembic/versions/a99f866a7e3a_add_user_pwd_reset_permission.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| """Add user reset password history permission to Domain Admins role. | ||
|
|
||
| Revision ID: a99f866a7e3a | ||
| Revises: 6c858cc05da7 | ||
| Create Date: 2025-12-23 10:20:29.147813 | ||
|
|
||
| """ | ||
|
|
||
| from alembic import op | ||
| from dishka import AsyncContainer, Scope | ||
| from sqlalchemy import select | ||
| from sqlalchemy.ext.asyncio import AsyncConnection, AsyncSession | ||
|
|
||
| from entities import Role | ||
| from enums import AuthorizationRules, RoleConstants | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision: None | str = "a99f866a7e3a" | ||
| down_revision: None | str = "6c858cc05da7" | ||
| branch_labels: None | list[str] = None | ||
| depends_on: None | list[str] = None | ||
|
|
||
|
|
||
| def upgrade(container: AsyncContainer) -> None: | ||
| """Upgrade.""" | ||
|
|
||
| async def _add_api_permission(connection: AsyncConnection) -> None: # noqa: ARG001 | ||
| async with container(scope=Scope.REQUEST) as cnt: | ||
| session = await cnt.get(AsyncSession) | ||
|
|
||
| query = ( | ||
| select(Role) | ||
| .filter_by(name=RoleConstants.DOMAIN_ADMINS_ROLE_NAME) | ||
| ) # fmt: skip | ||
| role = await session.scalar(query) | ||
|
|
||
| if role: | ||
| role.permissions |= AuthorizationRules.USER_CLEAR_PASSWORD_HISTORY | ||
|
|
||
| op.run_async(_add_api_permission) | ||
|
|
||
|
|
||
| def downgrade(container: AsyncContainer) -> None: | ||
| """Downgrade.""" | ||
|
|
||
| async def _remove_api_permission(connection: AsyncConnection) -> None: # noqa: ARG001 | ||
| async with container(scope=Scope.REQUEST) as cnt: | ||
| session = await cnt.get(AsyncSession) | ||
|
|
||
| query = ( | ||
| select(Role) | ||
| .filter_by(name=RoleConstants.DOMAIN_ADMINS_ROLE_NAME) | ||
| ) # fmt: skip | ||
| role = await session.scalar(query) | ||
|
|
||
| if role: | ||
| role.permissions &= ~AuthorizationRules.USER_CLEAR_PASSWORD_HISTORY | ||
|
|
||
| op.run_async(_remove_api_permission) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| """User Password history router. | ||
|
|
||
| Copyright (c) 2024 MultiFactor | ||
| License: https://github.com/MultiDirectoryLab/MultiDirectory/blob/main/LICENSE | ||
| """ | ||
|
|
||
| from typing import Annotated | ||
|
|
||
| from dishka import FromDishka | ||
| from fastapi import Body, Depends, status | ||
| from fastapi_error_map.routing import ErrorAwareRouter | ||
| from fastapi_error_map.rules import rule | ||
|
|
||
| from api.auth.utils import verify_auth | ||
| from api.error_routing import ( | ||
| ERROR_MAP_TYPE, | ||
| DishkaErrorAwareRoute, | ||
| DomainErrorTranslator, | ||
| ) | ||
| from api.password_policy.adapter import UserPasswordHistoryResetFastAPIAdapter | ||
| from enums import DomainCodes | ||
| from ldap_protocol.identity.exceptions import ( | ||
| AuthorizationError, | ||
| UserNotFoundError, | ||
| ) | ||
|
|
||
| translator = DomainErrorTranslator(DomainCodes.PASSWORD_POLICY) | ||
|
|
||
| error_map: ERROR_MAP_TYPE = { | ||
| UserNotFoundError: rule( | ||
| status=status.HTTP_400_BAD_REQUEST, | ||
| translator=translator, | ||
| ), | ||
| AuthorizationError: rule( | ||
| status=status.HTTP_401_UNAUTHORIZED, | ||
| translator=translator, | ||
| ), | ||
| } | ||
|
|
||
| user_password_history_router = ErrorAwareRouter( | ||
| prefix="/user/password_history", | ||
Naksen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| dependencies=[Depends(verify_auth)], | ||
| tags=["User Password history"], | ||
| route_class=DishkaErrorAwareRoute, | ||
| ) | ||
|
|
||
|
|
||
| @user_password_history_router.post("/clear", error_map=error_map) | ||
| async def clear( | ||
| identity: Annotated[str, Body(examples=["admin"])], | ||
| adapter: FromDishka[UserPasswordHistoryResetFastAPIAdapter], | ||
| ) -> None: | ||
| await adapter.clear(identity) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule interface
updated
from 242c01 to a4bb0d
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.