-
Notifications
You must be signed in to change notification settings - Fork 0
Add: LDAP schema move from models to directories #958
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
47
commits into
dev
Choose a base branch
from
feature/1258_ldap_schema_move_from_models_to_directories
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
Show all changes
47 commits
Select commit
Hold shift + click to select a range
b534f21
refactor: attrTypeDao.create method 1258
milov-dmitriy 6c0ab42
Merge remote-tracking branch 'origin/dev' into feature/1258_ldap_sche…
milov-dmitriy 99a2fd7
fix: merge alembic heads task_1258
milov-dmitriy e347e84
add: attrType like as LDAP schema draft task_1258
milov-dmitriy 75f148a
tests: off task_1258
milov-dmitriy 15691b9
tests: fix draft task_1258
milov-dmitriy f1bd853
fix: tests draft task_1258
milov-dmitriy 590df66
preparation: objectClass refactoring task_1258
milov-dmitriy 9146424
refactor: objectClass draft task_1258
milov-dmitriy 448eb59
Merge remote-tracking branch 'origin/dev' into feature/1258_ldap_sche…
milov-dmitriy d7b5169
refactor: at task_1258
milov-dmitriy e2de5da
task_1258
milov-dmitriy 81abcd1
draft task_1258
milov-dmitriy d5167f5
draft task_1258
milov-dmitriy 979d716
draft task_1258
milov-dmitriy 0f6e2aa
fix: tests task_1258
milov-dmitriy 0bd0dd4
fix: tests task_1258
milov-dmitriy 6b77d50
sm fix
milov-dmitriy f5f09a0
tests: fix task_1258
milov-dmitriy 416448f
smfix
milov-dmitriy b69991a
refactor: migrations task_1258
milov-dmitriy fab9940
fixes
milov-dmitriy 10a224f
Merge remote-tracking branch 'origin/dev' into feature/1258_ldap_sche…
milov-dmitriy 11c4c14
fixes: task_1258
milov-dmitriy 0b852bc
fix: task_1258
milov-dmitriy f2e3beb
move files
milov-dmitriy 2edacc4
fix
milov-dmitriy 0ae946b
fixes
milov-dmitriy f992a00
rename
milov-dmitriy aa58052
tests: fix
milov-dmitriy 52f1541
fix: linter
milov-dmitriy 0ac5fe3
Merge remote-tracking branch 'origin/dev' into feature/1258_ldap_sche…
milov-dmitriy bad1d29
smfix
milov-dmitriy fc3a288
many fixes
milov-dmitriy 3a16b37
add: test and delete legacy BL task_1258
milov-dmitriy 2a79895
fix: linters
milov-dmitriy e903e26
smfixes
milov-dmitriy 0113d41
refactor
milov-dmitriy 956f712
todo
milov-dmitriy f29baee
delete: tables; refactor: naming
milov-dmitriy d07f652
refactor
milov-dmitriy b9c11c1
finally
milov-dmitriy 11f2e3c
Merge remote-tracking branch 'origin/dev' into feature/1258_ldap_sche…
milov-dmitriy 4a2ede1
fix: ruff
milov-dmitriy c86c14b
fix: migrations alembic head after merge dev
milov-dmitriy ba8d70f
add: copilot instructions
milov-dmitriy 09f257a
refactor
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # Instructions for Large PR Reviews | ||
|
|
||
| ## General Approach for Big Changesets | ||
| - Prioritize high-impact issues: security, performance, errors. | ||
| - Review files individually; skip minor style if >1000 lines total diff. | ||
| - Group feedback by file; limit to 5-10 key comments per file. | ||
| - If diff too large, comment on architecture/summary + top 3 files. |
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
271 changes: 146 additions & 125 deletions
271
app/alembic/versions/275222846605_initial_ldap_schema.py
Large diffs are not rendered by default.
Oops, something went wrong.
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
195 changes: 195 additions & 0 deletions
195
app/alembic/versions/708b01eaf025_convert_schema_to_ldap.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,195 @@ | ||
| """Migrate LDAP Schema data to Directory (like as LDAP). | ||
|
|
||
| Revision ID: 759d196145ae | ||
| Revises: 19d86e660cf2 | ||
| Create Date: 2026-02-24 13:18:06.715730 | ||
|
|
||
| """ | ||
|
|
||
| from alembic import op | ||
| from dishka import AsyncContainer, Scope | ||
| from sqlalchemy.ext.asyncio import AsyncConnection, AsyncSession | ||
|
|
||
| from constants import ENTITY_TYPE_DTOS_V2 | ||
| from ldap_protocol.ldap_schema._legacy.attribute_type.attribute_type_use_case import ( # noqa: E501 | ||
| AttributeTypeUseCaseLegacy, | ||
| ) | ||
| from ldap_protocol.ldap_schema._legacy.object_class.object_class_use_case import ( # noqa: E501 | ||
| ObjectClassUseCaseLegacy, | ||
| ) | ||
| from ldap_protocol.ldap_schema.attribute_type.attribute_type_use_case import ( | ||
| AttributeTypeUseCase, | ||
| ) | ||
| from ldap_protocol.ldap_schema.entity_type.entity_type_use_case import ( | ||
| EntityTypeUseCase, | ||
| ) | ||
| from ldap_protocol.ldap_schema.object_class.object_class_use_case import ( | ||
| ObjectClassUseCase, | ||
| ) | ||
| from ldap_protocol.roles.migrations_ace_dao import ( | ||
| AccessControlEntryMigrationsDAO, | ||
| ) | ||
| from ldap_protocol.utils.queries import get_base_directories | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision: None | str = "708b01eaf025" | ||
| down_revision: None | str = "df4287898910" | ||
| branch_labels: None | list[str] = None | ||
| depends_on: None | list[str] = None | ||
|
|
||
|
|
||
| def upgrade(container: AsyncContainer) -> None: | ||
| """Upgrade.""" | ||
| op.drop_constraint( | ||
| op.f("AccessControlEntries_attributeTypeId_fkey"), | ||
| "AccessControlEntries", | ||
| type_="foreignkey", | ||
| ) | ||
|
|
||
| async def _update_entity_types(connection: AsyncConnection) -> None: # noqa: ARG001 | ||
| async with container(scope=Scope.REQUEST) as cnt: | ||
| session = await cnt.get(AsyncSession) | ||
| entity_type_use_case = await cnt.get(EntityTypeUseCase) | ||
|
|
||
| if not await get_base_directories(session): | ||
| return | ||
|
|
||
| for entity_type_dto in ENTITY_TYPE_DTOS_V2: | ||
| await entity_type_use_case.create(entity_type_dto) | ||
|
|
||
| await session.commit() | ||
|
|
||
| async def _create_ldap_attributes(connection: AsyncConnection) -> None: # noqa: ARG001 | ||
| async with container(scope=Scope.REQUEST) as cnt: | ||
| session = await cnt.get(AsyncSession) | ||
| attribute_type_use_case = await cnt.get(AttributeTypeUseCase) | ||
| attribute_type_use_case_legacy = await cnt.get(AttributeTypeUseCaseLegacy) # noqa: E501 # fmt: skip | ||
|
|
||
| if not await get_base_directories(session): | ||
| return | ||
|
|
||
| attr_type_dtos = await attribute_type_use_case_legacy.get_all() | ||
| for attr_type_dto in attr_type_dtos: | ||
| await attribute_type_use_case.create(attr_type_dto) | ||
|
|
||
| await session.commit() | ||
|
|
||
| async def _create_ldap_object_classes(connection: AsyncConnection) -> None: # noqa: ARG001 | ||
| async with container(scope=Scope.REQUEST) as cnt: | ||
| session = await cnt.get(AsyncSession) | ||
| obj_cls_use_case_legacy = await cnt.get(ObjectClassUseCaseLegacy) | ||
| object_class_use_case = await cnt.get(ObjectClassUseCase) | ||
|
|
||
| if not await get_base_directories(session): | ||
| return | ||
|
|
||
| obj_class_dtos = await obj_cls_use_case_legacy.get_all() | ||
| for obj_class_dto in obj_class_dtos: | ||
| obj_class_dto.attribute_types_may = [ | ||
| _.name # type: ignore | ||
| for _ in obj_class_dto.attribute_types_may | ||
| ] | ||
| obj_class_dto.attribute_types_must = [ | ||
| _.name # type: ignore | ||
| for _ in obj_class_dto.attribute_types_must | ||
| ] | ||
| await object_class_use_case.create(obj_class_dto) # type: ignore | ||
|
|
||
| await session.commit() | ||
|
|
||
| async def _rebind_ace_attribute_types_to_directories( | ||
| connection: AsyncConnection, # noqa: ARG001 | ||
| ) -> None: | ||
| async with container(scope=Scope.REQUEST) as cnt: | ||
| session = await cnt.get(AsyncSession) | ||
| ace_dao = await cnt.get(AccessControlEntryMigrationsDAO) | ||
|
|
||
| if not await get_base_directories(session): | ||
| return | ||
|
|
||
| await ace_dao.upgrade() | ||
|
|
||
| op.run_async(_update_entity_types) | ||
| op.run_async(_create_ldap_attributes) | ||
| op.run_async(_create_ldap_object_classes) | ||
| op.run_async(_rebind_ace_attribute_types_to_directories) | ||
|
|
||
| op.create_foreign_key( | ||
| op.f("AccessControlEntries_directoryAttributeTypeId_fkey"), | ||
| "AccessControlEntries", | ||
| "Directory", | ||
| ["attributeTypeId"], | ||
| ["id"], | ||
| ondelete="CASCADE", | ||
| ) | ||
|
|
||
|
|
||
| def downgrade(container: AsyncContainer) -> None: | ||
| """Downgrade.""" | ||
|
|
||
| async def _rebind_ace_attribute_types_to_legacy( | ||
| connection: AsyncConnection, # noqa: ARG001 | ||
| ) -> None: | ||
| async with container(scope=Scope.REQUEST) as cnt: | ||
| session = await cnt.get(AsyncSession) | ||
| ace_dao = await cnt.get(AccessControlEntryMigrationsDAO) | ||
|
|
||
| if not await get_base_directories(session): | ||
| return | ||
|
|
||
| await ace_dao.downgrade() | ||
|
|
||
| async def _delete_ldap_attributes(connection: AsyncConnection) -> None: # noqa: ARG001 | ||
| async with container(scope=Scope.REQUEST) as cnt: | ||
| session = await cnt.get(AsyncSession) | ||
| attribute_type_use_case_legacy = await cnt.get(AttributeTypeUseCaseLegacy) # noqa: E501 # fmt: skip | ||
|
|
||
| if not await get_base_directories(session): | ||
| return | ||
|
|
||
| await attribute_type_use_case_legacy.delete_all_dirs() | ||
| await session.commit() | ||
|
|
||
| async def _delete_ldap_object_classes(connection: AsyncConnection) -> None: # noqa: ARG001 | ||
| async with container(scope=Scope.REQUEST) as cnt: | ||
| session = await cnt.get(AsyncSession) | ||
| obj_cls_use_case_legacy = await cnt.get(ObjectClassUseCaseLegacy) | ||
|
|
||
| if not await get_base_directories(session): | ||
| return | ||
|
|
||
| await obj_cls_use_case_legacy.delete_all_dirs() | ||
| await session.commit() | ||
|
|
||
| async def _delete_entity_types(connection: AsyncConnection) -> None: # noqa: ARG001 | ||
| async with container(scope=Scope.REQUEST) as cnt: | ||
| session = await cnt.get(AsyncSession) | ||
| entity_type_use_case = await cnt.get(EntityTypeUseCase) | ||
|
|
||
| if not await get_base_directories(session): | ||
| return | ||
|
|
||
| entity_type_names = [dto.name for dto in ENTITY_TYPE_DTOS_V2] | ||
|
|
||
| await entity_type_use_case.delete_all_by_names(entity_type_names) | ||
| await session.commit() | ||
|
|
||
| op.drop_constraint( | ||
| op.f("AccessControlEntries_directoryAttributeTypeId_fkey"), | ||
| "AccessControlEntries", | ||
| type_="foreignkey", | ||
| ) | ||
|
|
||
| op.run_async(_rebind_ace_attribute_types_to_legacy) | ||
| op.run_async(_delete_ldap_attributes) | ||
| op.run_async(_delete_ldap_object_classes) | ||
| op.run_async(_delete_entity_types) | ||
|
|
||
| op.create_foreign_key( | ||
| op.f("AccessControlEntries_attributeTypeId_fkey"), | ||
| "AccessControlEntries", | ||
| "AttributeTypes", | ||
| ["attributeTypeId"], | ||
| ["id"], | ||
| ondelete="CASCADE", | ||
| ) | ||
Oops, something went wrong.
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.