Skip to content

feat: emit ApprovalStateChangedEvent on approval state changes - #449

Open
xyonium wants to merge 1 commit into
nextcloud:mainfrom
xyonium:feat/approval-state-changed-event
Open

xyonium wants to merge 1 commit into
nextcloud:mainfrom
xyonium:feat/approval-state-changed-event

Conversation

@xyonium

@xyonium xyonium commented Sep 27, 2026 •

Copy link
Copy Markdown

Motivation

Apps reacting to approval state changes (e.g. via workflow engine rules on the approval tags) currently cannot know who requested an approval:

  • the session user at that moment is the approver (on approve/reject)
  • the approval_activity row holding the requester is replaced by storeAction() before the tag change is triggered

This was reported in nextcloud/workflow_script#363, where a flow script needs the requester's user id to route the file after approval.

What this PR does

Adds OCA\Approval\Events\ApprovalStateChangedEvent, dispatched via dispatchTyped() when an approval is

  • requested (ApprovalService::request())
  • requested via manual/auto tag assignment (requestViaTagAssignment())
  • approved (approve())
  • rejected (reject())

The event carries:

getter content
getFileId() the file id
getRuleId() the approval rule id
getNewState() Application::STATE_PENDING / STATE_APPROVED / STATE_REJECTED
getActorUserId() the user performing the action (requester on request, approver otherwise)
getRequesterUserId() the user who requested the approval, if known

On approve/reject the requester is read via getLastAction(..., STATE_PENDING) before storeAction() replaces that row, and the event is dispatched before the tags change, so listeners reacting to the tag assignment events (like workflow engines) already have the context within the same request.

A unit test asserts the events and their payloads on request and approve.

Counterpart

This enables nextcloud/workflow_script#363 — consumed by nextcloud/workflow_script#534 which adds a %r placeholder for the requester's user id.

The new OCA\Approval\Events\ApprovalStateChangedEvent is dispatched
when an approval is requested, approved or rejected, right before the
corresponding system tags are (un)assigned.

Next to the acting user it carries the user who requested the approval.
That information is otherwise lost on approve/reject, because the
pending activity row is replaced by the approver's one before the tag
change is triggered.

This enables other apps, e.g. workflow engines like workflow_script, to
react to approval state changes on behalf of the requester, see
nextcloud/workflow_script#363

Signed-off-by: eli <shark_xc@hotmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant