[bug] Resending an unchanged is_admin value deletes the OrganizationUser membership
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
Direzione di ricerca
Inizia da SuperUserDetailSerializer.update() e BaseSuperUserSerializer.to_representation() in openwisp_users/api/serializers.py, poi leggi docs/user/rest-api.rst e i test test_remove_org_user_api e test_make_user_org_admin_api. L'issue richiede una decisione di prodotto tra documentare il comportamento attuale e modificare il segnale di rimozione; il lavoro è completato quando il contratto scelto è esplicito e coperto dalla documentazione e dai test pertinenti, considerando la migrazione o il versionamento in caso di modifica incompatibile.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
SuperUserDetailSerializer.update() in openwisp_users/api/serializers.py uses a non-obvious rule for organization_users: if the payload includes an existing membership and the submitted is_admin value is the same as the current value, the membership is deleted instead of being left unchanged.
This behavior is implemented here:
if org_user.is_admin != org_user_data["is_admin"]:
org_user.is_admin = org_user_data["is_admin"]
org_user.full_clean()
org_user.save()
else:
org_user.delete()
As a result, API clients that resend the current representation of a user on PATCH can unintentionally delete organization memberships. The only way to preserve an existing membership is to omit it entirely from the payload, or omit is_admin from that specific entry.
Why this is a problem
- The delete-vs-update behavior is not documented in the REST API docs.
- The serializer response representation includes
organization_users, so a naive PATCH round-trip can be destructive. - This is easy to miss for API consumers who expect unchanged fields to remain unchanged.
Relevant code
openwisp_users/api/serializers.pyBaseSuperUserSerializer.to_representation()serializesorganization_userswithorganizationandis_admin.SuperUserDetailSerializer.update()deletes the membership whenis_adminmatches the current value.
docs/user/rest-api.rstcurrently notes thatis_adminrepresents the organization manager flag, but does not document the delete-on-unchanged behavior.- Existing tests such as
test_remove_org_user_apiandtest_make_user_org_admin_apicover parts of this flow, but do not make the contract explicit in the docs.
Proposed resolution
Please make a product decision on one of these options:
- Document the current behavior explicitly, or
- Replace it with an explicit removal signal instead of overloading "unchanged" to mean "delete".
Option 2 would be a breaking API change for existing consumers, so it likely needs a migration plan or versioning strategy.
Notes
This is unrelated to the disabled-organization write protection work. The behavior predates that effort and appears to come from the original REST API implementation.
- Lingua principale
- Python
- Stelle
- 180
- Fork
- 98
- Merge medio
- 18h 13m
- PR unite (30g)
- 13
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di openwisp/openwisp-users
-
enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
openwisp/openwisp-users#582 ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
openwisp/openwisp-users#562 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
openwisp/openwisp-users#559 ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 38/100
openwisp/openwisp-users#557 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 4/5 3-5 giorni Idoneità per principianti 30/100
openwisp/openwisp-users#546 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di openwisp/openwisp-users
Issue simili
-
ci-rerun: collect.py fails a whole pr-babysit cycle on one transient GitHub 5xx and never retriesApertafollow-up
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
Built-in QUBO fallback applies bitwise xor to floating binary statesForse già presa @iloveeyjafjalla l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
qboson/kaiwu-pytorch-plugin#1702 ·
I maintainer di solito rispondono entro 3 giorni
-
bug v2
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
modelcontextprotocol/python-sdk#3811 ·
I maintainer di solito rispondono entro 1 giorno
-
cost:cheap practicality:seen-in-the-wild severity:medium
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
fairagro/m4.2_advanced_middleware_api#620 ·
I maintainer di solito rispondono entro 1 giorno