瀏覽代碼

Add new config setting `allow_adhoc_commands`

JC Brand 5 年之前
父節點
當前提交
2696c26ffb
共有 6 個文件被更改,包括 60 次插入31 次删除
  1. 4 3
      CHANGES.md
  2. 9 0
      docs/source/configuration.rst
  3. 21 14
      package-lock.json
  4. 1 1
      src/converse-profile.js
  5. 8 6
      src/templates/profile.js
  6. 17 7
      src/templates/user_settings_modal.js

+ 4 - 3
CHANGES.md

@@ -23,8 +23,6 @@ Soon we'll deprecate the latter, so prepare now.
 - #1963: Mentions are visually incorrect when used in message replies
 - #1963: Mentions are visually incorrect when used in message replies
 - Allow ignoring of bootstrap modules at build using environment variable. For xample: `export BOOTSTRAP_IGNORE_MODULES="Modal,Dropdown" && make dist`
 - Allow ignoring of bootstrap modules at build using environment variable. For xample: `export BOOTSTRAP_IGNORE_MODULES="Modal,Dropdown" && make dist`
 - Bugfix. Handle stanza that clears the MUC subject
 - Bugfix. Handle stanza that clears the MUC subject
-- New config option [modtools_disable_assign](https://conversejs.org/docs/html/configuration.html#modtools-disable-assign)
-- New config option [modtools_disable_query](https://conversejs.org/docs/html/configuration.html#modtools-disable-query)
 - Replace Backbone with [Skeletor](https://github.com/skeletorjs/skeletor)
 - Replace Backbone with [Skeletor](https://github.com/skeletorjs/skeletor)
 - Start using [lit-html](https://lit-html.polymer-project.org/) instead of lodash for templating.
 - Start using [lit-html](https://lit-html.polymer-project.org/) instead of lodash for templating.
 - [muc_fetch_members](https://conversejs.org/docs/html/configuration.html#muc-fetch-members) now also accepts an array of affiliations to fetch.
 - [muc_fetch_members](https://conversejs.org/docs/html/configuration.html#muc-fetch-members) now also accepts an array of affiliations to fetch.
@@ -32,8 +30,11 @@ Soon we'll deprecate the latter, so prepare now.
 - Support for XEP-0156 is now enabled by default (which means that
 - Support for XEP-0156 is now enabled by default (which means that
   [discover_connection_methods](https://conversejs.org/docs/html/configuration.html#discover-connection-methods) now has a default value of `true`).
   [discover_connection_methods](https://conversejs.org/docs/html/configuration.html#discover-connection-methods) now has a default value of `true`).
 - [show_send_button](https://conversejs.org/docs/html/configuration.html#show-send-button) now has a default value of `true`.
 - [show_send_button](https://conversejs.org/docs/html/configuration.html#show-send-button) now has a default value of `true`.
-- New configuration setting [muc_hats_from_vcard](https://conversejs.org/docs/html/configuration.html#muc-hats-from-vcard).
 - The [api.confirm](https://conversejs.org/docs/html/api/-_converse.api.html#.confirm) method now accepts a list of fields and returns the filled in list upon confirmation.
 - The [api.confirm](https://conversejs.org/docs/html/api/-_converse.api.html#.confirm) method now accepts a list of fields and returns the filled in list upon confirmation.
+- New config option [modtools_disable_assign](https://conversejs.org/docs/html/configuration.html#modtools-disable-assign)
+- New config option [modtools_disable_query](https://conversejs.org/docs/html/configuration.html#modtools-disable-query)
+- New config option [allow_adhoc_commands](https://conversejs.org/docs/html/configuration.html#allow-adhoc-commands)
+- New config option [muc_hats_from_vcard](https://conversejs.org/docs/html/configuration.html#muc-hats-from-vcard).
 
 
 ## 6.0.0 (2020-01-09)
 ## 6.0.0 (2020-01-09)
 
 

+ 9 - 0
docs/source/configuration.rst

@@ -98,6 +98,15 @@ Here's an example of Converse being initialized with these options:
         allow_logout: false
         allow_logout: false
     });
     });
 
 
+
+allow_adhoc_commands
+--------------------
+
+* Default:  ``true``
+
+Allows privileged users to run XEP-0050 Ad-Hoc commands via the settings modal.
+
+
 allow_bookmarks
 allow_bookmarks
 ---------------
 ---------------
 
 

+ 21 - 14
package-lock.json

@@ -2244,7 +2244,8 @@
 			"dependencies": {
 			"dependencies": {
 				"filesize": {
 				"filesize": {
 					"version": "6.1.0",
 					"version": "6.1.0",
-					"resolved": false
+					"resolved": "https://registry.npmjs.org/filesize/-/filesize-6.1.0.tgz",
+					"integrity": "sha512-LpCHtPQ3sFx67z+uh2HnSyWSLLu5Jxo21795uRDuar/EOuYWXib5EmPaGIBuSnRqH2IODiKA2k5re/K9OnN/Yg=="
 				},
 				},
 				"fs-extra": {
 				"fs-extra": {
 					"version": "8.1.0",
 					"version": "8.1.0",
@@ -2278,7 +2279,8 @@
 				},
 				},
 				"jed": {
 				"jed": {
 					"version": "1.1.1",
 					"version": "1.1.1",
-					"resolved": false
+					"resolved": "https://registry.npmjs.org/jed/-/jed-1.1.1.tgz",
+					"integrity": "sha1-elSbvZ/+FYWwzQoZHiAwVb7ldLQ="
 				},
 				},
 				"jsonfile": {
 				"jsonfile": {
 					"version": "5.0.0",
 					"version": "5.0.0",
@@ -2299,18 +2301,21 @@
 				},
 				},
 				"localforage": {
 				"localforage": {
 					"version": "1.7.3",
 					"version": "1.7.3",
-					"resolved": false,
+					"resolved": "https://registry.npmjs.org/localforage/-/localforage-1.7.3.tgz",
+					"integrity": "sha512-1TulyYfc4udS7ECSBT2vwJksWbkwwTX8BzeUIiq8Y07Riy7bDAAnxDaPU/tWyOVmQAcWJIEIFP9lPfBGqVoPgQ==",
 					"requires": {
 					"requires": {
 						"lie": "3.1.1"
 						"lie": "3.1.1"
 					}
 					}
 				},
 				},
 				"lodash": {
 				"lodash": {
 					"version": "4.17.15",
 					"version": "4.17.15",
-					"resolved": false
+					"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
+					"integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A=="
 				},
 				},
 				"pluggable.js": {
 				"pluggable.js": {
 					"version": "2.0.1",
 					"version": "2.0.1",
-					"resolved": false,
+					"resolved": "https://registry.npmjs.org/pluggable.js/-/pluggable.js-2.0.1.tgz",
+					"integrity": "sha512-SBt6v6Tbp20Jf8hU0cpcc/+HBHGMY8/Q+yA6Ih0tBQE8tfdZ6U4PRG0iNvUUjLx/hVyOP53n0UfGBymlfaaXCg==",
 					"requires": {
 					"requires": {
 						"lodash": "^4.17.11"
 						"lodash": "^4.17.11"
 					}
 					}
@@ -2324,11 +2329,13 @@
 				},
 				},
 				"strophe.js": {
 				"strophe.js": {
 					"version": "1.3.4",
 					"version": "1.3.4",
-					"resolved": false
+					"resolved": "https://registry.npmjs.org/strophe.js/-/strophe.js-1.3.4.tgz",
+					"integrity": "sha512-jSLDG8jolhAwGOSgiJ7DTMSYK3wVoEJHKtpVRyEacQZ6CWA6z2WRPJpcFMjsIweq5aP9/XIvKUQqHBu/ZhvESA=="
 				},
 				},
 				"twemoji": {
 				"twemoji": {
 					"version": "12.1.5",
 					"version": "12.1.5",
-					"resolved": false,
+					"resolved": "https://registry.npmjs.org/twemoji/-/twemoji-12.1.5.tgz",
+					"integrity": "sha512-B0PBVy5xomwb1M/WZxf/IqPZfnoIYy1skXnlHjMwLwTNfZ9ljh8VgWQktAPcJXu8080WoEh6YwQGPVhDVqvrVQ==",
 					"requires": {
 					"requires": {
 						"fs-extra": "^8.0.1",
 						"fs-extra": "^8.0.1",
 						"jsonfile": "^5.0.0",
 						"jsonfile": "^5.0.0",
@@ -12325,7 +12332,7 @@
 				},
 				},
 				"camelcase-keys": {
 				"camelcase-keys": {
 					"version": "2.1.0",
 					"version": "2.1.0",
-					"resolved": "http://registry.npmjs.org/camelcase-keys/-/camelcase-keys-2.1.0.tgz",
+					"resolved": "https://registry.npmjs.org/camelcase-keys/-/camelcase-keys-2.1.0.tgz",
 					"integrity": "sha1-MIvur/3ygRkFHvodkyITyRuPkuc=",
 					"integrity": "sha1-MIvur/3ygRkFHvodkyITyRuPkuc=",
 					"dev": true,
 					"dev": true,
 					"requires": {
 					"requires": {
@@ -12335,7 +12342,7 @@
 				},
 				},
 				"chalk": {
 				"chalk": {
 					"version": "1.1.3",
 					"version": "1.1.3",
-					"resolved": "http://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
+					"resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
 					"integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=",
 					"integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=",
 					"dev": true,
 					"dev": true,
 					"requires": {
 					"requires": {
@@ -12377,7 +12384,7 @@
 				},
 				},
 				"load-json-file": {
 				"load-json-file": {
 					"version": "1.1.0",
 					"version": "1.1.0",
-					"resolved": "http://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz",
+					"resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz",
 					"integrity": "sha1-lWkFcI1YtLq0wiYbBPWfMcmTdMA=",
 					"integrity": "sha1-lWkFcI1YtLq0wiYbBPWfMcmTdMA=",
 					"dev": true,
 					"dev": true,
 					"requires": {
 					"requires": {
@@ -12396,7 +12403,7 @@
 				},
 				},
 				"meow": {
 				"meow": {
 					"version": "3.7.0",
 					"version": "3.7.0",
-					"resolved": "http://registry.npmjs.org/meow/-/meow-3.7.0.tgz",
+					"resolved": "https://registry.npmjs.org/meow/-/meow-3.7.0.tgz",
 					"integrity": "sha1-cstmi0JSKCkKu/qFaJJYcwioAfs=",
 					"integrity": "sha1-cstmi0JSKCkKu/qFaJJYcwioAfs=",
 					"dev": true,
 					"dev": true,
 					"requires": {
 					"requires": {
@@ -17344,7 +17351,7 @@
 		},
 		},
 		"pinkie-promise": {
 		"pinkie-promise": {
 			"version": "2.0.1",
 			"version": "2.0.1",
-			"resolved": "http://registry.npmjs.org/pinkie-promise/-/pinkie-promise-2.0.1.tgz",
+			"resolved": "https://registry.npmjs.org/pinkie-promise/-/pinkie-promise-2.0.1.tgz",
 			"integrity": "sha1-ITXW36ejWMBprJsXh3YogihFD/o=",
 			"integrity": "sha1-ITXW36ejWMBprJsXh3YogihFD/o=",
 			"dev": true,
 			"dev": true,
 			"requires": {
 			"requires": {
@@ -19056,7 +19063,7 @@
 				},
 				},
 				"load-json-file": {
 				"load-json-file": {
 					"version": "1.1.0",
 					"version": "1.1.0",
-					"resolved": "http://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz",
+					"resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz",
 					"integrity": "sha1-lWkFcI1YtLq0wiYbBPWfMcmTdMA=",
 					"integrity": "sha1-lWkFcI1YtLq0wiYbBPWfMcmTdMA=",
 					"dev": true,
 					"dev": true,
 					"requires": {
 					"requires": {
@@ -19069,7 +19076,7 @@
 				},
 				},
 				"os-locale": {
 				"os-locale": {
 					"version": "1.4.0",
 					"version": "1.4.0",
-					"resolved": "http://registry.npmjs.org/os-locale/-/os-locale-1.4.0.tgz",
+					"resolved": "https://registry.npmjs.org/os-locale/-/os-locale-1.4.0.tgz",
 					"integrity": "sha1-IPnxeuKe00XoveWDsT0gCYA8FNk=",
 					"integrity": "sha1-IPnxeuKe00XoveWDsT0gCYA8FNk=",
 					"dev": true,
 					"dev": true,
 					"requires": {
 					"requires": {

+ 1 - 1
src/converse-profile.js

@@ -32,6 +32,7 @@ converse.plugins.add('converse-profile', {
         const { __ } = _converse;
         const { __ } = _converse;
 
 
         api.settings.update({
         api.settings.update({
+            'allow_adhoc_commands': true,
             'show_client_info': true
             'show_client_info': true
         });
         });
 
 
@@ -200,7 +201,6 @@ converse.plugins.add('converse-profile', {
                 return tpl_profile(Object.assign(
                 return tpl_profile(Object.assign(
                     this.model.toJSON(),
                     this.model.toJSON(),
                     this.model.vcard.toJSON(), {
                     this.model.vcard.toJSON(), {
-                    _converse,
                     chat_status,
                     chat_status,
                     'fullname': this.model.vcard.get('fullname') || _converse.bare_jid,
                     'fullname': this.model.vcard.get('fullname') || _converse.bare_jid,
                     "showUserSettingsModal": ev => this.showUserSettingsModal(ev),
                     "showUserSettingsModal": ev => this.showUserSettingsModal(ev),

+ 8 - 6
src/templates/profile.js

@@ -1,21 +1,23 @@
-import { html } from "lit-html";
 import { __ } from '@converse/headless/i18n';
 import { __ } from '@converse/headless/i18n';
-
+import { api } from "@converse/headless/converse-core";
+import { html } from "lit-html";
 
 
 const i18n_logout = __('Log out');
 const i18n_logout = __('Log out');
 const i18n_change_status = __('Click to change your chat status');
 const i18n_change_status = __('Click to change your chat status');
 const i18n_details = __('Show details about this chat client');
 const i18n_details = __('Show details about this chat client');
 
 
 
 
-export default (o) => html`
+export default (o) => {
+    const show_settings_button = api.settings.get('show_client_info') || api.settings.get('allow_adhoc_commands');
+    return html`
     <div class="userinfo controlbox-padded">
     <div class="userinfo controlbox-padded">
         <div class="controlbox-section profile d-flex">
         <div class="controlbox-section profile d-flex">
             <a class="show-profile" href="#">
             <a class="show-profile" href="#">
                 <canvas class="avatar align-self-center" height="40" width="40"></canvas>
                 <canvas class="avatar align-self-center" height="40" width="40"></canvas>
             </a>
             </a>
             <span class="username w-100 align-self-center">${o.fullname}</span>
             <span class="username w-100 align-self-center">${o.fullname}</span>
-            ${o._converse.api.settings.get('show_client_info') ? html`<a class="controlbox-heading__btn show-client-info fa fa-cog align-self-center" title="${i18n_details}" @click=${o.showUserSettingsModal}></a>` : ''}
-            ${o._converse.api.settings.get('allow_logout') ? html`<a class="controlbox-heading__btn logout fa fa-sign-out-alt align-self-center" title="${i18n_logout}"></a>` : ''}
+            ${show_settings_button  ? html`<a class="controlbox-heading__btn show-client-info fa fa-cog align-self-center" title="${i18n_details}" @click=${o.showUserSettingsModal}></a>` : ''}
+            ${api.settings.get('allow_logout') ? html`<a class="controlbox-heading__btn logout fa fa-sign-out-alt align-self-center" title="${i18n_logout}"></a>` : ''}
         </div>
         </div>
         <div class="d-flex xmpp-status">
         <div class="d-flex xmpp-status">
             <a class="change-status" title="${i18n_change_status}" data-toggle="modal" data-target="#changeStatusModal">
             <a class="change-status" title="${i18n_change_status}" data-toggle="modal" data-target="#changeStatusModal">
@@ -29,4 +31,4 @@ export default (o) => html`
             </a>
             </a>
         </div>
         </div>
     </div>
     </div>
-`;
+`};

+ 17 - 7
src/templates/user_settings_modal.js

@@ -1,9 +1,10 @@
+import '../components/adhoc-commands.js';
+import xss from "xss/dist/xss";
 import { __ } from '@converse/headless/i18n';
 import { __ } from '@converse/headless/i18n';
+import { api } from "@converse/headless/converse-core";
 import { html } from "lit-html";
 import { html } from "lit-html";
 import { modal_header_close_button } from "./buttons"
 import { modal_header_close_button } from "./buttons"
 import { unsafeHTML } from 'lit-html/directives/unsafe-html.js';
 import { unsafeHTML } from 'lit-html/directives/unsafe-html.js';
-import '../components/adhoc-commands.js';
-import xss from "xss/dist/xss";
 
 
 
 
 const i18n_modal_title = __('Settings');
 const i18n_modal_title = __('Settings');
@@ -35,7 +36,11 @@ const tpl_navigation = (o) => html`
 `;
 `;
 
 
 
 
-export default (o) => html`
+export default (o) => {
+    const show_client_info = api.settings.get('show_client_info');
+    const allow_adhoc_commands = api.settings.get('allow_adhoc_commands');
+    const show_both_tabs = show_client_info && allow_adhoc_commands;
+    return html`
     <div class="modal-dialog" role="document">
     <div class="modal-dialog" role="document">
         <div class="modal-content">
         <div class="modal-content">
             <div class="modal-header">
             <div class="modal-header">
@@ -43,10 +48,12 @@ export default (o) => html`
                 ${modal_header_close_button}
                 ${modal_header_close_button}
             </div>
             </div>
             <div class="modal-body">
             <div class="modal-body">
-                ${ tpl_navigation(o) }
+                ${ show_both_tabs ? tpl_navigation(o) : '' }
 
 
                 <div class="tab-content">
                 <div class="tab-content">
-                    <div class="tab-pane tab-pane--columns active" id="about-tabpanel" role="tabpanel" aria-labelledby="about-tab">
+                    <div class="tab-pane tab-pane--columns ${show_client_info ? 'active' : ''}"
+                         id="about-tabpanel" role="tabpanel" aria-labelledby="about-tab">
+
                         <span class="modal-alert"></span>
                         <span class="modal-alert"></span>
                         <br/>
                         <br/>
                         <div class="container brand-heading-container">
                         <div class="container brand-heading-container">
@@ -57,11 +64,14 @@ export default (o) => html`
                         </div>
                         </div>
                     </div>
                     </div>
 
 
-                    <div class="tab-pane tab-pane--columns" id="commands-tabpanel" role="tabpanel" aria-labelledby="commands-tab">
+                    <div class="tab-pane tab-pane--columns ${!show_client_info  && allow_adhoc_commands ? 'active' : ''}"
+                         id="commands-tabpanel"
+                         role="tabpanel"
+                         aria-labelledby="commands-tab">
                         <converse-adhoc-commands/>
                         <converse-adhoc-commands/>
                     </div>
                     </div>
                 </div>
                 </div>
             </div>
             </div>
         </div>
         </div>
     </div>
     </div>
-`;
+`};