Skip to content

feat: allow profile owners to disable and re-enable their account - #43

Open
fordimalanda wants to merge 1 commit into
congodevelopersclub:devfrom
fordimalanda:feat/disable-profile-account
Open

fordimalanda wants to merge 1 commit into
congodevelopersclub:devfrom
fordimalanda:feat/disable-profile-account

Conversation

@fordimalanda

Copy link
Copy Markdown

What this PR does

Closes #42

Profile owners can now disable their account. A disabled profile stops showing up anywhere public, and comes back as soon as its owner enables it again.

Changes

New status

  • Added DISABLED to ProfileAccountStatus.
  • New migration: adds DISABLED to the account_status enum column and adds a nullable account_status_before_disabled column.

New endpoints (authenticated, owner only)

Method Route Effect
PUT /api/v1/profiles/{profile}/disable Sets the profile to DISABLED and remembers its current status
PUT /api/v1/profiles/{profile}/enable Restores the status the profile had before it was disabled
  • Only the owner can call these endpoints: anyone else gets a 403, and a guest gets a 401.
  • Both calls are idempotent. Disabling twice does not overwrite the saved status, and enabling a profile that is not disabled changes nothing.

Why remember the previous status?

If we simply moved a profile back to PENDING_VALIDATION when it is enabled again, an already validated member would have to go through moderation again just because they hid their profile for a while. Saving the previous status avoids that. This column is hidden from API responses.

Filtering

  • New visible() scope on Profile that excludes disabled profiles.
  • Applied to GET /profiles and GET /profiles/search.
  • GET /profiles/{profile} returns 404 for a disabled profile, except when the caller is its owner. This lets the owner still see their own profile and enable it again.

Guard on the validation endpoint

PUT /profiles/{profile}/validate no longer accepts DISABLED. That status belongs to the owner and should not be set through moderation.

Other

  • ProfileFactory::disabled() state for tests.
  • OpenAPI docs for both new endpoints and the new enum value.

Tests

  • Added 12 feature tests: disable/enable by the owner, 403/401 cases, idempotency, restoring the previous status, hiding from list, search and show, the owner can still see their profile, and validate rejects DISABLED.
  • Full suite: 110 tests passing. PHPStan: 0 errors. PHP CS Fixer: no changes needed on the modified files.

How to try it

php artisan migrate
# as the profile owner
curl -X PUT -H "Authorization: Bearer <token>" {{base_url}}/api/v1/profiles/<id>/disable
curl {{base_url}}/api/v1/profiles/search          # the profile is gone
curl -X PUT -H "Authorization: Bearer <token>" {{base_url}}/api/v1/profiles/<id>/enable

Closes congodevelopersclub#42

Profile owners can now disable their account so it no longer shows up
in listings or searches, and enable it again whenever they want.

- add a DISABLED value to ProfileAccountStatus, plus a migration that
  extends the enum column and adds `account_status_before_disabled`
- add PUT /api/v1/profiles/{profile}/disable and
  PUT /api/v1/profiles/{profile}/enable (authenticated, owner only)
- remember the previous status when disabling, so enabling restores it
  (a VALIDATED profile comes back VALIDATED instead of going through
  moderation again)
- hide disabled profiles from GET /profiles and GET /profiles/search
  through a `visible()` scope on the Profile model
- return 404 on GET /profiles/{profile} for a disabled profile, except
  for its owner
- prevent the admin validation endpoint from setting DISABLED, since
  this status belongs to the owner
- add feature tests covering the new flow

This branch has not been deployed

No deployments
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.

1 participant