Skip to content

Catalogue Portal Approvals Developer Guide

Ed Mozley edited this page Nov 23, 2026 · 1 revision

Managers and cost centre owners approving on the portal - Developer Guide

GH #160 Part C2, built 23 Nov 2026 for 5.10.0. Also #348 slices 2 and 4. For people setting it up: Catalogue Request Approvals. The step engine this extends: Approval steps and chains - Developer Guide.

C1's steps are decided by staff: an analyst or a team. Managers and budget holders usually are not staff. They are people (users), and FreeITSM keeps their manager and their cost centres against that table. C2 adds two kinds of step that people decide on the portal:

who Who decides Set where
manager the requester's users.manager_id People -> the person's Manager field
cc_owner the cost centre's owner (owner_user_id, or any member of owner_group_id) and its deputy (deputy_user_id) System -> Cost Centres (Part B)

πŸ”‘ Who decides is worked out at every decision, never stored. The request keeps the kind of step and, for an owner step, which cost centre. Who the manager or owner is gets asked each time, which is the rule team membership already follows. So a leaver cannot approve, and their replacement can.


1. πŸ“ The files involved

File What it does
includes/catalogue_approval_people.php New. Who may decide (catalogueStepPeople()), deciding as a person, the portal list, away, Remind, telling approvers (bell and email), the email
includes/catalogue_approval_steps.php manager / cc_owner in catalogueNormaliseStepPolicy() (steps only, never a fallback); catalogueStepColumns() carries approver_kind and approval_cost_centre_id; the plan fixes each owner step's cost centre; catalogueStepFindsNobody() asks the people; catalogueAdvanceStep() writes the new columns and resets the clocks
includes/catalogue_approvals.php Policy mode people; progress and Stuck for it; staff decide refused; Move clears it; events carry user_id; catalogueFinishDecision() records the person and does "already approved by"; the inbox names who it waits on; the ticket body names the requester's cost centre
includes/services/forms.php submitForm() writes approver_kind, approval_cost_centre_id, approval_step_datetime, requester_cost_centre_id
api/self-service/approvals.php New. The portal page's GET list, POST decide, POST away
api/self-service/remind_request.php New. The requester's Remind
self-service/approvals.php New. The portal Approvals page
self-service/includes/header.php The Approvals tab, cap is_approver
self-service/index.php, api/self-service/get_dashboard.php Remind on Your requests; a person's rejection reason shown
includes/services/notifications.php portalLinkFor('catalogue_request') -> the portal Approvals page
assets/js/forms-approval-steps.js Two more Who decides choices; the cost centre question picker
api/forms/approval_chains.php, forms/settings/index.php The deputy rule, the mailbox, Remind (Forms -> Settings -> Approvals)
forms/approvals.php "Waiting for: the requester's manager: Sam Jones", the new record lines
tests/catalogue-approval-people.php 41 checks

2. πŸ—„οΈ Schema

ALTER TABLE form_submissions
  ADD approver_kind               VARCHAR(20) NULL,  -- 'manager' | 'cc_owner' | NULL (a staff step)
  ADD approval_cost_centre_id     INT NULL,          -- an owner step's cost centre, fixed by the answers
  ADD approval_decided_by_user_id INT NULL,          -- a person decided it (the twin of approval_decided_by_id)
  ADD approval_step_datetime      DATETIME NULL,     -- when the current step was reached
  ADD approval_reminded_datetime  DATETIME NULL,     -- last Remind on this step
  ADD requester_cost_centre_id    INT NULL;          -- #348 slice 4: the requester's cost centre when they asked
ALTER TABLE form_submission_approval_events ADD user_id INT NULL;   -- a person acted
ALTER TABLE users ADD approvals_away_until DATE NULL;               -- "away until", for a cover-only deputy

Settings, in system_settings: forms_approval_deputy_mode (any | cover), forms_approval_deputy_days, forms_approval_mailbox_id, forms_approval_remind (1 default). Read them with catalogueApprovalOptions($conn).

cataloguePeopleAvailable($conn) is true once all eight columns exist. Before Database Verification, nothing new can be chosen or reached.

Not built, and why: the design planned approver_user_id and user votes with their own unique key. A stored approver would contradict "checked at every decision". Votes are not needed because a people group that owns a cost centre decides like one person: any member settles the step.


3. βš™οΈ Who may decide - catalogueStepPeople($conn, $sub)

$p = catalogueStepPeople($conn, $sub);
// ['kind' => 'cc_owner', 'decide' => [3420, 3421], 'owners' => [3420], 'deputy' => 3421,
//  'deputy_decides' => true, 'cost_centre' => ['id' => 7, 'code' => '0010', 'name' => 'Logistics'],
//  'reason' => null]       // reason when decide is empty: no_manager | no_cost_centre | no_owner
  • The requester is never in it. If they own the cost centre, the owners list is empty, so the deputy decides even when the deputy is only cover.
  • Owners and the deputy must be active (users.is_active = 1). A group's members must be member_type = 'user' and not expired.
  • Deputy mode cover: the deputy is added only when the owners list is empty, every owner has approvals_away_until >= CURDATE(), or deputy_days > 0 and the step was reached that many days ago (approval_step_datetime, else submitted_date).

catalogueUserMayDecide($conn, $sub, $userId) is that list's in_array. Every listing, decision and reminder asks it. A request id in an address grants nothing.


4. βš™οΈ At submission

catalogueStepsPlan() fixes each owner step's cost centre into the snapshot step as cost_centre_id:

if (($s['who'] ?? '') === 'cc_owner') {
    $s['cost_centre_id'] = catalogueStepCostCentre($conn, $s, $fieldsById, $valuesByFieldId, $requesterId);
}

