antonvdl opened a new issue, #14847:
URL: https://github.com/apache/cloudstack/issues/14847

   ### problem
   
   On a fresh session the UI stays empty and the console shows:
   
   ```
   TypeError: store.getters.zones.filter is not a function
       at Object.show (network.js)
       ...
       at GenerateRoutes (permission.js)
   ```
   
   A reload (F5) fixes it. We see it for users with a User-type role and a 
short API list; a DomainAdmin user with a longer API list usually does not hit 
it.
   
   Cause: in `ui/src/store/modules/user.js` the state starts with `zones: {}` 
(an object, not an array). `GetInfo` starts `listZones` and `listApis` in 
parallel and dispatches `GenerateRoutes` as soon as `listApis` returns, without 
waiting for `listZones`. When `listApis` returns first, the `show` of the 
`securitygroups` section in `ui/src/config/section/network.js` calls 
`store.getters.zones.filter(...)` on `{}`. The `createNetwork` show and the 
`vnfapp` details have the same unguarded call. On a reload the cached branch of 
`GetInfo` commits the zones from local storage before anything else, so there 
is no race.
   
   
   ### versions
   
   Apache CloudStack 4.22.1.0 (management server and UI), KVM, advanced zones. 
Login via SAML2 (Keycloak). The same code (`zones: {}` and no wait on 
`listZones` before `GenerateRoutes`) is on the 4.22 branch and on main.
   
   ### The steps to reproduce the bug
   
   1. Create a custom role of type User with a short allow-list that includes 
`listApis`, `listZones`, `listSecurityGroups`, `listUsers`, `listCapabilities`, 
`listLdapConfigurations`, `listNetworkServiceProviders` and 
`cloudianIsEnabled`, ending with `*,deny`.
   2. Create an account with that role and a user, and authorise the user for 
SAML.
   3. Open a new private browser window and log in through SAML.
   4. In the network tab, `listApis` returns before `listZones`; the UI stays 
empty and the console shows `store.getters.zones.filter is not a function`.
   5. Press F5: the UI loads normally.
   
   It is timing dependent: the shorter the API list of the role, the more often 
`listApis` wins.
   
   ### What to do about it?
   
   - Initialise `zones` as `[]` in the state of `ui/src/store/modules/user.js`.
   - Wait for `listZones` (and `SET_ZONES`) before dispatching `GenerateRoutes` 
in `GetInfo`.
   - Guard the `show` functions in `ui/src/config/section/network.js` (and the 
`vnfapp` details) with `Array.isArray(store.getters.zones)`.
   
   Any one of the first two fixes the race; the guard makes the menu robust 
against a missing zone list.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

  • [I] UI: store.getters.zones.fi... antonvdl (via GitHub) via commits

Reply via email to