Skip to content

Commit

Permalink
Merge pull request RocketChat#544 from assistify/hotfix/no-smarti-con…
Browse files Browse the repository at this point in the history
…nection

Don't load the Smarti Widget if Smarti is disabled
  • Loading branch information
mrsimpson authored Oct 23, 2018
2 parents 21c6e9a + 57cd00c commit 19c16dc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
4 changes: 4 additions & 0 deletions packages/assistify-ai/server/lib/SmartiAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ function terminateCurrentSync() {
*/
export class SmartiAdapter {

static isEnabled() {
return !!RocketChat.settings.get('Assistify_AI_Enabled');
}

/**
* Returns the webhook URL that reveives the analysis callback from Smarti.
*/
Expand Down
27 changes: 15 additions & 12 deletions packages/assistify-ai/server/methods/SmartiWidgetBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,25 @@ let script;
let timeoutHandle;

function loadSmarti() {

let script = RocketChat.RateLimiter.limitFunction(
SmartiProxy.propagateToSmarti, 5, 1000, {
userId(userId) {
return !RocketChat.authz.hasPermission(userId, 'send-many-messages');
if (SmartiAdapter.isEnabled()) {
let script = RocketChat.RateLimiter.limitFunction(
SmartiProxy.propagateToSmarti, 5, 1000, {
userId(userId) {
return !RocketChat.authz.hasPermission(userId, 'send-many-messages');
}
}
)(verbs.get, 'plugin/v1/rocket.chat.js');
if (!script.error && script) {
// add pseudo comment in order to make the script appear in the frontend as a file. This makes it de-buggable
script = `${ script } //# sourceURL=SmartiWidget.js`;
} else {
SystemLogger.error('Could not load Smarti script from', '${SMARTI-SERVER}/plugin/v1/rocket.chat.js');
throw new Meteor.Error('no-smarti-ui-script', 'no-smarti-ui-script');
}
)(verbs.get, 'plugin/v1/rocket.chat.js');
if (script) {
// add pseudo comment in order to make the script appear in the frontend as a file. This makes it de-buggable
script = `${ script } //# sourceURL=SmartiWidget.js`;
return script;
} else {
SystemLogger.error('Could not load Smarti script from', '${SMARTI-SERVER}/plugin/v1/rocket.chat.js');
throw new Meteor.Error('no-smarti-ui-script', 'no-smarti-ui-script');
return ''; // there is no script to be added, so return an empty source (and not null) - hte consumer expects a string
}
return script;
}

function delayedReload() {
Expand Down

0 comments on commit 19c16dc

Please sign in to comment.