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
Empty file.
22 changes: 22 additions & 0 deletions libzapi/application/commands/custom_data/custom_object_cmds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from dataclasses import dataclass


@dataclass(frozen=True, slots=True)
class CreateCustomObjectCmd:
key: str
title: str
title_pluralized: str
include_in_list_view: bool = False
description: str = ""
allows_photos: bool = False
allows_attachments: bool = False


@dataclass(frozen=True, slots=True)
class UpdateCustomObjectCmd:
title: str | None = None
title_pluralized: str | None = None
description: str | None = None
include_in_list_view: bool | None = None
allows_photos: bool | None = None
allows_attachments: bool | None = None
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from __future__ import annotations

from dataclasses import dataclass


@dataclass(frozen=True, slots=True)
class CreateCustomObjectFieldCmd:
type: str
key: str
title: str
description: str = ""
active: bool = True
position: int = 0
regexp_for_validation: str | None = None
custom_field_options: list[dict] | None = None
relationship_target_type: str | None = None
relationship_filter: dict | None = None
tag: str | None = None


@dataclass(frozen=True, slots=True)
class UpdateCustomObjectFieldCmd:
title: str | None = None
description: str | None = None
active: bool | None = None
position: int | None = None
custom_field_options: list[dict] | None = None
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from __future__ import annotations

from dataclasses import dataclass, field


@dataclass(frozen=True, slots=True)
class CreateCustomObjectRecordCmd:
name: str
custom_object_fields: dict[str, str] = field(default_factory=dict)
external_id: str | None = None


@dataclass(frozen=True, slots=True)
class UpdateCustomObjectRecordCmd:
custom_object_fields: dict[str, str] = field(default_factory=dict)


@dataclass(frozen=True, slots=True)
class BulkJobCmd:
action: str
items: list[dict] = field(default_factory=list)


@dataclass(frozen=True, slots=True)
class FilteredSearchCmd:
filter: dict = field(default_factory=dict)
26 changes: 26 additions & 0 deletions libzapi/application/commands/custom_data/object_trigger_cmds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from __future__ import annotations

from dataclasses import dataclass, field


@dataclass(frozen=True, slots=True)
class CreateObjectTriggerCmd:
title: str
conditions: dict
actions: list[dict]
active: bool = True
description: str = ""


@dataclass(frozen=True, slots=True)
class UpdateObjectTriggerCmd:
title: str | None = None
conditions: dict | None = None
actions: list[dict] | None = None
active: bool | None = None
description: str | None = None


@dataclass(frozen=True, slots=True)
class UpdateManyTriggersCmd:
triggers: list[dict] = field(default_factory=list)
27 changes: 27 additions & 0 deletions libzapi/application/commands/custom_data/permission_cmds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from __future__ import annotations

from dataclasses import dataclass, field


@dataclass(frozen=True, slots=True)
class UpdatePermissionPolicyCmd:
create: str | None = None
read: str | None = None
update: str | None = None
delete: str | None = None
create_rule_id: str | None = None
read_rule_id: str | None = None
update_rule_id: str | None = None
delete_rule_id: str | None = None


@dataclass(frozen=True, slots=True)
class CreateAccessRuleCmd:
name: str
conditions: dict = field(default_factory=dict)


@dataclass(frozen=True, slots=True)
class UpdateAccessRuleCmd:
name: str | None = None
conditions: dict | None = None
14 changes: 12 additions & 2 deletions libzapi/application/services/custom_data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
from libzapi.application.services.custom_data.custom_objects_service import CustomObjectsService
from libzapi.application.services.custom_data.access_rules_service import AccessRulesService
from libzapi.application.services.custom_data.custom_object_fields_service import CustomObjectFieldsService
from libzapi.application.services.custom_data.custom_object_records import CustomObjectRecordsService
from libzapi.infrastructure.http.auth import oauth_headers, api_token_headers
from libzapi.application.services.custom_data.custom_objects_service import CustomObjectsService
from libzapi.application.services.custom_data.object_triggers_service import ObjectTriggersService
from libzapi.application.services.custom_data.permission_policies_service import PermissionPoliciesService
from libzapi.application.services.custom_data.record_attachments_service import RecordAttachmentsService
from libzapi.application.services.custom_data.record_events_service import RecordEventsService
from libzapi.infrastructure.http.auth import api_token_headers, oauth_headers
from libzapi.infrastructure.http.client import HttpClient
import libzapi.infrastructure.api_clients.custom_data as api

