kuzzleio / kuzzle

Open-source Back-end, self-hostable & ready to use - Real-time, storage, advanced search - Web, Apps, Mobile, IoT -
https://kuzzle.io
Apache License 2.0
1.43k stars 123 forks source link

Users match the wrong Profile #305

Closed xbill82 closed 8 years ago

xbill82 commented 8 years ago

If I create a user associated with a profile dummy-profile that actually exists, then I get the user by id, I see the right profile in the _source attribute, but I see the profile attribute in the result contains the default one.

{
  "action": "getUser",
  "controller": "security",
  "error": null,
  "metadata": {},
  "requestId": "7223fd3c-f7e5-489a-9e9e-371c9bc86395",
  "result": {
    "_id": "dummy-user",
    "_source": {
      "_index": "%kuzzle",
      "_source": {
        "profile": "dummy-profile",
        "username": "dummy-user"
      },
      "_type": "users",
      "_version": 1,
      "found": true,
      "profile": {
        "_id": "default",
        "_source": {
          "roles": [
            {
              "_id": "default",
              "_source": {
                "allowInternalIndex": true,
                "controllers": {
                  "*": {
                    "actions": {
                      "*": true
                    }
                  }
                }
              }
            }
          ]
        }
      }
    }
  },
  "status": 200
}

Computing the rights array associated with the user (via the ~security::getUserRights method) confirms this, since the resulting rights are clearly issued from the default profile.

Note that this happens both when creating the User from a fixtures.json file and when creating it via the REST API.

ballinette commented 8 years ago

I cannot reproduce the issue here :(

On which branch are you ? And which version of Elasticsearch container ?

ballinette commented 8 years ago

The result we see in your environment is very strange. We should see something like that:

{
  "action": "getUser",
  "controller": "security",
  "error": null,
  "metadata": {},
  "requestId": "7223fd3c-f7e5-489a-9e9e-371c9bc86395",
  "result": {
    "_id": "dummy-user",
      "username": "dummy-user"
      "profile": {
        "_id": "dummy-profile",
        "_source": {
          "roles": [
             // (profile's roles)
          ]
        }
      }
    }
  },
  "status": 200
}

I don't undestand where following data come from:

      "_index": "%kuzzle",
      "_source": {
        "profile": "dummy-profile",
        "username": "dummy-user"
      },
      "_type": "users",
      "_version": 1,
      "found": true,

We should have a look at userRepository.js and repository.js code within lib/api/code/models/repositories, and specially trace in which format is the result of "this.readEngine.get" (within Repository.prototype.loadOneFromDatabase).

xbill82 commented 8 years ago

This seems to be solved by #312