Skip to content

Add reset annotations button to admin table with database synchronization - #67

Merged
IvoLeist merged 8 commits into
mainfrom
copilot/add-reset-button-user-annotations
Jan 21, 2026
Merged

Add reset annotations button to admin table with database synchronization#67
IvoLeist merged 8 commits into
mainfrom
copilot/add-reset-button-user-annotations

Conversation

Copilot AI commented Jan 19, 2026

Copy link
Copy Markdown
Contributor

Admins need ability to reset user annotation files while preserving variant coordinates and randomization order, with automatic database vote count synchronization.

Changes

Core function (R/admin_utils.R)

  • Added reset_user_annotations() - reads TSV, identifies cast votes, decrements database vote counts, preserves coordinates/REF/ALT columns, clears voting data (agreement, observation, comment, session_id, time), writes back
  • SQL injection protection: validates column names against allowlist before database operations
  • Uses MAX(0, vote_count - 1) to prevent negative vote counts
  • Comprehensive error handling for database operations

Admin UI (R/mod_admin.R)

  • Added "Reset Annotations" button to Action column alongside existing "Email Template" button
  • Two-step confirmation modal with clear warning about preserved vs cleared data
  • Success/error feedback modals

Testing (tests/testthat/test-admin-reset-annotations.R)

  • Validates column preservation logic
  • Validates database vote count decrements
  • Tests with mock database and config
  • Handles missing files and invalid structures
  • 5 comprehensive test cases

Database Integration

When resetting annotations:

  1. Reads user's annotation file to identify cast votes
  2. Decrements corresponding vote counts in database (vote_count_correct, vote_count_different_variant, etc.)
  3. Clears annotation file while preserving coordinates/REF/ALT
  4. Maintains database consistency with annotation files

Example

Before reset:

coordinates  REF  ALT  agreement  observation  comment
chr1:100     A    T    yes        coverage     looks good
chr2:200     T    C    germline   alignment    check

Database before: vote_count_correct = 5, vote_count_germline = 3

After reset:

coordinates  REF  ALT  agreement  observation  comment
chr1:100     A    T
chr2:200     T    C

Database after: vote_count_correct = 4, vote_count_germline = 2 (decremented by 1 each)

User can re-vote on same randomized variant order with clean slate while maintaining accurate vote counts.

Original prompt

This section details on the original issue you should resolve

<issue_title>Reset the annotations of a user via the admin table</issue_title>
<issue_description>Add a button to the table which allows the reset of the user annotations files.
=> First row (=headers) and first column (randomized coordinates) should stay all the other cells should be empty</issue_description>

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


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits January 19, 2026 12:10
Co-authored-by: IvoLeist <28399610+IvoLeist@users.noreply.github.com>
Co-authored-by: IvoLeist <28399610+IvoLeist@users.noreply.github.com>
Co-authored-by: IvoLeist <28399610+IvoLeist@users.noreply.github.com>
Copilot AI changed the title [WIP] Add a button to reset user annotations in admin table Add reset annotations button to admin table Jan 19, 2026
Copilot AI requested a review from IvoLeist January 19, 2026 12:18
Comment thread R/admin_utils.R

@IvoLeist IvoLeist Jan 19, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@copilot
Not only the respective user annotation file needs to be reset but also the votes counts of the selected user need to be updated accordingly in the database

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 6ac84d2. The reset_user_annotations() function now:

  1. Reads existing votes from the annotation file
  2. Decrements the corresponding vote counts in the database for each vote the user cast
  3. Then resets the annotation file

The function uses MAX(0, vote_count - 1) to prevent negative counts and includes error handling for database operations.

@IvoLeist IvoLeist left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not only the respective user annotation file needs to be reset but also the votes counts of the selected user need to be updated accordingly in the database

Co-authored-by: IvoLeist <28399610+IvoLeist@users.noreply.github.com>

Copilot AI commented Jan 19, 2026

Copy link
Copy Markdown
Contributor Author

Not only the respective user annotation file needs to be reset but also the votes counts of the selected user need to be updated accordingly in the database

Fixed in 6ac84d2. The reset function now updates the database vote counts by decrementing them for each vote the user had cast before clearing the annotation file. Added tests to verify the database integration works correctly.

Co-authored-by: IvoLeist <28399610+IvoLeist@users.noreply.github.com>
Copilot AI changed the title Add reset annotations button to admin table Add reset annotations button to admin table with database synchronization Jan 19, 2026
Copilot AI requested a review from IvoLeist January 19, 2026 18:05
@IvoLeist
IvoLeist marked this pull request as ready for review January 21, 2026 09:03
@IvoLeist
IvoLeist merged commit 9153dc5 into main Jan 21, 2026
1 check passed
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.

Reset the annotations of a user via the admin table

2 participants