Multiple user-to-app-to-role assignment


#1

After update from 2.1.1 to 2.1.2
I have this error when I was trying to update a user settings:

Api Error Multiple user-to-app-to-role assignment. You can only have a single user-to-app-to-role assignment.

This error in a user with a single app, this role used by a single user


#2

Hello. This is known bug that has been fixed in the upcoming release.

In the mean time you can work around it by switching to the mysqlnd php module, rather than the mysql php module. In ubuntu this would be:

sudo apt-get remove php5-mysql sudo apt-get install php5-mysqlnd

Then restart Apache (or PHP FPM and Nginx if that’s your thing.)


#3

Hi @drewpearce,

This is still happening for us on DreamFactory version 2.3.0.

We’re making a PATCH request to system/user including a user_to_app_to_role_by_user_id array in order to change the user’s role. The array only contains one element (as we only have one app).

Are we doing something incorrectly or is the bug still around?

Thanks


#4

I’m not aware of any known issues around this, but I’ll be happy to check it out. Can you provide a sample payload?


#5

Hi Drew, sure thing.

In this example I have an existing user which already has role id 2 for an app with id 4. I’m PATCHing the following JSON to system/user/:

{
  "id": 13,
  "first_name": "adam",
  "last_name": "cunliffe",
  "email": "adam@Weaveware.co.uk",
  "name": "adam cunliffe",
  "user_to_app_to_role_by_user_id": [
    {
      "app_id": 4,
      "role_id": 1,
      "user_id": 13
    }
  ]
}

I get back the error “Multiple user-to-app-to-role assignment. You can only have a single user-to-app-to-role assignment.

The error message makes sense as this is indeed already an existing role assignment, but I’m not aware of any way to clear that down via the API.


#6

I just realized what’s happening here. The user resource for “user_to_app_to_role” also has an ID. You’re not including it in your payload. So DreamFactory thinks you’re trying to create a new role assignment rather than update an existing one. You can remedy this by including the id of the existing role assignment in the payload, for example:

      "id": 13,
      "first_name": "adam",
      "last_name": "cunliffe",
      "email": "adam@Weaveware.co.uk",
      "name": "adam cunliffe",
      "user_to_app_to_role_by_user_id": [
        {
          "id":1,
          "app_id": 4,
          "role_id": 1,
          "user_id": 13
        }
      ]
    }```


If you're not sure what the id number is you can do GET on system/user/<id>?related=user_to_app_to_role_by_user_id

#7

Hi Drew,

That makes sense, thanks very much for the help!