Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/joaomonteir0/printheritage/llms.txt

Use this file to discover all available pages before exploring further.

PrintHeritage maintains a tamper-evident audit trail of every significant action performed on the platform. Every time a user logs in, creates or modifies a resource, or changes team membership, a record is written to the audit_logs table. The Auditoria do Sistema page surfaces these records in a searchable, colour-coded table that is restricted to SUPER_ADMIN users only.

AuditLog Data Model

Audit records are stored in the audit_logs table, backed by the following SQLAlchemy model:
class AuditLog(Base):
    __tablename__ = "audit_logs"
    id         = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
    user_id    = Column(UUID(as_uuid=True), ForeignKey("users.id"), nullable=False)
    action     = Column(String, nullable=False)   # e.g. "USER_LOGIN", "PROJECT_CREATE"
    target_type = Column(String)                  # e.g. "USER", "PROJECT"
    target_id  = Column(String)
    details    = Column(String)
    timestamp  = Column(DateTime, default=datetime.utcnow)

    user = relationship("User")
The user_id field references the user who performed the action. The target_type and target_id fields identify which entity was affected. The optional details field carries a human-readable description (for example, the email address of a newly created user).

Retrieving Audit Logs

The audit log endpoint is accessible only to authenticated users with the SUPER_ADMIN global role:
GET /audit-logs
The server joins AuditLog with the User table on user_id and returns rows ordered by timestamp descending (newest first). Each row in the response is a composite object:
{
  "AuditLog": {
    "id": "...",
    "user_id": "...",
    "action": "PROJECT_CREATE",
    "target_type": "PROJECT",
    "target_id": "abc12345-...",
    "details": null,
    "timestamp": "2024-03-15T10:22:00"
  },
  "email": "admin@example.com"
}
Any attempt to access GET /audit-logs with a role other than SUPER_ADMIN will be rejected by the server with a 403 Forbidden response.

All Logged Actions

The following table lists every action type emitted by the auth service, along with the associated target_type and a description of what triggers it.
ActionTarget TypeTriggered When
USER_LOGINUSERA user successfully authenticates and receives a JWT.
USER_CREATEDUSERA new user account is created via POST /register. The details field records the new user’s email.
USER_UPDATEUSERA user’s profile or global role is modified via PATCH /users/{user_id}.
USER_DELETEUSERA user account is permanently removed via DELETE /users/{user_id}.
PROJECT_CREATEPROJECTA new project is created.
PROJECT_DATA_ADDPROJECTA new dataset is attached to a project via PATCH /projects/{project_id}/data.
PROJECT_DATA_DELETEPROJECTA dataset is deleted from a project.
PROJECT_MEMBER_INVITEUSERAn invitation is sent to a user to join a project. The target_id is the invited user’s ID.
PROJECT_MEMBER_REMOVEUSERA member is removed from a project’s team.
INVITE_ACCEPTPROJECTAn invited user accepts their pending project invitation.
INVITE_REJECTPROJECTAn invited user rejects their pending project invitation.
PASSWORD_CHANGEUSERA user successfully changes their own password.

Table Columns

The Auditoria do Sistema page renders all logs in a scrollable table with the following columns:
ColumnSource FieldNotes
Data / HoraAuditLog.timestampFormatted with toLocaleString().
UtilizadoremailThe email of the actor, resolved from the User join.
AçãoAuditLog.actionColour-coded badge (see below).
AlvoAuditLog.target_type + target_idtarget_id is truncated to the first 8 characters for display.
DetalhesAuditLog.detailsFree-text context; truncated at max-w-xs. Displays when null.

Colour Coding

Action badges are colour-coded by the getActionColor function, which matches on substrings of the action string:

Green — Create / Accept

Actions containing CREATE or ACCEPT are rendered with an emerald badge (text-emerald-500 bg-emerald-500/10). These represent successful additions and positive responses to invitations.

Red — Delete / Reject

Actions containing DELETE or REJECT are rendered with a red badge (text-red-500 bg-red-500/10). These represent destructive or declined operations.

Blue — Update

Actions containing UPDATE are rendered with a blue badge (text-blue-500 bg-blue-500/10). All other actions fall back to a neutral slate badge.

Loading and Empty States

  • While the initial GET /audit-logs request is in flight, the table body shows an animated A ler registos… placeholder across all five columns.
  • If the response returns an empty array, the table body shows Nenhuma atividade registada. in italics.
The audit log page fetches data once on mount (useEffect with an empty dependency array) and does not auto-refresh. Reload the page to see entries written after the initial load.

Build docs developers (and LLMs) love