cc_question names a cost-centre lookup by label, as conditions do, because chains are shared. Its answer is {"id":7,"label":"0010 - Logistics"}. A blank cc_question means the requester's own users.cost_centre_id. No cost centre means the step finds nobody, so the fallback decides.

catalogueStepColumns() turns a people step into approver_kind + approval_cost_centre_id, with approver_id and approval_team_id both NULL. submitForm() also stamps approval_step_datetime and requester_cost_centre_id.


5. βš™οΈ Deciding as a person - catalogueDecideAsPerson()

The same lock and finish as a named analyst, recorded against the person:

$conn->beginTransaction();
$sub = catalogueLockSubmission($conn, $submissionId);          // FOR UPDATE
if (!catalogueUserMayDecide($conn, $sub, $userId)) throw new Exception('That request is not waiting for you');
$done = catalogueFinishDecision($conn, $sub, $decision, 0, $comment, $userId);
$conn->commit();
return catalogueAfterDecision($conn, $sub, $decision, $comment, $done);
  • A rejection needs a reason. get_dashboard.php shows the requester approval_comment when the request was rejected and approval_decided_by_user_id is set. A staff approver's note stays internal, as before.
  • catalogueFinishDecision(..., $actorUserId) passes the person to catalogueAdvanceStep(), so the step_passed event has user_id. On the last step it sets approval_decided_by_user_id.
  • Staff cannot decide a people step. catalogueApprovalDecide() refuses mode people, administrators included. Their way round is Override, which needs a reason, or Move.

Already approved by (decision 3)

while ($advanced !== null && $actorUserId > 0 && catalogueUserMayDecide($conn, $advanced['sub'], $actorUserId)) {
    catalogueApprovalEvent($conn, $id, 0, 'step_already_approved', $advanced['to'], $name, $actorUserId);
    $next = catalogueAdvanceStep($conn, $advanced['sub'], 0, '', 0);
    if ($next === null) { $sub = $advanced['sub']; $advanced = null; break; }   // last step: approve
    $advanced = $next;
}

A manager who also owns the requester's cost centre approves once. The per-form setting "require a different person at each step" from decision 3 is not built.


6. πŸ”” Telling approvers - catalogueTellApprovers($conn, $sub, $reminder)

One function for reaching a step and for Remind:

  • Staff: the analyst bell (catalogue_request.awaiting, each person's own switch).
  • People: the portal bell (portal_user_id). portalLinkFor('catalogue_request') opens self-service/approvals.php?id=. The portal shows its bell once somebody has a notification.
  • Email, when forms_approval_mailbox_id names an active mailbox, goes through mailboxSendSimple() (route catalogue_approval). Staff get a link to forms/approvals.php, people one to the portal page, built on publicBaseUrl(). No approve button: forwarding the email must not forward the decision.

catalogueTellStepApprovers() (C1) calls it for requests with steps. A single-policy request is still told only by a workflow rule, as before. Remind works on any waiting request.


7. βš™οΈ Remind - catalogueRemind($conn, $userId, $id)

The requester only, and only while the request is waiting. catalogueCanRemind() checks forms_approval_remind and that approval_reminded_datetime is empty or a day old. Remind locks the row, stamps the time, records a reminded event with user_id, then tells the approvers. catalogueAdvanceStep() and Move reset the stamp, so each step gets its own reminder.


8. πŸ–₯️ The portal page

self-service/approvals.php draws what api/self-service/approvals.php returns. The tabs are Waiting for me and Decided. Each card shows the answers, the price, the requester's cost centre, "Step 2 of 3" and why it is with me (as: manager / owner / deputy). The Away until box appears only when the deputy is cover. ?id= scrolls to a card and grants nothing.

The tab's cap is is_approver, from catalogueUserIsApprover(): a manager of somebody, an owner or deputy of a cost centre or in a group that owns one, or somebody who has decided before. It fails closed.


9. ⚠️ Traps

Trap Rule
Storing the approver Never. Ask catalogueStepPeople() at the moment of the decision
Mode person assumptions catalogueApprovalPolicy() now returns people too. Anything that branches on person vs team must treat people as "staff cannot decide"
A fallback that is a person A fallback is always staff (catalogueNormaliseStepPolicy(..., $allowPeople = false)): it must be somebody fixed
Move Must clear approver_kind and approval_cost_centre_id, or the moved request still routes to the portal
t() in a portal endpoint catalogue_approval_people.php requires i18n.php itself, for the email and the ticket body
Two identities A person's right comes from the portal sign-in (ss_user_id), never from an analyst sharing their email

10. βœ… How it was verified

tests/catalogue-approval-people.php (41 checks) covers:

  • saving, and a fallback refused as a person;
  • the owner step routed to the requester's own cost centre or a question's, and the requester's cost centre kept;
  • staff refused; the manager told on the portal bell and deciding by id only when it is theirs;
  • owner and deputy as equals; cover when the owner is away, after N days, and when the owner made the request;
  • a people group with any member settling it;
  • "already approved"; no manager going to the fallback, else Stuck;
  • a new manager deciding when the old one cannot;
  • Remind once a day, refused for others, refused when switched off, and reset by a pass;
  • Move clearing it, Override passing one step, and the staff inbox naming the owner.

The C1 tests and the other approval tests still pass: steps 37, group approvals 38, answer edits 26, card 71, approver access 20, grid 14, lookup portal submit 16, analyst lifecycle 21.

The screens were driven on a test install: the manager and the owner on the portal page (desktop and phone), approving in the portal to a ticket, Remind on the requester's dashboard, the staff inbox, the step editor, and the Settings tab.

See also

FreeITSM

Getting Started

Modules

Multi-tenancy (planned)

Responses to feedback

Blue sky thinking

Bugs resolved

Pull requests

Links

Clone this wiki locally