python-alfresco-api 1.2.0__py3-none-any.whl → 1.2.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -36,7 +36,12 @@ from .clients.conversion_utils import (
36
36
  # Import raw_clients to ensure they get packaged
37
37
  from . import raw_clients
38
38
 
39
- __version__ = "1.2.0"
39
+ # Tolerate Alfresco responses that omit the (spec-required) UserInfo.displayName for JIT /
40
+ # OAuth2 service-account users (defaults displayName -> id). See _compat.py.
41
+ from ._compat import install_shims as _install_shims
42
+ _install_shims()
43
+
44
+ __version__ = "1.2.1"
40
45
  __all__ = [
41
46
  # Factory & utilities
42
47
  "ClientFactory",
@@ -0,0 +1,55 @@
1
+ """Runtime compatibility shims for Alfresco responses that deviate from the OpenAPI spec.
2
+
3
+ Alfresco marks ``UserInfo.displayName`` as *required*, but omits it for JIT / OAuth2 service-account
4
+ users (e.g. ``service-account-*`` produced by the client-credentials grant). That makes the generated
5
+ ``UserInfo.from_dict`` raise ``KeyError('displayName')`` while parsing ``createdByUser`` /
6
+ ``modifiedByUser`` / ``owner`` on node responses.
7
+
8
+ This shim defaults ``displayName`` to ``id`` when it is absent, so parsing never crashes. It lives
9
+ outside ``raw_clients/`` so it survives client re-generation.
10
+
11
+ Scope (verified across all 7 generated raw clients): the ``UserInfo`` model — which is what
12
+ createdBy/modifiedBy/owner deserialize to — exists **only** in the core and search clients; the other
13
+ five (auth, discovery, model, search_sql, workflow) have no required-``displayName`` models. Core's
14
+ group models (``Group`` / ``GroupMember`` / ``GroupBodyCreate`` / ``GroupBodyUpdate``) also mark
15
+ ``displayName`` required, but groups always carry a display name and those models have *other* required
16
+ fields (e.g. ``Group.isRoot``), so they are not the JIT/service-account case and are left alone.
17
+ """
18
+
19
+ from importlib import import_module
20
+
21
+ # UserInfo covers every user reference (createdByUser / modifiedByUser / owner), in the two clients
22
+ # that define it.
23
+ _MODELS = (
24
+ ("python_alfresco_api.raw_clients.alfresco_core_client.core_client.models.user_info", "UserInfo"),
25
+ ("python_alfresco_api.raw_clients.alfresco_search_client.search_client.models.user_info", "UserInfo"),
26
+ )
27
+
28
+
29
+ def _patch_from_dict(cls) -> None:
30
+ if getattr(cls, "_display_name_shim_installed", False):
31
+ return
32
+ _orig_from_dict = cls.from_dict # bound classmethod
33
+
34
+ def _from_dict(src_dict, _orig=_orig_from_dict):
35
+ d = dict(src_dict)
36
+ if "displayName" not in d and "id" in d:
37
+ # Alfresco omitted the (spec-required) display name; fall back to the id.
38
+ d["displayName"] = d["id"]
39
+ return _orig(d)
40
+
41
+ cls.from_dict = staticmethod(_from_dict)
42
+ cls._display_name_shim_installed = True
43
+
44
+
45
+ def install_shims() -> None:
46
+ """Patch ``UserInfo.from_dict`` in the raw clients to tolerate a missing ``displayName``.
47
+
48
+ Idempotent — safe to call more than once.
49
+ """
50
+ for mod_path, cls_name in _MODELS:
51
+ try:
52
+ _patch_from_dict(getattr(import_module(mod_path), cls_name))
53
+ except Exception:
54
+ # Model not present in this build/layout — skip quietly.
55
+ continue