alerta / angular-alerta-webui

Alerta Web UI 6.0 (DEPRECATED) - See latest version Web UI 7.0
https://github.com/alerta/alerta-webui
MIT License
69 stars 52 forks source link

roles dropdown empty in user view #178

Closed escoand closed 5 years ago

escoand commented 5 years ago

roles dropdown empty in user view

I've a problem with the user view, especially with the roles drop down. They are empty and so it's impossible to change the role of a user via gui.

The data is loaded via API correctly:

{
  "permissions": [
    {
      "href": "https://.../perm/8ee7b92b-4a68-4d84-9053-19bcbc1fce70",
      "id": "8ee7b92b-4a68-4d84-9053-19bcbc1fce70",
      "match": "user",
      "scopes": [
        "read:alerts",
        "read:blackouts",
        "read:heartbeats"
      ]
    },
    {
      "href": "https://.../perm/97545288-17fc-4897-8a9b-d6257a740fc1",
      "id": "97545288-17fc-4897-8a9b-d6257a740fc1",
      "match": "ams",
      "scopes": [
        "read:alerts",
        "write:alerts",
        "read:blackouts",
        "write:blackouts",
        "read:heartbeats"
      ]
    }
  ],
  "status": "ok",
  "total": 2
}

The thrown error in the JavaScript console is:

16:23:33.678 "Error: [ngRepeat:dupes] http://errors.angularjs.org/1.5.11/ngRepeat/dupes?p0=role%20in%20roles&p1=string%3Auser&p2=user
G/<@https://.../vendor/js/angular.min.js:6:426
We</<.compile/</<@https://.../vendor/js/angular.min.js:308:39
If/this.$get</m.prototype.$watchCollection/<@https://.../vendor/js/angular.min.js:143:302
If/this.$get</m.prototype.$digest@https://.../vendor/js/angular.min.js:144:410
If/this.$get</m.prototype.$apply@https://.../vendor/js/angular.min.js:147:361
l@https://.../vendor/js/angular.min.js:99:192
K@https://.../vendor/js/angular.min.js:103:376
tg/</N.onload@https://.../vendor/js/angular.min.js:104:338
" 1 angular.min.js:119:446
    f/< https://.../vendor/js/angular.min.js:119:446
    vf/this.$get</< https://.../vendor/js/angular.min.js:92:42
    If/this.$get</m.prototype.$digest https://.../vendor/js/angular.min.js:145:66
    If/this.$get</m.prototype.$apply https://.../vendor/js/angular.min.js:147:361
    l https://.../vendor/js/angular.min.js:99:192
    K https://.../vendor/js/angular.min.js:103:376
    tg/</N.onload https://.../vendor/js/angular.min.js:104:338
satterly commented 5 years ago

Sorry but I can't reproduce this. I created 3 roles and can assign them to users without a problem...

{
  "permissions": [
    {
      "href": "http://localhost:8080/perm/d851aef9-3ced-4aa9-9803-cfe5a64cf44f",
      "id": "d851aef9-3ced-4aa9-9803-cfe5a64cf44f",
      "match": "read-only",
      "scopes": [
        "read"
      ]
    },
    {
      "href": "http://localhost:8080/perm/0cc50400-f7ea-4961-ae47-024711b9fec7",
      "id": "0cc50400-f7ea-4961-ae47-024711b9fec7",
      "match": "read-write",
      "scopes": [
        "write"
      ]
    },
    {
      "href": "http://localhost:8080/perm/fafed461-c1cc-4583-8437-7047ae2bc6bb",
      "id": "fafed461-c1cc-4583-8437-7047ae2bc6bb",
      "match": "websys",
      "scopes": [
        "admin"
      ]
    }
  ],
  "status": "ok",
  "total": 3
}
screenshot 2018-11-07 at 20 29 06

The error doesn't help me much either. It's just a trackback of angular framework code. There doesn't seem to be a reference to any alerta web UI code. Any chance there is more to that error than you managed to capture? Or anything else that might help debug this?

escoand commented 5 years ago

Found the reason with this: https://docs.angularjs.org/error/ngRepeat/dupes

So I tested with:

<span ng-repeat="role in roles track by $index">{{ $index }}:{{ roles[$index] }}, </span>

And got: 0:user, 1:ams, 2:user,

escoand commented 5 years ago

The question is now: where is the second user coming from? /api/perm is just exposing 2 roles.

Is it maybe because I've created the "user" role explicitly?

satterly commented 5 years ago

yes. you should modify the server configuration to set permissions for the default "user" role...

USER_DEFAULT_SCOPES = ['read', 'write']  # Note: 'write' scope implicitly includes 'read'

https://github.com/alerta/alerta/blob/371ab3c7144ba9ae83a895ed31053bb6147cccc0/alerta/settings.py#L59

escoand commented 5 years ago

thanks, it's working now. but maybe this could be described more clearly or maybe the controller should test if user is already existing.

satterly commented 5 years ago

It's probably both. ie. documentation should be better and the API should probably reject user-defined roles called "admin" and "user".