Expand All @@ -23,3 +28,8 @@ def __init__(
self.custom_objects = CustomObjectsService(api.CustomObjectApiClient(http))
self.custom_object_fields = CustomObjectFieldsService(api.CustomObjectFieldApiClient(http))
self.custom_object_records = CustomObjectRecordsService(api.CustomObjectRecordApiClient(http))
self.record_events = RecordEventsService(api.RecordEventApiClient(http))
self.object_triggers = ObjectTriggersService(api.ObjectTriggerApiClient(http))
self.record_attachments = RecordAttachmentsService(api.RecordAttachmentApiClient(http))
self.permission_policies = PermissionPoliciesService(api.PermissionPolicyApiClient(http))
self.access_rules = AccessRulesService(api.AccessRuleApiClient(http))
30 changes: 30 additions & 0 deletions libzapi/application/services/custom_data/access_rules_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from typing import Iterator

from libzapi.application.commands.custom_data.permission_cmds import CreateAccessRuleCmd, UpdateAccessRuleCmd
from libzapi.domain.models.custom_data.access_rule import AccessRule
from libzapi.infrastructure.api_clients.custom_data import AccessRuleApiClient


class AccessRulesService:
def __init__(self, client: AccessRuleApiClient) -> None:
self._client = client

def list_all(self, custom_object_key: str) -> Iterator[AccessRule]:
return self._client.list_all(custom_object_key=custom_object_key)

def get(self, custom_object_key: str, rule_id: str) -> AccessRule:
return self._client.get(custom_object_key=custom_object_key, rule_id=rule_id)

def create(self, custom_object_key: str, name: str, conditions: dict | None = None) -> AccessRule:
cmd = CreateAccessRuleCmd(name=name, conditions=conditions or {})
return self._client.create(custom_object_key=custom_object_key, cmd=cmd)

def update(self, custom_object_key: str, rule_id: str, **kwargs) -> AccessRule:
cmd = UpdateAccessRuleCmd(**kwargs)
return self._client.update(custom_object_key=custom_object_key, rule_id=rule_id, cmd=cmd)

def delete(self, custom_object_key: str, rule_id: str) -> None:
self._client.delete(custom_object_key=custom_object_key, rule_id=rule_id)

def definitions(self, custom_object_key: str) -> dict:
return self._client.definitions(custom_object_key=custom_object_key)
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
from __future__ import annotations

from typing import Iterator

from libzapi.application.commands.custom_data.custom_object_field_cmds import (
CreateCustomObjectFieldCmd,
UpdateCustomObjectFieldCmd,
)
from libzapi.domain.models.custom_data.custom_object_field import CustomObjectField
from libzapi.infrastructure.api_clients.custom_data import CustomObjectFieldApiClient

Expand All @@ -15,3 +21,17 @@ def list_all(self, custom_object_key: str) -> Iterator[CustomObjectField]:

def get(self, custom_object_key: str, custom_object_field_id: int) -> CustomObjectField:
return self._client.get(custom_object_key=custom_object_key, custom_object_field_id=custom_object_field_id)

def create(self, custom_object_key: str, type: str, key: str, title: str, **kwargs) -> CustomObjectField:
cmd = CreateCustomObjectFieldCmd(type=type, key=key, title=title, **kwargs)
return self._client.create(custom_object_key=custom_object_key, cmd=cmd)

def update(self, custom_object_key: str, field_id: int, **kwargs) -> CustomObjectField:
cmd = UpdateCustomObjectFieldCmd(**kwargs)
return self._client.update(custom_object_key=custom_object_key, field_id=field_id, cmd=cmd)

def delete(self, custom_object_key: str, field_id: int) -> None:
self._client.delete(custom_object_key=custom_object_key, field_id=field_id)

def reorder(self, custom_object_key: str, field_ids: list[int]) -> None:
self._client.reorder(custom_object_key=custom_object_key, field_ids=field_ids)
66 changes: 66 additions & 0 deletions libzapi/application/services/custom_data/custom_object_records.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
from __future__ import annotations

from typing import Iterator, Optional, Iterable

from libzapi.application.commands.custom_data.custom_object_record_cmds import (
BulkJobCmd,
CreateCustomObjectRecordCmd,
FilteredSearchCmd,
UpdateCustomObjectRecordCmd,
)
from libzapi.domain.models.custom_data.custom_object_record import CustomObjectRecord
from libzapi.domain.shared_objects.count_snapshot import CountSnapshot
from libzapi.domain.shared_objects.custom_object_limit import CustomObjectLimit
from libzapi.domain.shared_objects.job_status import JobStatus
from libzapi.infrastructure.api_clients.custom_data import CustomObjectRecordApiClient
from libzapi.infrastructure.api_clients.custom_data.custom_object_record import SortOrder, SortType

Expand All @@ -26,5 +36,61 @@ def list_all(
def get(self, custom_object_key: str, custom_object_record_id: str) -> CustomObjectRecord:
return self._client.get(custom_object_key=custom_object_key, custom_object_record_id=custom_object_record_id)

def create(
self, custom_object_key: str, name: str, custom_object_fields: dict[str, str] | None = None, **kwargs
) -> CustomObjectRecord:
cmd = CreateCustomObjectRecordCmd(name=name, custom_object_fields=custom_object_fields or {}, **kwargs)
return self._client.create(custom_object_key=custom_object_key, cmd=cmd)

def update(
self, custom_object_key: str, record_id: str, custom_object_fields: dict[str, str]
) -> CustomObjectRecord:
cmd = UpdateCustomObjectRecordCmd(custom_object_fields=custom_object_fields)
return self._client.update(custom_object_key=custom_object_key, record_id=record_id, cmd=cmd)

def upsert(
self,
custom_object_key: str,
name: str,
custom_object_fields: dict[str, str] | None = None,
*,
external_id: str | None = None,
upsert_by_name: str | None = None,
**kwargs,
) -> CustomObjectRecord:
cmd = CreateCustomObjectRecordCmd(name=name, custom_object_fields=custom_object_fields or {}, **kwargs)
return self._client.upsert(
custom_object_key=custom_object_key, cmd=cmd, external_id=external_id, name=upsert_by_name
)

def delete(self, custom_object_key: str, record_id: str) -> None:
self._client.delete(custom_object_key=custom_object_key, record_id=record_id)

def delete_by_external_id(self, custom_object_key: str, external_id: str) -> None:
self._client.delete_by_external_id(custom_object_key=custom_object_key, external_id=external_id)

def delete_by_name(self, custom_object_key: str, name: str) -> None:
self._client.delete_by_name(custom_object_key=custom_object_key, name=name)

def count(self, custom_object_key: str) -> CountSnapshot:
return self._client.count(custom_object_key=custom_object_key)

def search(self, custom_object_key: str, query: str, sort: str | None = None) -> Iterator[CustomObjectRecord]:
return self._client.search(custom_object_key=custom_object_key, query=query, sort=sort)

def filtered_search(self, custom_object_key: str, filter: dict) -> Iterator[CustomObjectRecord]:
cmd = FilteredSearchCmd(filter=filter)
return self._client.filtered_search(custom_object_key=custom_object_key, cmd=cmd)

def autocomplete(self, custom_object_key: str, name: str) -> Iterator[CustomObjectRecord]:
return self._client.autocomplete(custom_object_key=custom_object_key, name=name)

def bulk_job(self, custom_object_key: str, action: str, items: list[dict]) -> JobStatus:
cmd = BulkJobCmd(action=action, items=items)
return self._client.bulk_job(custom_object_key=custom_object_key, cmd=cmd)

def incremental_export(self, custom_object_key: str, start_time: int) -> Iterator[CustomObjectRecord]:
return self._client.incremental_export(custom_object_key=custom_object_key, start_time=start_time)

def limit(self) -> CustomObjectLimit:
return self._client.limit()
12 changes: 12 additions & 0 deletions libzapi/application/services/custom_data/custom_objects_service.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Iterator

from libzapi.application.commands.custom_data.custom_object_cmds import CreateCustomObjectCmd, UpdateCustomObjectCmd
from libzapi.domain.models.custom_data.custom_object import CustomObject
from libzapi.domain.shared_objects.custom_object_limit import CustomObjectLimit
from libzapi.infrastructure.api_clients.custom_data import CustomObjectApiClient
Expand All @@ -17,5 +18,16 @@ def list_all(self) -> Iterator[CustomObject]:
def get(self, custom_object_id: str) -> CustomObject:
return self._client.get(custom_object_id=custom_object_id)

def create(self, key: str, title: str, title_pluralized: str, **kwargs) -> CustomObject:
cmd = CreateCustomObjectCmd(key=key, title=title, title_pluralized=title_pluralized, **kwargs)
return self._client.create(cmd=cmd)

def update(self, custom_object_key: str, **kwargs) -> CustomObject:
cmd = UpdateCustomObjectCmd(**kwargs)
return self._client.update(custom_object_key=custom_object_key, cmd=cmd)

def delete(self, custom_object_key: str) -> None:
self._client.delete(custom_object_key=custom_object_key)

def limit(self) -> CustomObjectLimit:
return self._client.limit()
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from __future__ import annotations

from typing import Iterator

from libzapi.application.commands.custom_data.object_trigger_cmds import (
CreateObjectTriggerCmd,
UpdateManyTriggersCmd,
UpdateObjectTriggerCmd,
)
from libzapi.domain.models.custom_data.object_trigger import ObjectTrigger
from libzapi.infrastructure.api_clients.custom_data import ObjectTriggerApiClient


class ObjectTriggersService:
def __init__(self, client: ObjectTriggerApiClient) -> None:
self._client = client

def list_all(self, custom_object_key: str) -> Iterator[ObjectTrigger]:
return self._client.list_all(custom_object_key=custom_object_key)

def list_active(self, custom_object_key: str) -> Iterator[ObjectTrigger]:
return self._client.list_active(custom_object_key=custom_object_key)

def search(self, custom_object_key: str, query: str) -> Iterator[ObjectTrigger]:
return self._client.search(custom_object_key=custom_object_key, query=query)

def get(self, custom_object_key: str, trigger_id: int) -> ObjectTrigger:
return self._client.get(custom_object_key=custom_object_key, trigger_id=trigger_id)

def definitions(self, custom_object_key: str) -> dict:
return self._client.definitions(custom_object_key=custom_object_key)

def create(
self, custom_object_key: str, title: str, conditions: dict, actions: list[dict], **kwargs
) -> ObjectTrigger:
cmd = CreateObjectTriggerCmd(title=title, conditions=conditions, actions=actions, **kwargs)
return self._client.create(custom_object_key=custom_object_key, cmd=cmd)

def update(self, custom_object_key: str, trigger_id: int, **kwargs) -> ObjectTrigger:
cmd = UpdateObjectTriggerCmd(**kwargs)
return self._client.update(custom_object_key=custom_object_key, trigger_id=trigger_id, cmd=cmd)

def update_many(self, custom_object_key: str, triggers: list[dict]) -> list[ObjectTrigger]:
cmd = UpdateManyTriggersCmd(triggers=triggers)
return self._client.update_many(custom_object_key=custom_object_key, cmd=cmd)

def delete(self, custom_object_key: str, trigger_id: int) -> None:
self._client.delete(custom_object_key=custom_object_key, trigger_id=trigger_id)

def delete_many(self, custom_object_key: str, ids: list[int]) -> None:
self._client.delete_many(custom_object_key=custom_object_key, ids=ids)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from typing import Iterator

from libzapi.application.commands.custom_data.permission_cmds import UpdatePermissionPolicyCmd
from libzapi.domain.models.custom_data.permission_policy import PermissionPolicy
from libzapi.infrastructure.api_clients.custom_data import PermissionPolicyApiClient


class PermissionPoliciesService:
def __init__(self, client: PermissionPolicyApiClient) -> None:
self._client = client

def list_all(self, custom_object_key: str) -> Iterator[PermissionPolicy]:
return self._client.list_all(custom_object_key=custom_object_key)

def get(self, custom_object_key: str, policy_id: str) -> PermissionPolicy:
return self._client.get(custom_object_key=custom_object_key, policy_id=policy_id)

def update(self, custom_object_key: str, policy_id: str, **kwargs) -> PermissionPolicy:
cmd = UpdatePermissionPolicyCmd(**kwargs)
return self._client.update(custom_object_key=custom_object_key, policy_id=policy_id, cmd=cmd)
Loading
Loading