Skip to content

feat(reputation): introduce automated reputation point rollback on deleted reviews and retracted endorsements #1384

Description

@Pcmhacker-hero

Description

When a builder receives testimonials, project awards, or positive peer reviews, reputation points are awarded to their account via backend/app/routers/user_reputation.py. If a spammy or fraudulent review is subsequently deleted by moderators or retracted by the author, the previously credited reputation points are never deducted, corrupting leaderboard integrity (frontend/src/routes/_app.leaderboard.tsx).

Steps to Reproduce

  1. User A writes a testimonial for User B (User B receives +50 reputation points).
  2. User A deletes the testimonial or an Admin soft-deletes it for policy violations.
  3. User B retains the +50 points permanently on the global leaderboard.

Expected Behavior

  • Backend: Implement an event-driven reputation audit ledger (ReputationLedger model). On soft-delete or retraction of source events, automatically create an offsetting negative ledger entry and recompute aggregate reputation.
  • Frontend: Display an audit trail of points earned/deducted in the user's reputation dashboard.

Implementation Hints

Backend (backend/app/routers/user_reputation.py):

async def rollback_reputation_points(
    db: AsyncSession,
    user_id: UUID,
    source_type: str,
    source_id: UUID
):
    original_tx = await db.scalar(
        select(ReputationLedger).where(
            ReputationLedger.user_id == user_id,
            ReputationLedger.source_type == source_type,
            ReputationLedger.source_id == source_id,
            ReputationLedger.is_reverted.is_(False)
        )
    )
    if original_tx:
        original_tx.is_reverted = True
        offsetting_tx = ReputationLedger(
            user_id=user_id,
            points=-original_tx.points,
            reason=f"Rollback: {source_type} deleted",
            source_type=source_type,
            source_id=source_id
        )
        db.add(offsetting_tx)
        await db.commit()

Affected Files

  • backend/app/routers/user_reputation.py
  • backend/app/models/user.py
  • frontend/src/routes/_app.leaderboard.tsx

Labels
type:feature, level:advanced, GSSoC-26

Activity

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

Metadata

Metadata

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions