-
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
Open
milov-dmitriy
wants to merge
3
commits into
dev
Choose a base branch
from
add_user_password_history_reset_task_523
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
53 changes: 53 additions & 0 deletions
53
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,53 @@ | ||
| """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 | ||
| 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: # noqa: ARG001 | ||
| """Upgrade.""" | ||
|
|
||
| async def _add_api_permission(connection: AsyncConnection) -> None: | ||
| session = AsyncSession(bind=connection) | ||
| query = ( | ||
| select(Role) | ||
| .filter_by(name=RoleConstants.DOMAIN_ADMINS_ROLE_NAME) | ||
| ) # fmt: skip | ||
| role = (await session.scalars(query)).first() | ||
| if role: | ||
| role.permissions |= AuthorizationRules.USER_CLEAR_PASSWORD_HISTORY | ||
|
|
||
| op.run_async(_add_api_permission) | ||
|
|
||
|
|
||
| def downgrade(container: AsyncContainer) -> None: # noqa: ARG001 | ||
| """Downgrade.""" | ||
|
|
||
| async def _remove_api_permission(connection: AsyncConnection) -> None: | ||
| session = AsyncSession(bind=connection) | ||
| query = ( | ||
| select(Role) | ||
| .filter_by(name=RoleConstants.DOMAIN_ADMINS_ROLE_NAME) | ||
| ) # fmt: skip | ||
| role = (await session.scalars(query)).first() | ||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| """Password Policy router. | ||
|
|
||
| Copyright (c) 2024 MultiFactor | ||
| License: https://github.com/MultiDirectoryLab/MultiDirectory/blob/main/LICENSE | ||
| """ | ||
|
|
||
| from dishka import FromDishka | ||
| from fastapi import 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", | ||
| dependencies=[Depends(verify_auth)], | ||
| tags=["User Password history"], | ||
| route_class=DishkaErrorAwareRoute, | ||
| ) | ||
|
|
||
|
|
||
| @user_password_history_router.post("/clear/{user_name}", error_map=error_map) | ||
| async def clear( | ||
| user_name: str, | ||
| adapter: FromDishka[UserPasswordHistoryResetFastAPIAdapter], | ||
| ) -> None: | ||
| await adapter.clear(user_name) |
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 f31962 to 017b7f
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.