Skip to content

Conversation

@milov-dmitriy
Copy link
Collaborator

@milov-dmitriy milov-dmitriy commented Jan 29, 2026

Сделал ручку для rename директории: в ручке совмещена логика Modify + ModifyDN.

Сначала делаем ModifyDN, а затем Modify.
Именно такой порядок потому что если сделать rollback изменений (в случае падения в Modify) для ModifyDN сделать проще, чем наоборот.

"Проще" из-за того, что для ModifyDN мы можем узнать и старое значение и новое значение. Для Modify мы это так просто не узнаем.

Задача: 1110

@milov-dmitriy milov-dmitriy self-assigned this Jan 29, 2026
Copilot AI review requested due to automatic review settings January 29, 2026 17:26
@milov-dmitriy milov-dmitriy added python Pull requests that update Python code ldap labels Jan 29, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an API endpoint to rename an LDAP entry by running ModifyDN first and then Modify, including a rollback path when Modify fails.

Changes:

  • Introduced RenameRequest schema that orchestrates ModifyDN → Modify with rollback on Modify failure
  • Added /entry/rename route wired to the new request handler
  • Added API tests plus a fixture to create a computer entry for rollback testing

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
tests/test_api/test_main/test_router/test_rename.py Adds happy-path rename test and rollback-on-failure test
tests/test_api/test_main/conftest.py Adds fixture to create a test “computer” LDAP entry
app/api/main/schema.py Implements RenameRequest combining ModifyDN + Modify and rollback logic
app/api/main/router.py Exposes the new /entry/rename endpoint
interface Updates submodule pointer (interface dependency)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

return await modify_dn_request.handle_api(container)

async def _clear_session_cache(self, container: AsyncContainer) -> None:
session = await container.get(AsyncSession)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

мб логировать?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не пон, зачем?

название еще не совсем удачное мне показалось, сделал так: _expire_session_objects

assert data["resultCode"] == LDAPCodes.SUCCESS
assert data["search_result"][0]["object_name"] == "cn=admin2,dc=md,dc=test"

for attr in data["search_result"][0]["partial_attributes"]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тут тоже можно сжать. либо собрать в 1 цикл, либо сделать функцию проверки и снизу тоже заюзать

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

выписал это и отдельным пр сделаю по всем тестам

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

из вариантов такое могу предложить, вролде должно работать

sAMAccountName_found = False
displayName_found = False

for attr in data["search_result"][0]["partial_attributes"]:
    if attr["type"] == "sAMAccountName":
        assert attr["vals"][0] == "admin2"
        sAMAccountName_found = True
    elif attr["type"] == "displayName":
        assert attr["vals"][0] == "Administrator"
        displayName_found = True

    if sAMAccountName_found and displayName_found:
        break

if not sAMAccountName_found:
    raise Exception("User without sAMAccountName")
if not displayName_found:
    raise Exception("User without displayName")
#----------------------------
attrs_dict = {attr["type"]: attr["vals"][0] 
              for attr in data["search_result"][0]["partial_attributes"]}

assert attrs_dict.get("sAMAccountName") == "admin2"
assert attrs_dict.get("displayName") == "Administrator"

Combines ModifyDN and Modify operations.
"""

object: str
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

сделай _object, чтобы не трогать зарезервированное

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вообще, в ModifyDNRequest аналогичное поле называется entry. Мб сделать более менее едино?

Copy link
Collaborator Author

@milov-dmitriy milov-dmitriy Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

делал по аналогии с modify + делал по схеме как в ТЗ

нам бы везде поменять нейминг у реквестов, сейчас предлагаю везде делать по одному неидеальному шаблону

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

это надо в общий рефакторинг реквестов уносить, сейчас мы это красиво не обыграем, только разменом костыль на костыль

@milov-dmitriy milov-dmitriy requested review from Misha-Shvets and rimu-stack and removed request for Misha-Shvets January 30, 2026 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ldap python Pull requests that update Python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants