Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/alembic/versions/275222846605_initial_ldap_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ async def _create_attribute_types(connection: AsyncConnection) -> None: # noqa:
AttributeTypeDTO(
oid=oid,
name=name,
ldap_display_name=name,
syntax="1.3.6.1.4.1.1466.115.121.1.15",
single_value=True,
no_user_modification=False,
Expand Down
5 changes: 5 additions & 0 deletions app/api/ldap_schema/adapters/attribute_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def _convert_update_uschema_to_dto(
return AttributeTypeDTO[None](
oid="",
name="",
ldap_display_name="",
syntax=request.syntax,
single_value=request.single_value,
no_user_modification=request.no_user_modification,
Expand All @@ -54,6 +55,10 @@ def _convert_update_uschema_to_dto(
AttributeTypeDTO[None],
recipe=[
allow_unlinked_optional(P[AttributeTypeDTO].id),
link_function(
lambda _: _.ldap_display_name or "",
P[AttributeTypeDTO].ldap_display_name,
),
link_function(
lambda _: DEFAULT_ATTRIBUTE_TYPE_SYNTAX,
P[AttributeTypeDTO].syntax,
Expand Down
1 change: 1 addition & 0 deletions app/api/ldap_schema/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class AttributeTypeSchema(BaseModel, Generic[_IdT]):
id: _IdT = Field(default=None) # type: ignore[assignment]
oid: str = Field(pattern=OID_REGEX_PATTERN, max_length=128)
name: str = Field(min_length=1, max_length=255)
ldap_display_name: str | None = Field(default=None, max_length=255)
syntax: str
single_value: bool
no_user_modification: bool
Expand Down
6 changes: 4 additions & 2 deletions app/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@
),
)

ATTRIBUTE_TYPE_OBJECT_CLASS_NAMES = ["top", "attributeSchema"]
OBJECT_CLASS_OBJECT_CLASS_NAMES = ["top", "classSchema"]

# NOTE: Second time load
ENTITY_TYPE_DTOS_V2: tuple[EntityTypeDTO, ...] = (
Expand All @@ -306,12 +308,12 @@
EntityTypeDTO(
name=EntityTypeNames.ATTRIBUTE_TYPE,
is_system=True,
object_class_names=["top", "attributeSchema"],
object_class_names=ATTRIBUTE_TYPE_OBJECT_CLASS_NAMES,
),
EntityTypeDTO(
name=EntityTypeNames.OBJECT_CLASS,
is_system=True,
object_class_names=["top", "classSchema"],
object_class_names=OBJECT_CLASS_OBJECT_CLASS_NAMES,
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
"""

from adaptix import P
from adaptix.conversion import (
allow_unlinked_optional,
get_converter,
link_function,
)
from adaptix.conversion import get_converter, link_function
from entities_legacy import AttributeTypeLegacy, ObjectClassLegacy
from sqlalchemy import delete, or_, select, update
from sqlalchemy.exc import IntegrityError
Expand All @@ -24,13 +20,27 @@
)
from repo.pg.tables import queryable_attr as qa

_convert_model_to_dto = get_converter(
AttributeTypeLegacy,
AttributeTypeDTO,
recipe=[
allow_unlinked_optional(P[AttributeTypeDTO].object_class_names),
],
)

def _convert_model_to_dto(
attr_type: AttributeTypeLegacy,
) -> AttributeTypeDTO[int]:
"""Convert AttributeTypeLegacy to AttributeTypeDTO."""
ldap_display_name = (
f"{attr_type.name[0].lower()}{attr_type.name.replace('-', '')[1:]}"
)
return AttributeTypeDTO[int](
oid=attr_type.oid,
name=ldap_display_name,
ldap_display_name=ldap_display_name,
syntax=attr_type.syntax,
single_value=attr_type.single_value,
no_user_modification=attr_type.no_user_modification,
is_system=attr_type.is_system,
system_flags=attr_type.system_flags,
is_included_anr=attr_type.is_included_anr,
)


_convert_dto_to_model = get_converter(
AttributeTypeDTO,
AttributeTypeLegacy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
allow_unlinked_optional(P[ObjectClassDTO].id),
allow_unlinked_optional(P[ObjectClassDTO].entity_type_names),
allow_unlinked_optional(P[AttributeTypeDTO].object_class_names),
link_function(
lambda _: "",
P[AttributeTypeDTO].ldap_display_name,
),
link_function(lambda x: x.kind, P[ObjectClassDTO].kind),
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
def _convert_model_to_dto(directory: Directory) -> AttributeTypeDTO[int]:
return AttributeTypeDTO[int](
id=directory.id,
name=directory.name,
name=directory.attributes_dict[Names.LDAP_DISPLAY_NAME][0],
ldap_display_name=directory.attributes_dict[Names.LDAP_DISPLAY_NAME][0],
oid=directory.attributes_dict[Names.OID][0],
syntax=directory.attributes_dict[Names.SYNTAX][0],
single_value=directory.attributes_dict[Names.SINGLE_VALUE][0] == "True", # noqa: E501
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from sqlalchemy.exc import IntegrityError

from abstract_service import AbstractService
from constants import ATTRIBUTE_TYPE_OBJECT_CLASS_NAMES
from enums import AuthorizationRules, EntityTypeNames
from ldap_protocol.ldap_schema.attribute_type.attribute_type_dao import (
AttributeTypeDAO,
Expand Down Expand Up @@ -71,12 +72,23 @@ async def get_all(self) -> list[AttributeTypeDTO[int]]:

async def create(self, dto: AttributeTypeDTO) -> None:
"""Create Attribute Type."""
if not dto.ldap_display_name:
dto.ldap_display_name = f"{dto.name[0].lower()}{dto.name.replace('-', '')[1:]}" # noqa: E501 # fmt: skip

_dto = CreateDirDTO(
name=dto.name,
entity_type_name=EntityTypeNames.ATTRIBUTE_TYPE,
attributes=(
AttributeDTO(name=Names.OID, values=[str(dto.oid)]),
AttributeDTO(name=Names.NAME, values=[str(dto.name)]),
AttributeDTO(
name=Names.OBJECT_CLASS,
values=ATTRIBUTE_TYPE_OBJECT_CLASS_NAMES,
),
AttributeDTO(
name=Names.LDAP_DISPLAY_NAME,
values=[str(dto.ldap_display_name)],
),
AttributeDTO(name=Names.SYNTAX, values=[str(dto.syntax)]),
AttributeDTO(
name=Names.SINGLE_VALUE,
Expand Down
2 changes: 2 additions & 0 deletions app/ldap_protocol/ldap_schema/attribute_type/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class AttributeTypeAttributeNames(StrEnum):

OID = "attributeID"
NAME = "name"
OBJECT_CLASS = "objectClass"
LDAP_DISPLAY_NAME = "lDAPDisplayName"
SYNTAX = "attributeSyntax"
SINGLE_VALUE = "isSingleValued"
NO_USER_MODIFICATION = "systemOnly"
Expand Down
1 change: 1 addition & 0 deletions app/ldap_protocol/ldap_schema/dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class AttributeTypeDTO(Generic[_IdT]):

oid: str
name: str
ldap_display_name: str
syntax: str
single_value: bool
no_user_modification: bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from sqlalchemy.exc import IntegrityError

from abstract_service import AbstractService
from constants import OBJECT_CLASS_OBJECT_CLASS_NAMES
from enums import AuthorizationRules, EntityTypeNames
from ldap_protocol.ldap_schema.attribute_type.attribute_type_dao import (
AttributeTypeDAO,
Expand Down Expand Up @@ -111,7 +112,7 @@ async def create(self, dto: ObjectClassDTO[None, str]) -> None:
attributes=(
AttributeDTO(
name=Names.OBJECT_CLASS,
values=["top", "classSchema"],
values=OBJECT_CLASS_OBJECT_CLASS_NAMES,
),
AttributeDTO(name=Names.OID, values=[str(dto.oid)]),
AttributeDTO(name=Names.NAME, values=[str(dto.name)]),
Expand Down
2 changes: 2 additions & 0 deletions app/ldap_protocol/ldap_schema/raw_definition_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ def collect_attribute_type_dto_from_raw(
if not name:
raise ValueError("Attribute Type name is required")

ldap_display_name = f"{name[0].lower()}{name.replace('-', '')[1:]}"
return AttributeTypeDTO(
oid=attribute_type_info.oid,
name=name,
ldap_display_name=ldap_display_name,
syntax=attribute_type_info.syntax,
single_value=attribute_type_info.single_value,
no_user_modification=attribute_type_info.no_user_modification,
Expand Down
2 changes: 1 addition & 1 deletion interface
2 changes: 2 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,7 @@ async def setup_session(
AttributeTypeDTO[None](
oid="1.2.3.4.5.6.7.8",
name="attr_with_bvalue",
ldap_display_name="attrWithBvalue",
syntax="1.3.6.1.4.1.1466.115.121.1.40", # Octet String
single_value=True,
no_user_modification=False,
Expand All @@ -1126,6 +1127,7 @@ async def setup_session(
AttributeTypeDTO[None](
oid="1.2.3.4.5.6.7.8.9",
name="testing_attr",
ldap_display_name="testingAttr",
syntax="1.3.6.1.4.1.1466.115.121.1.15",
single_value=True,
no_user_modification=False,
Expand Down
3 changes: 3 additions & 0 deletions tests/test_api/test_ldap_schema/test_attribute_type_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ async def test_create_one_attribute_type(
schema = AttributeTypeSchema[None](
oid="1.2.3.4",
name="testAttribute",
ldap_display_name="testAttribute",
syntax="1.3.6.1.4.1.1466.115.121.1.15",
single_value=True,
no_user_modification=False,
Expand All @@ -57,6 +58,7 @@ async def test_create_attribute_type_conflict_when_already_exists(
schema = AttributeTypeSchema(
oid="1.2.3.4",
name="testAttribute",
ldap_display_name="testAttribute",
syntax="1.3.6.1.4.1.1466.115.121.1.15",
single_value=True,
no_user_modification=False,
Expand Down Expand Up @@ -99,6 +101,7 @@ async def test_modify_one_attribute_type_raise_404(
schema = AttributeTypeSchema(
oid="1.2.3.4",
name="testAttributeType1",
ldap_display_name="testAttributeType1",
syntax="1.3.6.1.4.1.1466.115.121.1.15",
single_value=True,
no_user_modification=False,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"attribute_type_schema": AttributeTypeSchema(
oid="1.2.3.4",
name="testAttributeType0",
ldap_display_name="testAttributeType0",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

в схеме по-моему вообще не нужен ldap_display_name, он же автоматом в name проставляется

syntax="1.3.6.1.4.1.1466.115.121.1.15",
single_value=False,
no_user_modification=False,
Expand All @@ -32,6 +33,7 @@
"attribute_type_schema": AttributeTypeSchema(
oid="1.2.3.4",
name="testAttributeType1",
ldap_display_name="testAttributeType1",
syntax="1.3.6.1.4.1.1466.115.121.1.15",
single_value=True,
no_user_modification=False,
Expand All @@ -51,6 +53,7 @@
"attribute_type_schema": AttributeTypeSchema(
oid="1.2.3.4",
name="testAttributeType2",
ldap_display_name="testAttributeType2",
syntax="1.3.6.1.4.1.1466.115.121.1.15",
single_value=False,
no_user_modification=False,
Expand All @@ -73,6 +76,7 @@
AttributeTypeSchema(
oid="1.2.3.4",
name="testAttributeType1",
ldap_display_name="testAttributeType1",
syntax="1.3.6.1.4.1.1466.115.121.1.15",
single_value=True,
no_user_modification=False,
Expand All @@ -82,6 +86,7 @@
AttributeTypeSchema(
oid="1.2.3.4.5",
name="testAttributeType2",
ldap_display_name="testAttributeType2",
syntax="1.3.6.1.4.1.1466.115.121.1.15",
single_value=True,
no_user_modification=False,
Expand All @@ -100,6 +105,7 @@
AttributeTypeSchema(
oid="1.2.3.4",
name="testAttributeType1",
ldap_display_name="testAttributeType1",
syntax="1.3.6.1.4.1.1466.115.121.1.15",
single_value=True,
no_user_modification=False,
Expand Down
2 changes: 2 additions & 0 deletions tests/test_api/test_ldap_schema/test_entity_type_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ async def test_get_entity_type_attributes(http_client: AsyncClient) -> None:
AttributeTypeSchema(
oid="1.2.3.100",
name="testEntityTypeAttr1",
ldap_display_name="testEntityTypeAttr1",
syntax="1.3.6.1.4.1.1466.115.121.1.15",
single_value=True,
no_user_modification=False,
Expand All @@ -141,6 +142,7 @@ async def test_get_entity_type_attributes(http_client: AsyncClient) -> None:
AttributeTypeSchema(
oid="1.2.3.101",
name="testEntityTypeAttr2",
ldap_display_name="testEntityTypeAttr2",
syntax="1.3.6.1.4.1.1466.115.121.1.15",
single_value=True,
no_user_modification=False,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
{
"oid": "1.2.3.4",
"name": "testAttributeType1",
"ldap_display_name": "testAttributeType1",
"syntax": "1.3.6.1.4.1.1466.115.121.1.15",
"single_value": True,
"no_user_modification": False,
Expand All @@ -17,6 +18,7 @@
{
"oid": "1.2.3.4.5",
"name": "testAttributeType2",
"ldap_display_name": "testAttributeType2",
"syntax": "1.3.6.1.4.1.1466.115.121.1.15",
"single_value": True,
"no_user_modification": False,
Expand All @@ -26,6 +28,7 @@
{
"oid": "1.2.3.4.5.6",
"name": "testAttributeType3",
"ldap_display_name": "testAttributeType3",
"syntax": "1.3.6.1.4.1.1466.115.121.1.15",
"single_value": True,
"no_user_modification": False,
Expand Down Expand Up @@ -95,6 +98,7 @@
{
"oid": "1.2.3.4",
"name": "testAttributeType1",
"ldap_display_name": "testAttributeType1",
"syntax": "1.3.6.1.4.1.1466.115.121.1.15",
"single_value": True,
"no_user_modification": False,
Expand All @@ -121,6 +125,7 @@
{
"oid": "1.2.3.4",
"name": "testAttributeType1",
"ldap_display_name": "testAttributeType1",
"syntax": "1.3.6.1.4.1.1466.115.121.1.15",
"single_value": True,
"no_user_modification": False,
Expand All @@ -130,6 +135,7 @@
{
"oid": "1.2.3.4.5",
"name": "testAttributeType2",
"ldap_display_name": "testAttributeType2",
"syntax": "1.3.6.1.4.1.1466.115.121.1.15",
"single_value": True,
"no_user_modification": False,
Expand Down Expand Up @@ -159,6 +165,7 @@
{
"oid": "1.2.3.4",
"name": "testAttributeType1",
"ldap_display_name": "testAttributeType1",
"syntax": "1.3.6.1.4.1.1466.115.121.1.15",
"single_value": True,
"no_user_modification": False,
Expand All @@ -168,6 +175,7 @@
{
"oid": "1.2.3.4.5",
"name": "testAttributeType2",
"ldap_display_name": "testAttributeType2",
"syntax": "1.3.6.1.4.1.1466.115.121.1.15",
"single_value": True,
"no_user_modification": False,
Expand All @@ -177,6 +185,7 @@
{
"oid": "1.2.3.4.5.6",
"name": "testAttributeType3",
"ldap_display_name": "testAttributeType3",
"syntax": "1.3.6.1.4.1.1466.115.121.1.15",
"single_value": True,
"no_user_modification": False,
Expand Down
Loading
Loading