Require permission or pref to debug in client
authorThomas Berezansky <tsbere@mvlc.org>
Mon, 15 Aug 2011 12:59:31 +0000 (08:59 -0400)
committerJason Etheridge <jason@esilibrary.com>
Tue, 4 Oct 2011 18:22:51 +0000 (14:22 -0400)
Disables all debug functions I know of unless:

1 - You have new DEBUG_CLIENT permission (after login)

This should work even on operator change.
Once a given debug interface is open you can change operator back.

2 - You have a client with the debug preference enabled

This causes the client in all places I touched to think you have DEBUG_CLIENT
This also allows debugging *before* login, including in the Standalone interface.

Debug functions I know of:

Debug box on login page (already protected by pref)
Debug items in Admin menu
    Venkman
    Javascript Shells
    Inspector
    Chrome List
CTRL+SHIFT+F7 debug box in overlays

Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>
Signed-off-by: Jason Etheridge <jason@esilibrary.com>
Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/xul/staff_client/chrome/content/OpenILS/util_overlay_chrome.xul
Open-ILS/xul/staff_client/chrome/content/OpenILS/util_overlay_offline.xul
Open-ILS/xul/staff_client/chrome/content/auth/controller.js
Open-ILS/xul/staff_client/chrome/content/main/main.js
Open-ILS/xul/staff_client/chrome/content/main/menu.js
Open-ILS/xul/staff_client/chrome/content/main/menu_frame_menus.xul
Open-ILS/xul/staff_client/server/OpenILS/util_overlay.xul

index 1c84e97..441b2b9 100644 (file)
@@ -1440,7 +1440,9 @@ INSERT INTO permission.perm_list ( id, code, description ) VALUES
  ( 511, 'PERSISTENT_LOGIN', oils_i18n_gettext( 511,
     'Allows a user to authenticate and get a long-lived session (length configured in opensrf.xml)', 'ppl', 'description' )),
  ( 512, 'ACQ_INVOICE_REOPEN', oils_i18n_gettext( 512,
-    'Allows a user to reopen an Acquisitions invoice', 'ppl', 'description' ));
+    'Allows a user to reopen an Acquisitions invoice', 'ppl', 'description' )),
+ ( 513, 'DEBUG_CLIENT', oils_i18n_gettext( 513,
+    'Allows a user to use debug functions in the staff client', 'ppl', 'description' ));
 
 SELECT SETVAL('permission.perm_list_id_seq'::TEXT, 1000);
 
index fdfb446..c4b023b 100644 (file)
@@ -71,7 +71,7 @@
             <button label="Inspect" oncommand="try { var dtb = document.getElementById('debug_tb'); var dx = eval( dtb.value ); var ds = ''; for (var di in dx) { ds += di + '=' + dx[di] + '\r\n'; }; window.open('data:text/plain;charset=UTF-8,'+window.escape(ds),'debug_win','chrome,resizable,modal'); } catch(E) { alert(E); }; dtb.focus();"/>
             <button label="js2JSON" oncommand="try { var dtb = document.getElementById('debug_tb'); alert( js2JSON( eval( dtb.value ) ) ); } catch(E) { alert(E); }; dtb.focus();"/>
         </hbox>
-        <keyset><key id="debug_box_key" keycode="VK_F7" modifiers="control,shift" oncommand="var dtb = document.getElementById('debug_tb'); var dx = document.getElementById('debug_box'); dx.hidden = !dx.hidden; if (!dx.hidden) dtb.focus();"/></keyset>
+        <keyset><key id="debug_box_key" keycode="VK_F7" modifiers="control,shift" oncommand="JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'}); var dtb = document.getElementById('debug_tb'); var dx = document.getElementById('debug_box'); if(data.enable_debug || !dx.hidden) { dx.hidden = !dx.hidden; if(!dx.hidden) dtb.focus();}"/></keyset>
  
         <script>dump('finished openils_util_overlay\n');</script>
     </scripts>
index 207469c..5b50799 100644 (file)
@@ -66,7 +66,7 @@
             <button label="Inspect" oncommand="try { var dtb = document.getElementById('debug_tb'); var dx = eval( dtb.value ); var ds = ''; for (var di in dx) { ds += di + '=' + dx[di] + '\r\n'; }; window.open('data:text/plain;charset=UTF-8,'+window.escape(ds),'debug_win','chrome,resizable,modal'); } catch(E) { alert(E); }; dtb.focus();"/>
             <button label="js2JSON" oncommand="try { var dtb = document.getElementById('debug_tb'); alert( js2JSON( eval( dtb.value ) ) ); } catch(E) { alert(E); }; dtb.focus();"/>
         </hbox>
