Skip to content

Record moderator actions on ticket status updates with explicit action details#150

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/fix-moderators-actions-table
Draft

Record moderator actions on ticket status updates with explicit action details#150
Copilot wants to merge 4 commits intomainfrom
copilot/fix-moderators-actions-table

Conversation

Copy link

Copilot AI commented Mar 6, 2026

moderator_actions existed in schema but was never written during moderation workflows, leaving production without an audit trail of ticket decisions. This change wires status updates to persistent moderator action logging and now lets callers specify what moderation action was performed.

  • Status update now writes audit records

    • PUT /api/v1/tickets/{ticket_id}/status creates a ModeratorActionModel row whenever a moderator changes ticket status.
    • Stored fields: action_type, user_id, ticket_id, created_at.
  • New optional action parameter for richer audit logs

    • PUT /api/v1/tickets/{ticket_id}/status now accepts an optional free-text action parameter.
    • Endpoint docs suggest terms: fix, edit, dismiss.
    • If action is omitted or whitespace-only, it falls back to set_status_<status> to preserve previous behavior.
  • Auth dependency now returns normalized actor identity

    • auth_dependency returns user payload and normalizes a canonical user_id field (with safe fallback to "unknown"), so moderation endpoints can consistently attribute actions.
  • Focused coverage for the new behavior

    • Added/updated unit tests for:
      • custom action logging,
      • fallback to status-based action when action is missing,
      • fallback when action is whitespace-only,
      • fallback to "unknown" when moderator identity is unavailable,
      • no action insert when ticket does not exist (404 path).

Example of the new write path:

action_type = action.strip() if isinstance(action, str) and action.strip() else None
ModeratorActionModel.create(
    action_type=action_type or f"set_status_{status.value}",
    user_id=user_id,
    ticket=ticket,
    created_at=datetime.now(timezone.utc),
)
Original prompt

This section details on the original issue you should resolve

<issue_title>moderators_actions table is empty in production !</issue_title>
<issue_description>moderators_actions table is empty in production.

It means we do not register which action was taken !
</issue_description>

<agent_instructions>This must be a bug of some sort, because normally it should be implemented.

But it might also be that it was not implemented.

Please take a look and report what you think we should do.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits March 6, 2026 09:18
Co-authored-by: alexgarel <144788+alexgarel@users.noreply.github.com>
Co-authored-by: alexgarel <144788+alexgarel@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix empty moderators_actions table in production Record moderator actions on ticket status updates Mar 6, 2026
Copy link
Member

@alexgarel alexgarel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot, there are changes needed.

Comment on lines +490 to +495
ModeratorActionModel.create(
action_type=f"set_status_{status.value}",
user_id=user_id,
ticket=ticket,
created_at=datetime.now(timezone.utc),
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok the code is really correct, but it does not bring new information if we do that.

So What we should do instead is: add a parameter, so that the caller can explain what was done.

I propose to add an "action" parameter which is free text.

The documentation should suggest those terms: "fix", "edit", "dismiss".

We will change the frontend on the other end to use this new parameter.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented in 344124f. PUT /tickets/{ticket_id}/status now accepts optional free-text action, stores it in moderator_actions.action_type, and documents suggested values (fix, edit, dismiss). If omitted or whitespace-only, it falls back to set_status_<status>.

Co-authored-by: alexgarel <144788+alexgarel@users.noreply.github.com>
Copy link
Author

Copilot AI commented Mar 9, 2026

@copilot, there are changes needed.

Addressed in 344124f with the requested changes: added the new optional action parameter on ticket status updates and updated tests/validation accordingly.

Copilot AI changed the title Record moderator actions on ticket status updates Record moderator actions on ticket status updates with explicit action details Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

moderators_actions table is empty in production !

2 participants