Bug 1361255

Summary: UI plugin API: allow executing certain actions while the plugin is loading
Product: [oVirt] ovirt-engine Reporter: Vojtech Szocs <vszocs>
Component: Frontend.WebAdminAssignee: Vojtech Szocs <vszocs>
Status: CLOSED CURRENTRELEASE QA Contact: Pavel Novotny <pnovotny>
Severity: high Docs Contact:
Priority: unspecified    
Version: 4.0.2CC: bugs, gklein, oourfali, pstehlik, sbonazzo
Target Milestone: ovirt-4.0.2Flags: rule-engine: ovirt-4.0.z+
rule-engine: exception+
rule-engine: planning_ack+
oourfali: devel_ack+
pstehlik: testing_ack+
Target Release: 4.0.2.4   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Enhancement
Doc Text:
Background: UI plugin API performs requested actions only if the given plugin is either initializing (within UiInit callback) or in use (within other callbacks). This means all API actions are no-op while the plugin is loading, e.g. before the plugin calls the ready() function that triggers the UiInit callback. Feature: Allow following API functions to be executed also while the plugin is loading: - loginUserName - loginUserId - ssoToken - engineBaseUrl - currentLocale Above functions are considered "safe to call while loading" as they have no visual or other side effects on WebAdmin UI. Reason: Let UI plugins call above functions within their init code, e.g. before the plugin calls ready() to signal that it's ready for use. Result: Plugins able to call above functions within their init code.
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-08-17 14:44:56 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: UX RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1351585    
Attachments:
Description Flags
UI plugin used to verify the new API behavior none

Description Vojtech Szocs 2016-07-28 15:39:28 UTC
Description of problem:

UI plugin API performs requested actions only if the given plugin is either initializing (code within UiInit callback) or in use (code within other callbacks).

This means all API actions are no-op while the plugin is loading (before the plugin calls ready function that triggers UiInit callback).

Some API functions are "harmless" (e.g. without visual or other side effects):

- loginUserName
- loginUserId
- ssoToken
- engineBaseUrl
- currentLocale

For above mentioned actions, API should allow their execution even while the plugin is still loading.

Why is this important: let plugins do proper initialization (using api.currentLocale for example) *before* calling api.ready function.

There is no impact on existing UI plugins.

Steps to Reproduce:
1. var locale = api.currentLocale()
2. api.ready()
3. console.log('locale = ' + locale)

Actual results:
locale = undefined

Expected results:
locale = en-US (or similar)

Comment 1 Vojtech Szocs 2016-07-28 16:56:30 UTC
This change is low risk and has no impact on existing UI plugins.

The practical effect is relaxing the condition when UI plugin API interaction is allowed, but only for specific ("harmless") API functions.

Comment 2 Vojtech Szocs 2016-07-29 15:21:16 UTC
Created attachment 1185592 [details]
UI plugin used to verify the new API behavior

Comment 3 Vojtech Szocs 2016-07-29 15:26:30 UTC
Attached test UI plugin to ease the verification.

After loading WebAdmin page, browser console should say:

---Before ready call
null
null
<actual-sso-token>
<base-engine-path>
<webadmin-locale>

---After ready call
null
null
<actual-sso-token>
<base-engine-path>
<webadmin-locale>

The first two nulls are for loginUserName + loginUserId. This is expected behavior due to adopting SSO. I'll post another patch to address that.

Comment 4 Vojtech Szocs 2016-07-29 15:56:44 UTC
(In reply to vszocs from comment #3)
> The first two nulls are for loginUserName + loginUserId. This is expected
> behavior due to adopting SSO.

It's actually a bug, I've got the fix ready, will open a separate BZ on that.

Comment 5 Oved Ourfali 2016-08-02 06:43:14 UTC
Pavel - can you qe-ack?

Comment 6 Pavel Novotny 2016-08-16 17:35:46 UTC
Verified in 
rhevm-4.0.2.6-0.1.el7ev.noarch
ovirt-engine-webadmin-portal-4.0.2.6-0.1.el7ev.noarch

Verification:

I verified with Vojta's test UI plugin from attachment 1185592 [details].

After reloading the Webadmin page, the browser console says:
-~-
Tue Aug 16 19:22:23 GMT+200 2016 org.ovirt.engine.ui.webadmin.plugin.PluginManager
INFO: Plugin [loading-test] has registered the event handler object
plugin.html:11 ---Before ready call
plugin.html:12 null
plugin.html:13 null
plugin.html:14 YC6XzGIlksd_GMYqM5PbtcqsD12ff7Goz7EF6u869Egd52lu9aWkWgSQ8dZJeJTbBhBk0Bn_43tSEBaQchnGvw
plugin.html:15 https://rhvm.example.com/ovirt-engine/
plugin.html:16 en-US
webadmin-0.js:15466 Tue Aug 16 19:22:23 GMT+200 2016 org.ovirt.engine.ui.webadmin.plugin.PluginManager
INFO: Plugin [loading-test] reports in as ready
webadmin-0.js:15466 Tue Aug 16 19:22:24 GMT+200 2016 org.ovirt.engine.ui.webadmin.plugin.PluginManager
INFO: Plugin [dashboard] has registered the event handler object
webadmin-0.js:15466 Tue Aug 16 19:22:24 GMT+200 2016 org.ovirt.engine.ui.webadmin.plugin.PluginManager
INFO: Plugin [dashboard] reports in as ready
...
...
Tue Aug 16 19:22:26 GMT+200 2016 org.ovirt.engine.ui.webadmin.plugin.PluginManager
INFO: Invoking event handler function [UiInit] for plugin [loading-test]
plugin.html:11 ---After ready call
plugin.html:12 admin@internal-authz
plugin.html:13 0000002c-002c-002c-002c-000000000411
plugin.html:14 YC6XzGIlksd_GMYqM5PbtcqsD12ff7Goz7EF6u869Egd52lu9aWkWgSQ8dZJeJTbBhBk0Bn_43tSEBaQchnGvw
plugin.html:15 https://rhvm.example.com/ovirt-engine/
plugin.html:16 en-US
webadmin-0.js:15466 Tue Aug 16 19:22:26 GMT+200 2016 org.ovirt.engine.ui.webadmin.plugin.PluginManager
INFO: Plugin [loading-test] is initialized and in use now
webadmin-0.js:15466 Tue Aug 16 19:22:26 GMT+200 2016 org.ovirt.engine.ui.webadmin.plugin.PluginManager
INFO: Invoking event handler function [UserLogin] for plugin [loading-test]
-~-