Repository navigation
feat(reputation): add update_user_type entrypoint - #1601
Conversation
|
@Spaully is attempting to deploy a commit to the Mftee's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@Spaully Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
…tale boolean update_stats signature
mftee
left a comment
There was a problem hiding this comment.
Sensible addition: update_user_type lets a user correct a mis-registered UserType (Carrier/Shipper) in one signed call, mirroring identity's update_identity, and preserves existing per-type counters rather than wiping history. While resolving the conflict against #1599/#1600 (merged just before this), I updated this PR's pre-existing test calls in test/events.rs and test/users.rs to use the new Outcome enum instead of the old was_on_time/was_successful booleans, since update_stats's signature changed underneath this PR; the new update_user_type logic and its own tests are untouched.
Summary
Closes #1464
Adds
update_user_typeto the reputation contract so a Carrier mis-registered as Shipper (or vice versa) can correct itsUserTypein one user-signed call, without an admin round-trip.register_userlocks a user's type in at registration and a second registration fails withUserAlreadyRegistered, so there was previously no on-protocol path to fix a wrong label. The new entrypoint is the reputation analogue of identity'supdate_identity, follows the existingusersmodule style, and reusesstorage::require_not_paused/storage::load_reputation/storage::save_reputationand the standardupdatedevent.The single most important design decision: the correction is self-serve (
user.require_auth()), so the person who registered is the only party who can fix their own record - noUserTypeMismatchround-trip and no admin involvement, exactly as the issue asks.Also closes
Closes #1463, Closes #1465, Closes #1466
(Closed without implementation - see Deliberately deferred.)
Why
users::registersetsuser_typeonce and every later call fails withUserAlreadyRegistered. There was noupdate_user_type-style entrypoint anywhere in the crate, so correcting a mis-registered type required an admin to manually rewrite storage off-protocol. Identity solved the analogous problem withupdate_identity(a wallet can correct itsuser_id_hashin one signed call); reputation had no equivalent foruser_type. This PR adds exactly that, with auth scoped to the user themselves and the pause guard consistent with the crate's other mutating entrypoints.What was built
contracts/reputation/src/users.rsusers::update:user.require_auth(),require_not_paused, loads the existingReputation, setsuser_type, updateslast_updated, saves, emitsupdated. Doc comment explains the correction path and that per-type counters are intentionally preserved.contracts/reputation/src/contract.rsupdate_user_type(env, user, user_type)delegating tousers::update.contracts/reputation/src/test/users.rsUserNotFound), and counter preservation (existingsuccess_countsurvives a Shipper->Carrier correction).contracts/reputation/src/test/events.rstest_update_user_type_emits_updated: asserts exactly oneupdatedevent with the corrected payload and the user as key topic.No existing files modified outside
contracts/reputation/. No new actions added tocontracts/EVENTS.mdbecause the change reuses the existingupdatedevent.Acceptance criteria coverage (primary issue #1464)
update_user_type-style entrypoint exists in the reputation crate (contracts/reputation/src/contract.rs,users::update)user.require_auth(), no admin parameter) (test/users.rs:test_update_user_type)update_identity: single self-auth call, no admin round-trip (doc comments on the entrypoint andusers::update)UserNotFound(test/users.rs:test_update_user_type_requires_prior_registration)test/users.rs:test_update_user_type_preserves_counters)Deliberately deferred
get_total_ratingssemantics documentation and the "void does not decrement" test: deliberately not implemented in this PR to keep it focused on the new entrypoint; remains tracked.contracts/shipment); remains tracked.ShipmentStatus::Cancelleddoc-comment fix: different crate (contracts/shipment); remains tracked.Test plan
cargo fmt --all -- --check: not run - no Rust toolchain in this workspace environment; code follows the formatting of the neighbouringusers.rs/test/*modules.cargo clippy --all-targets --all-features -- -D warnings: not run (no toolchain).cargo test -p reputation: not run (no toolchain). New tests only drive existing public client methods; 4 new tests added (3 intest/users.rs, 1 intest/events.rs).cargo build --all: not run (no toolchain).Env vars / Notes
No new environment variables or config keys introduced. The new public entrypoint is
update_user_type(env, user, user_type); it is not admin-gated, consistent withregister_userand identity'supdate_identity.