-        <keyset><key id="debug_box_key" keycode="VK_F7" modifiers="control,shift" oncommand="var dtb = document.getElementById('debug_tb'); var dx = document.getElementById('debug_box'); dx.hidden = !dx.hidden; if (!dx.hidden) dtb.focus();"/></keyset>
+        <keyset><key id="debug_box_key" keycode="VK_F7" modifiers="control,shift" oncommand="JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'}); var dtb = document.getElementById('debug_tb'); var dx = document.getElementById('debug_box'); if(data.debug_build || data.enable_debug || !dx.hidden) { dx.hidden = !dx.hidden; if(!dx.hidden) dtb.focus();}"/></keyset>
  
     </scripts>
     <script>dump('Loaded OpenILS/util_overlay_offline.xul\n');</script>
index f0f8f8f..dd6de40 100644 (file)
@@ -553,8 +553,10 @@ auth.controller.prototype = {
         this.session.close();
         this.data.menu_perms = false;
         this.data.current_hotkeyset = undefined;
+        this.data.enable_debug = this.data.debug_client;
         this.data.stash('menu_perms');
         this.data.stash('current_hotkeyset');
+        this.data.stash('enable_debug');
 
         /* FIXME - need some locking or object destruction for the async tests */
         /* this.test_server( this.controller.view.server_prompt.value ); */
index 123e3de..9598484 100644 (file)
@@ -212,6 +212,15 @@ function get_menu_perms(indocument) {
             var r = network.simple_request('BATCH_PERM_RETRIEVE_WORK_OU', [ G.data.session.key, get_menu_perms.perm_list ]);
             for(p in r)
                 r[p] = (typeof(r[p][0]) == 'number');
+            // Developer-enabled clients override permissions and always allow debugging
+            if(G.data.debug_build) {
+                r['DEBUG_CLIENT'] = true;
+            }
+            // If we have DEBUG_CLIENT (by force or otherwise) we can use debugging interfaces
+            // Doing this here because this function gets called at least once per login
+            // Including operator change
+            G.data.enable_debug = (r['DEBUG_CLIENT'] == true);
+            G.data.stash('enable_debug');
             G.data.menu_perms = r;
             G.data.stash('menu_perms');
         }
@@ -524,6 +533,12 @@ function main_init() {
         } catch(E) {
         }
 
+        // If we are showing the debugging frame then we consider this a debug build
+        // This could be a versionless build, a developer-pref enabled build, or otherwise
+        // If set this will enable all debugging commands, even if you normally don't have permission to use them
+        G.data.debug_build = !document.getElementById('debug_gb').hidden;
+        G.data.stash('debug_build');
+
         var appInfo = Components.classes["@mozilla.org/xre/app-info;1"] 
             .getService(Components.interfaces.nsIXULAppInfo); 
 
index a68b9bf..61d239c 100644 (file)
@@ -1585,6 +1585,46 @@ main.menu.prototype = {
                         xulG.pref.clearUserPref('open-ils.menu.toolbar.labelbelow');
                 }
             ],
+            'cmd_debug_venkman' : [
+                ['oncommand'],
+                function() {
+                    try{
+                        xulG.window.win.start_debugger();
+                    } catch(E) {
+                        alert(E);
+                    }
+                }
+            ],
+            'cmd_debug_inspector' : [
+                ['oncommand'],
+                function() {
+                    try{
+                        xulG.window.win.start_inspector();
+                    } catch(E) {
+                        alert(E);
+                    }
+                }
+            ],
+            'cmd_debug_chrome_list' : [
+                ['oncommand'],
+                function() {
+                    try{
+                        xulG.window.win.start_chrome_list();
+                    } catch(E) {
+                        alert(E);
+                    }
+                }
+            ],
+            'cmd_debug_chrome_shell' : [
+                ['oncommand'],
+                function() {
+                    try{
+                        xulG.window.win.start_js_shell();
+                    } catch(E) {
+                        alert(E)
+                    }
+                }
+            ],
         };
 
         JSAN.use('util.controller');
index 014ffab..4ec89a3 100644 (file)
     <command id="cmd_local_admin" />
     <command id="cmd_toggle_meters" />
 
-    <command id="cmd_extension_manager" />
-    <command id="cmd_theme_manager" />
-    <command id="cmd_about_config" />
+    <command id="cmd_extension_manager"
+             perm="DEBUG_CLIENT"
+             />
+    <command id="cmd_theme_manager"
+             perm="DEBUG_CLIENT"
+             />
+    <command id="cmd_about_config"
+             perm="DEBUG_CLIENT"
+             />
 
     <command id="cmd_adv_user_edit" />
-    <command id="cmd_console" />
-    <command id="cmd_shell" />
-    <command id="cmd_xuleditor" />
+    <command id="cmd_console"
+             perm="DEBUG_CLIENT" />
+    <command id="cmd_shell"
+             perm="DEBUG_CIENT"
+             />
+    <command id="cmd_xuleditor"
+             perm="DEBUG_CLIENT"
+             />
     <command id="cmd_fieldmapper" />
     <command id="cmd_test_html" />
     <command id="cmd_test_xul" />
     <command id="cmd_toolbar_mode_set" />
     <command id="cmd_toolbar_size_set" />
     <command id="cmd_toolbar_label_position_set" />
