Skip to content

add env_types array to userroles assignment#471

Open
boddumanohar wants to merge 2 commits intomainfrom
userrolelink-env
Open

add env_types array to userroles assignment#471
boddumanohar wants to merge 2 commits intomainfrom
userrolelink-env

Conversation

@boddumanohar
Copy link
Member

@boddumanohar boddumanohar commented Jan 7, 2026

Currently, when assigning a role of type environment to the user, if the env_types field has multiple values, we get 500 error.

This PR fixes that issue by changing the env_type field to env_types of type array.

Testing

  1. create a user. This will create a user in KeyCloak
curl -X 'POST' \
  'http://localhost:8000/vela/users/' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer $TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
  "email": "user2@example.com",
  "first_name": "string",
  "last_name": "string",
  "send_mail": false
}'
  1. create a role of type environment
curl -X 'POST' \
  'http://localhost:8000/vela/organizations/01KECFW18ZSJWA6KARB2XEHJWM/roles/' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer $TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
  "name": "string3",
  "role_type": "environment",
  "is_active": true,
  "is_deletable": true,
  "description": "string",
  "access_rights": []
}'
  1. Call the org membership endpoint. This will create an entry in Vela User table for the Keycloak user created in step 1
curl -X 'POST' \
  'http://localhost:8000/vela/organizations/01KECFW18ZSJWA6KARB2XEHJWM/members/' \
  -H 'accept: */*' \
  -H 'Authorization: Bearer $TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
  "id": "f0937d55-716f-4946-8b56-e03b41893e6c"
}'
  1. assign role to the user
curl -X 'POST' \
'http://localhost:8000/vela/organizations/01KECCWDXBMYMFRRFGYX6V5HRJ/roles/01KECEV80HRQD1F5BS3TS6TJEM/assign/92b21f88-f10b-46a5-bdcf-b7d873ea5556/' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer $TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
  "env_types": ["prod", "asdf"]
}'

That works and the response body is:

{
  "status": "assigned",
  "count": 1,
  "links": [
    {
      "organization_id": "01KECFW18ZSJWA6KARB2XEHJWM",
      "project_id": null,
      "branch_id": null,
      "role_id": "01KECFWSNDFF9BTKWH223135XN",
      "user_id": "f0937d55-716f-4946-8b56-e03b41893e6c",
      "env_types": [
        "prod",
        "asdf"
      ]
    }
  ]
}

@boddumanohar boddumanohar marked this pull request as draft January 7, 2026 11:48
@boddumanohar boddumanohar marked this pull request as ready for review January 7, 2026 15:17
Copy link
Collaborator

@mxsrc mxsrc left a comment

Choose a reason for hiding this comment

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

Looks quite good, just a question regarding how we encode things in the database.

@noctarius
Copy link
Collaborator

noctarius commented Jan 7, 2026

Looking at the code (and it makes sense) but this will change the API, won't it? I think there are one or two more calls which have env vars and retrieve a comma separated list right now. However, I assume these are already handled since the type check is happy.

@noctarius
Copy link
Collaborator

Since this also requires a change in the studio-backend code, let's not merge it immediately. I'll create the change tomorrow and merge it right after the studio is merged and deployed.

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.

3 participants