Defect #35965

REST group api does not work when user is already member of group

Added by Wim Bertels about 1 month ago.

Status:NewStart date:
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:REST API
Target version:-
Resolution: Affected version:4.0.7

Description

This might be related to:
https://stackoverflow.com/questions/56767239/how-to-fix-user-is-invalid-error-when-adding-user-to-a-group-with-redmine-api

How to reproduce:
  1. add a user U1 to group G1 via the redmine admin panel
  2. add the same user U1 to the group G1 with a (curl) api request

the following errors are thrown:


$ curl -i -H "Content-Type: application/json" -X POST --data '{"user_id":1234}' -H  "X-Redmine-API-Key: secret" https://myredmi.ne/groups/1/users.json

HTTP/1.1 422 Unprocessable Entity
Date: Fri, 08 Oct 2021 09:13:04 GMT
Server: Apache
Cache-Control: no-cache
Referrer-Policy: strict-origin-when-cross-origin
X-Permitted-Cross-Domain-Policies: none
X-XSS-Protection: 1; mode=block
X-Request-Id: 5b6c0feb-2051-41b0-bb27-5227f558d708
X-Download-Options: noopen
X-Runtime: 0.007623
X-Frame-Options: SAMEORIGIN
X-Content-Type-Options: nosniff
X-Powered-By: Phusion Passenger 5.0.30
Strict-Transport-Security: max-age=31536000; includeSubDomains
Status: 422 Unprocessable Entity
Transfer-Encoding: chunked
Content-Type: application/json; charset=utf-8

{"errors":["User is invalid"]}

the user is not invalid, but already part of the group.

--

i would prefer a behaviour where the user is added the group again,
as in the background this invokes other operations,
namely on members and member_roles.

more precise:
  • a group G1 has access to project P1
  • when a user U1 gets added to the group G1, in the background this user gets added project P1 (inherited from G1)
  • when the user is removed from G1, it is also removed from P1 (as found through inherited)

i have noticed that sometimes, (not often,) this process does not complete,
so users might get added to a group, but not to the projects of the group,
adding them again to the group should fix the problem,
but the api does not allow that,
if the api would allow that, then this would possible 'self-heal' the rare cases in which the users where not added to projects properly

--

workaround: first remove group, and add again; for example

(ps: delete seems only to work with xml)

hth

Also available in: Atom PDF