(self, activity: Any)
| 870 | ) |
| 871 | |
| 872 | def _normalize_admin_activity(self, activity: Any) -> Optional[dict[str, Any]]: |
| 873 | if not isinstance(activity, dict): |
| 874 | return None |
| 875 | |
| 876 | action = self._normalize_admin_activity_text(activity.get("action")) |
| 877 | target_type = self._normalize_admin_activity_text( |
| 878 | activity.get("targetType") or activity.get("target_type") or "system" |
| 879 | ) |
| 880 | if not action: |
| 881 | return None |
| 882 | |
| 883 | target_name = self._normalize_admin_activity_text( |
| 884 | activity.get("targetName") or activity.get("target_name") |
| 885 | ) |
| 886 | created_at = activity.get("createdAt") or activity.get("created_at") |
| 887 | if isinstance(created_at, datetime): |
| 888 | created_at = created_at.isoformat() |
| 889 | created_at = str(created_at or "") |
| 890 | if not created_at: |
| 891 | return None |
| 892 | |
| 893 | target_id = activity.get("targetId") |
| 894 | if target_id is None: |
| 895 | target_id = activity.get("target_id") |
| 896 | |
| 897 | count = activity.get("count", 1) |
| 898 | try: |
| 899 | count = max(int(count), 1) |
| 900 | except (TypeError, ValueError): |
| 901 | count = 1 |
| 902 | |
| 903 | meta = activity.get("meta") |
| 904 | if not isinstance(meta, dict): |
| 905 | meta = {} |
| 906 | |
| 907 | activity_id = self._normalize_admin_activity_text(activity.get("id")) |
| 908 | if not activity_id: |
| 909 | activity_id = self._build_admin_activity_id( |
| 910 | action=action, |
| 911 | target_type=target_type, |
| 912 | target_id=target_id, |
| 913 | target_name=target_name, |
| 914 | timestamp=None, |
| 915 | seed=created_at, |
| 916 | ) |
| 917 | |
| 918 | return { |
| 919 | "id": activity_id, |
| 920 | "action": action, |
| 921 | "targetType": target_type, |
| 922 | "target_type": target_type, |
| 923 | "targetId": target_id, |
| 924 | "target_id": target_id, |
| 925 | "targetName": target_name, |
| 926 | "target_name": target_name, |
| 927 | "count": count, |
| 928 | "meta": meta, |
| 929 | "createdAt": created_at, |
no test coverage detected