Load 1C access profiles groups and users
CI / python (push) Has been cancelled
CI / rust (push) Has been cancelled

This commit is contained in:
2026-05-21 18:17:27 +03:00
parent 3c7b1825c4
commit d0b74c05be
11 changed files with 599 additions and 0 deletions
@@ -2889,6 +2889,34 @@ async def get_normalized_project_summary(project_id: str) -> NormalizedProjectSu
return _normalized_project_summary(normalized)
@app.get("/projects/{project_id}/access")
async def get_project_access_model(project_id: str) -> dict:
normalized = _load_normalized_project(project_id)
if normalized is None:
raise HTTPException(status_code=404, detail="NormalizedProject not found")
return normalized.access.model_dump(mode="json")
@app.get("/projects/{project_id}/access/users/{user_name}")
async def get_project_access_user(project_id: str, user_name: str) -> dict:
normalized = _load_normalized_project(project_id)
if normalized is None:
raise HTTPException(status_code=404, detail="NormalizedProject not found")
wanted = user_name.casefold()
user = next(
(
item
for item in normalized.access.users
if item.name.casefold() == wanted or str(item.qualified_name or "").casefold() == wanted
),
None,
)
if user is None:
raise HTTPException(status_code=404, detail="Access user not found")
effective_roles = _effective_access_roles(normalized, user)
return {"user": user.model_dump(mode="json"), "effective_roles": effective_roles}
@app.get("/projects/{project_id}/imports/quality", response_model=ImportQualityResponse)
async def get_import_quality(project_id: str) -> ImportQualityResponse:
return _import_quality_response(project_id)
@@ -3985,6 +4013,9 @@ _FLOWCHART_KIND_LABELS = {
NodeKind.STYLE_ITEM: "Элементы стиля",
NodeKind.STYLE: "Стили",
NodeKind.LANGUAGE: "Языки",
NodeKind.ACCESS_PROFILE: "Профили групп доступа",
NodeKind.ACCESS_GROUP: "Группы доступа",
NodeKind.ACCESS_USER: "Пользователи ИБ",
NodeKind.HTTP_SERVICE: "HTTP-сервисы",
NodeKind.INTEGRATION_ENDPOINT: "Интеграции",
NodeKind.SCHEDULED_JOB: "Регламентные задания",
@@ -4008,6 +4039,8 @@ _FLOWCHART_EDGE_LABELS = {
EdgeKind.RUNS: "запускает",
EdgeKind.USES_INTEGRATION: "интеграция",
EdgeKind.HANDLES: "обработчик",
EdgeKind.ASSIGNS_ROLE: "назначает роль",
EdgeKind.MEMBER_OF: "участник",
}
_FLOWCHART_IMPORTANT_EDGES = {
@@ -4017,6 +4050,8 @@ _FLOWCHART_IMPORTANT_EDGES = {
EdgeKind.WRITES,
EdgeKind.HAS_ROLE,
EdgeKind.GRANTS_ACCESS,
EdgeKind.ASSIGNS_ROLE,
EdgeKind.MEMBER_OF,
EdgeKind.RUNS,
EdgeKind.USES_INTEGRATION,
EdgeKind.HANDLES,
@@ -4045,6 +4080,9 @@ _FLOWCHART_LOGIC_NODE_KINDS = {
NodeKind.XDTO_PACKAGE,
NodeKind.EXTENSION,
NodeKind.INTEGRATION_ENDPOINT,
NodeKind.ACCESS_PROFILE,
NodeKind.ACCESS_GROUP,
NodeKind.ACCESS_USER,
NodeKind.ROLE,
}
@@ -7210,6 +7248,39 @@ def _load_normalized_project(project_id: str) -> NormalizedProject | None:
return normalized
def _effective_access_roles(normalized: NormalizedProject, user) -> list[dict]:
roles = [item.model_dump(mode="json") for item in user.roles]
user_groups = {group.casefold() for group in user.groups}
groups = [
group
for group in normalized.access.groups
if group.name.casefold() in user_groups
or str(group.qualified_name or "").casefold() in user_groups
or user.name in group.users
]
profile_names = {
value.casefold()
for group in groups
for value in (group.profile, group.profile_qualified_name)
if value
}
profiles = [
profile
for profile in normalized.access.profiles
if profile.name.casefold() in profile_names or str(profile.qualified_name or "").casefold() in profile_names
]
for group in groups:
roles.extend(item.model_dump(mode="json") for item in group.roles)
for profile in profiles:
roles.extend(item.model_dump(mode="json") for item in profile.roles)
unique: dict[str, dict] = {}
for role in roles:
key = str(role.get("role_qualified_name") or role.get("role") or "").casefold()
if key:
unique.setdefault(key, role)
return sorted(unique.values(), key=lambda item: str(item.get("role") or "").casefold())
def _import_quality_response(project_id: str) -> ImportQualityResponse:
normalized = _load_normalized_project(project_id)
summary = _normalized_project_summary(normalized) if normalized is not None else None