Skip to content
Merged
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
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

## Unreleased

### Added

- **`list_pending_reasons`, `iter_pending_reasons`,
`get_ticket_pending_reason`, `set_ticket_pending_reason` and
`clear_ticket_pending_reason`** on both clients, from a new
`PendingReasonMixin`. The catalogue is read from the v2
`/Assistance/PendingReason` route; a ticket's pending-reason item goes
through the legacy v1 API, because the v2 item schema omits the
catalogue id and no v2 route writes an item. The three ticket methods
need the v1 session and raise `RuntimeError` without one.
`set_ticket_pending_reason` creates or updates the item after reading
it and does not change the ticket status.
- **`PendingReason` and `PendingReasonItem`** read models, exported from
the package root and from `glpi_python_client.models`.
### Fixed

- **A success response whose body is not JSON now raises `GlpiProtocolError`
Expand Down
19 changes: 19 additions & 0 deletions docs/api_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,25 @@ Ticket Team Members
:undoc-members:
:show-inheritance:

Pending reasons
---------------

Models for the GLPI pending-reason catalogue (v2) and a ticket's pending
reason item (legacy v1). The companion mixin methods are exposed on
:class:`GlpiClient` / :class:`AsyncGlpiClient` as ``list_pending_reasons``,
``iter_pending_reasons``, ``get_ticket_pending_reason``,
``set_ticket_pending_reason`` and ``clear_ticket_pending_reason``.

.. autoclass:: PendingReason
:members:
:undoc-members:
:show-inheritance:

.. autoclass:: PendingReasonItem
:members:
:undoc-members:
:show-inheritance:

Documents
---------

Expand Down
66 changes: 63 additions & 3 deletions docs/user_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Neither is a wrapper around the other; both are the same code, as

Both clients speak the GLPI **v2** high-level API and fall back to the
legacy v1 API for features that are not exposed by v2, currently
binary document uploads and the ``Fields`` plugin custom-field
helpers. They expose the exact same endpoint methods and accept the
binary document uploads, the ``Fields`` plugin custom-field
helpers and the ticket pending-reason item methods. They expose the exact same endpoint methods and accept the
same constructor arguments.
Public methods always return Pydantic models (or simple Python types)
and never raw dictionaries.
Expand Down Expand Up @@ -126,7 +126,9 @@ Optional constructor arguments
* ``v1_base_url`` and ``v1_user_token`` — together enable the legacy v1
fallback used by :meth:`GlpiClient.upload_document` and the
``Fields`` plugin helpers such as
:meth:`GlpiClient.get_ticket_custom_fields`.
:meth:`GlpiClient.get_ticket_custom_fields`, and the ticket
pending-reason methods such as
:meth:`GlpiClient.set_ticket_pending_reason`.

``from_env``
~~~~~~~~~~~~
Expand Down Expand Up @@ -1085,6 +1087,64 @@ to ``list_item_plugin_field_rows``, ``create_item_plugin_field_row``,
or ``update_item_plugin_field_row`` only when you need the raw v1 row
shape.

Pending reasons
~~~~~~~~~~~~~~~

A pause is ticket status ``4`` (Pending) plus at most one item linking
the ticket to an entry of the pending-reason catalogue. The catalogue is
read from the v2 API; the ticket's item needs the legacy v1 session
(``v1_base_url`` and ``v1_user_token``), because the v2 item schema does
not say *which* reason a ticket carries and no v2 route writes an item.
Without the v1 session the three ticket methods raise ``RuntimeError``.

.. code-block:: python

from glpi_python_client import GlpiClient, GlpiTicketStatus, PatchTicket

with GlpiClient(
glpi_api_url="https://glpi.example.com/api.php/v2",
server_timezone="Europe/Paris",
client_id="oauth-client-id",
client_secret="oauth-client-secret",
username="api-user",
password="api-password",
v1_base_url="https://glpi.example.com/apirest.php",
v1_user_token="legacy-user-token",
) as client:
reasons = client.list_pending_reasons()
reason = reasons[0]

# The status is the caller's to set: the item alone does not pause.
client.update_ticket(ticket_id, PatchTicket(status=GlpiTicketStatus.PENDING))
item = client.set_ticket_pending_reason(
ticket_id,
reason.id,
followup_frequency=reason.followup_frequency or 0,
followups_before_resolution=reason.followups_before_resolution or 0,
)
print(item.pendingreasons_id)

print(client.get_ticket_pending_reason(ticket_id)) # item or None

client.clear_ticket_pending_reason(ticket_id) # True, or False if none

Things worth knowing:

* ``set_ticket_pending_reason`` creates the item when the ticket has none
and changes it otherwise, so it avoids GLPI's duplicate-key error
unless another writer creates the item between its read and its write.
It does **not** change the ticket status. An item set on a ticket that
is not pending is stored but has no effect; GLPI removes an item when
its ticket leaves status ``4``, but one set on a ticket that never was
pending is not known to be cleaned up, so clear it explicitly.
* The item does not copy the catalogue's ``followup_frequency``: pass the
frequencies wanted, or the item stores ``0``.
* ``clear_ticket_pending_reason`` leaves the ticket at status ``4``,
without a reason. Leaving status ``4`` removes the item by itself.
* A reason id that is not in the catalogue is stored without error.
* None of these calls adds a followup to the timeline. The GLPI web
interface pauses through a followup, which does.

Aggregated ticket context
~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
4 changes: 4 additions & 0 deletions glpi_python_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@
PatchTicketTask,
PatchTimelineDocument,
PatchUser,
PendingReason,
PendingReasonItem,
PostComputer,
PostContract,
PostContractCost,
Expand Down Expand Up @@ -239,6 +241,8 @@
"PatchTicketTask",
"PatchTimelineDocument",
"PatchUser",
"PendingReason",
"PendingReasonItem",
"PostComputer",
"PostContract",
"PostContractCost",
Expand Down
2 changes: 2 additions & 0 deletions glpi_python_client/_async/clients/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
)
from glpi_python_client._async.clients.api.assets import ComputerMixin
from glpi_python_client._async.clients.api.assistance import (
PendingReasonMixin,
TeamMemberMixin,
TicketMixin,
)
Expand Down Expand Up @@ -58,6 +59,7 @@
"KBArticleRevisionMixin",
"KBCategoryMixin",
"LocationMixin",
"PendingReasonMixin",
"PluginFieldsMixin",
"SolutionMixin",
"TeamMemberMixin",
Expand Down
5 changes: 4 additions & 1 deletion glpi_python_client/_async/clients/api/assistance/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

from __future__ import annotations

from glpi_python_client._async.clients.api.assistance._pending_reason import (
PendingReasonMixin,
)
from glpi_python_client._async.clients.api.assistance._team import TeamMemberMixin
from glpi_python_client._async.clients.api.assistance._ticket import TicketMixin

__all__ = ["TeamMemberMixin", "TicketMixin"]
__all__ = ["PendingReasonMixin", "TeamMemberMixin", "TicketMixin"]
Loading
Loading