+    <command id="cmd_debug_venkman"
+             perm="DEBUG_CLIENT"
+             />
+    <command id="cmd_debug_inspector"
+             perm="DEBUG_CLIENT"
+             />
+    <command id="cmd_debug_chrome_list"
+             perm="DEBUG_CLIENT"
+             />
+    <command id="cmd_debug_chrome_shell"
+             perm="DEBUG_CLIENT"
+             />
 </commandset>
 
 <!-- The File menu on the main menu -->
                 <menuitem label="&staff.main.menu.admin.fieldmapper.label;" accesskey="&staff.main.menu.admin.fieldmapper.accesskey;" command="cmd_fieldmapper"/>
                 <menuitem label="&staff.main.menu.admin.cmd_console.label;" accesskey="&staff.main.menu.admin.cmd_console.accesskey;" command="cmd_console"/>
                 <menuitem label="&staff.main.menu.admin.cmd_shell.label;" accesskey="&staff.main.menu.admin.cmd_shell.accesskey;" command="cmd_shell"/>
-                <menuitem label="&staff.main.menu.admin.cmd_chrome_shell.label;" accesskey="&staff.main.menu.admin.cmd_chrome_shell.accesskey;" 
-                    oncommand="try{xulG.window.win.start_js_shell();}catch(E){alert(E);}"/>
+                <menuitem label="&staff.main.menu.admin.cmd_chrome_shell.label;" accesskey="&staff.main.menu.admin.cmd_chrome_shell.accesskey;" command="cmd_debug_chrome_shell"/> 
                 <menuitem label="server/main/test.html" accesskey="1" command="cmd_test_html"/>
                 <menuitem label="server/main/test.xul" accesskey="2" command="cmd_test_xul"/>
                 <menuitem label="&staff.main.menu.admin.clear_cache.label;" accesskey="&staff.main.menu.admin.clear_cache.accesskey;" command="cmd_clear_cache"/>
                 <menuitem label="&staff.main.menu.admin.extension_manager.label;" command="cmd_extension_manager"/>
                 <menuitem label="&staff.main.menu.admin.theme_manager.label;" command="cmd_theme_manager"/>
                 <menuitem label="&staff.main.menu.admin.about_config.label;" command="cmd_about_config"/>
-                <menuitem label="&staff.main.menu.admin.venkman.label;" oncommand="try{xulG.window.win.start_debugger();}catch(E){alert(E);}"/>
-                <menuitem label="&staff.main.auth.debug.inspector;" oncommand="try{xulG.window.win.start_inspector();}catch(E){alert(E);}"/>
-                <menuitem label="&staff.main.auth.debug.chrome_list;" oncommand="try{xulG.window.win.start_chrome_list();}catch(E){alert(E);}"/>
+                <menuitem label="&staff.main.menu.admin.venkman.label;" command="cmd_debug_venkman"/>
+                <menuitem label="&staff.main.auth.debug.inspector;" command="cmd_debug_inspector"/>
+                <menuitem label="&staff.main.auth.debug.chrome_list;" command="cmd_debug_chrome_list"/>
                 <menuitem label="&staff.main.menu.admin.ping;" oncommand="try{netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');JSAN.use('util.network'); var n = new util.network(); alert(n.ping());}catch(E){alert(E);}"/>
             </menupopup>
         </menu>
index 242acdc..f185b79 100644 (file)
@@ -88,7 +88,7 @@
             <button label="Inspect" oncommand="try { var dtb = document.getElementById('debug_tb'); var dx = eval( dtb.value ); var ds = ''; for (var di in dx) { ds += di + '=' + dx[di] + '\r\n'; }; window.open('data:text/plain;charset=UTF-8,'+window.escape(ds),'debug_win','chrome,resizable,modal'); } catch(E) { alert(E); }; dtb.focus();"/>
             <button label="js2JSON" oncommand="try { var dtb = document.getElementById('debug_tb'); alert( js2JSON( eval( dtb.value ) ) ); } catch(E) { alert(E); }; dtb.focus();"/>
         </hbox>
-        <keyset><key id="debug_box_key" keycode="VK_F7" modifiers="control,shift" oncommand="var dtb = document.getElementById('debug_tb'); var dx = document.getElementById('debug_box'); dx.hidden = !dx.hidden; if (!dx.hidden) dtb.focus();"/></keyset>
+        <keyset><key id="debug_box_key" keycode="VK_F7" modifiers="control,shift" oncommand="JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'}); var dtb = document.getElementById('debug_tb'); var dx = document.getElementById('debug_box'); if(data.enable_debug || !dx.hidden) { dx.hidden = !dx.hidden; if(!dx.hidden) dtb.focus();}"/></keyset>
         <script type="text/javascript" src="/xul/server/skin/custom.js" />
         <script>dump('finished openils_util_overlay\n');</script>
     </scripts>