Skip to content

feat(contracts): implement content flagging mechanism#271

Merged
Kaylahray merged 3 commits intogeevapp:mainfrom
Birdmannn:feat/reporting-system
Mar 30, 2026
Merged

feat(contracts): implement content flagging mechanism#271
Kaylahray merged 3 commits intogeevapp:mainfrom
Birdmannn:feat/reporting-system

Conversation

@Birdmannn
Copy link
Copy Markdown
Contributor

Pull Request Template

Description

What was added

types.rs

  • DataKey::FlagRecord(u64, Address) — tracks whether a specific user has flagged a specific content ID
  • DataKey::FlagCount(u64) — running tally of total flags per content ID
  • Error::AlreadyFlagged — returned when a user attempts to flag the same ID more than once

governance.rs (new)

A new GovernanceContract with three public functions:

Function Description
flag_content(env, user, target_id) Flags a content ID on behalf of user. Requires auth, rejects duplicates, increments count, emits ContentFlagged event.
get_flag_count(env, target_id) Returns the total number of flags for a given ID.
has_flagged(env, user, target_id) Returns whether a user has already flagged a given ID.

lib.rs

  • Registered the governance module and re-exported GovernanceContract / GovernanceContractClient.

Anti-spam design

Each flag is keyed by (target_id, user_address) in persistent storage. A second call from the same user on the same ID returns Error::AlreadyFlagged immediately, making spam-flagging impossible at the contract level.

Tests (test.rs)

Test Covers
test_flag_content_increments_count Count goes from 0 → 1 after a single flag
test_flag_content_multiple_users Two different users each increment the count
test_flag_content_duplicate_panics Same user flagging twice panics
test_has_flagged_returns_false_before_flag has_flagged is false before any flag
test_flag_counts_are_independent_per_id Flagging ID 1 does not affect ID 2

All 39 tests pass.


Checklist

  • I have tested my changes locally
  • I have updated documentation as needed
  • I have run npx prisma generate after schema changes
  • I have run npx prisma migrate dev or npx prisma migrate deploy as appropriate

Post-Merge Steps for Maintainers

If this PR includes changes to the Prisma schema:

  1. Run the following command to apply the migration to your database:

    npx prisma migrate deploy

    or, for local development:

    npx prisma migrate dev
  2. Ensure your CI pipeline runs the migration before tests (add this step if missing):

    - name: Run Prisma Migrate
      run: npx prisma migrate deploy
  3. Make sure the database user in CI has permission to run migrations.


If you have any questions, please comment on this PR.
this PR closes #210

Copy link
Copy Markdown
Contributor

@3m1n3nc3 3m1n3nc3 left a comment

Choose a reason for hiding this comment

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

Please resolve the conflicts

@Birdmannn Birdmannn requested a review from 3m1n3nc3 March 30, 2026 10:53
@Kaylahray Kaylahray assigned Birdmannn and unassigned Kaylahray Mar 30, 2026
@Kaylahray Kaylahray merged commit fc84228 into geevapp:main Mar 30, 2026
2 checks 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.

Reporting Mechanism (Flagging)

3 participants