Add permissions;

Fixed bugs;
pull/6110/head
Marcelo Schmidt 9 years ago
parent 66309d806a
commit 09eb833a79
No known key found for this signature in database
GPG Key ID: CA48C21A7B66097E
  1. 65
      packages/rocketchat-autotranslate/client/lib/actionButton.js
  2. 4
      packages/rocketchat-autotranslate/client/lib/autotranslate.js
  3. 2
      packages/rocketchat-autotranslate/client/lib/tabBar.js
  4. 3
      packages/rocketchat-autotranslate/client/stylesheets/autotranslate.less
  5. 84
      packages/rocketchat-autotranslate/client/views/autoTranslateFlexTab.html
  6. 6
      packages/rocketchat-autotranslate/client/views/autoTranslateFlexTab.js
  7. 1
      packages/rocketchat-autotranslate/package.js
  8. 2
      packages/rocketchat-autotranslate/server/autotranslate.js
  9. 4
      packages/rocketchat-autotranslate/server/methods/getSupportedLanguages.js
  10. 4
      packages/rocketchat-autotranslate/server/methods/saveSettings.js
  11. 3
      packages/rocketchat-autotranslate/server/models/Subscriptions.js
  12. 5
      packages/rocketchat-autotranslate/server/permissions.js
  13. 1
      packages/rocketchat-i18n/i18n/en.i18n.json
  14. 20
      packages/rocketchat-theme/client/vendor/fontello/css/fontello.css
  15. 5
      packages/rocketchat-ui-message/message/message.coffee

@ -1,43 +1,32 @@
Meteor.startup(function() {
RocketChat.MessageAction.addButton({
id: 'show-original-message',
icon: 'icon-language',
i18nLabel: 'Show_original_message',
context: [
'message',
'message-mobile'
],
action() {
const message = this._arguments[1];
RocketChat.MessageAction.hideDropDown();
RocketChat.models.Messages.update({ _id: message._id }, { $set: { autoTranslateShowOriginal: true } });
},
Tracker.autorun(function() {
if (RocketChat.settings.get('AutoTranslate_Enabled') && RocketChat.authz.hasAtLeastOnePermission(['auto-translate'])) {
RocketChat.MessageAction.addButton({
id: 'toggle-language',
icon: 'icon-language',
i18nLabel: 'Toggle_original_translated',
context: [
'message',
'message-mobile'
],
action() {
const message = this._arguments[1];
RocketChat.MessageAction.hideDropDown();
if (message.autoTranslateShowInverse) {
RocketChat.models.Messages.update({ _id: message._id }, { $unset: { autoTranslateShowInverse: true } });
} else {
RocketChat.models.Messages.update({ _id: message._id }, { $set: { autoTranslateShowInverse: true } });
}
},
validation(message) {
return message && !message.autoTranslateShowOriginal && message.u && message.u._id !== Meteor.userId();
},
validation(message) {
return message && message.u && message.u._id !== Meteor.userId();
},
order: 90
});
RocketChat.MessageAction.addButton({
id: 'show-translated-message',
icon: 'icon-language',
i18nLabel: 'Show_translated_message',
context: [
'message',
'message-mobile'
],
action() {
const message = this._arguments[1];
RocketChat.MessageAction.hideDropDown();
RocketChat.models.Messages.update({ _id: message._id }, { $unset: { autoTranslateShowOriginal: 1 } });
},
validation(message) {
return message && message.autoTranslateShowOriginal && message.u && message.u._id !== Meteor.userId();
},
order: 90
order: 90
});
} else {
RocketChat.MessageAction.removeButton('toggle-language');
}
});
});

@ -1,10 +1,10 @@
Meteor.startup(function() {
Tracker.autorun(function() {
if (RocketChat.settings.get('AutoTranslate_Enabled')) {
if (RocketChat.settings.get('AutoTranslate_Enabled') && RocketChat.authz.hasAtLeastOnePermission(['auto-translate'])) {
RocketChat.callbacks.add('renderMessage', (message) => {
if (message.u._id !== Meteor.userId()) {
const subscription = RocketChat.models.Subscriptions.findOne({ rid: message.rid }, { fields: { autoTranslate: 1, autoTranslateLanguage: 1, autoTranslateDisplay: 1 } });
if (subscription && subscription.autoTranslate === true && subscription.autoTranslateDisplay === true && subscription.autoTranslateLanguage && !message.autoTranslateShowOriginal) {
if (subscription && subscription.autoTranslate === true && subscription.autoTranslateLanguage && !!subscription.autoTranslateDisplay !== !!message.autoTranslateShowInverse) {
const autoTranslateLanguage = subscription.autoTranslateLanguage;
if (!message.translations) {
message.translations = {};

@ -1,6 +1,6 @@
Meteor.startup(function() {
Tracker.autorun(function() {
if (RocketChat.settings.get('AutoTranslate_Enabled')) {
if (RocketChat.settings.get('AutoTranslate_Enabled') && RocketChat.authz.hasAtLeastOnePermission(['auto-translate'])) {
RocketChat.TabBar.addButton({
groups: ['channel', 'group', 'direct'],
id: 'autotranslate',

@ -34,8 +34,7 @@
}
}
.message {
.message {
.translated {
border-left: 1px dotted;
padding-left: 3px;

@ -1,51 +1,53 @@
<template name="autoTranslateFlexTab">
<div class="content">
<div class="list-view autotranslate">
<div class="title">
<h2>{{_ "Auto_Translate"}}</h2>
</div>
<form>
<ul class="list clearfix">
<li>
<label>{{_ "Enabled"}}</label>
<div>
<div class="input checkbox toggle">
<input type="checkbox" id="autoTranslate" name="autoTranslate" value="1" checked="{{$eq autoTranslate true}}" />
<label for="autoTranslate"></label>
</div>
</div>
</li>
{{#if $eq autoTranslate true}}
{{#requiresPermission 'auto-translate'}}
<div class="list-view autotranslate">
<div class="title">
<h2>{{_ "Auto_Translate"}}</h2>
</div>
<form>
<ul class="list clearfix">
<li>
<label>{{_ "Target_Language"}}</label>
<div>
{{#if editing 'autoTranslateLanguage'}}
<label>
<select name="autoTranslateLanguage">
{{#each supportedLanguages}}
<option value="{{language}}" selected={{$eq language autoTranslateLanguage}}>{{$or name language}}</option>
{{/each}}
</select>
</label>
<button type="button" class="button cancel">{{_ "Cancel"}}</button>
<button type="button" class="button primary save">{{_ "Save"}}</button>
{{else}}
<span class="current-setting">{{languageName autoTranslateLanguage}} <i class="icon-pencil" data-edit="autoTranslateLanguage"></i></span>
{{/if}}
</div>
</li>
<li>
<label>{{_ "Display_translated_text"}}</label>
<label>{{_ "Enabled"}}</label>
<div>
<div class="input checkbox toggle">
<input type="checkbox" id="autoTranslateDisplay" name="autoTranslateDisplay" value="1" checked="{{$eq autoTranslateDisplay true}}"/>
<label for="autoTranslateDisplay"></label>
<input type="checkbox" id="autoTranslate" name="autoTranslate" value="1" checked="{{$eq autoTranslate true}}" />
<label for="autoTranslate"></label>
</div>
</div>
</li>
{{/if}}
</ul>
</form>
</div>
{{#if $eq autoTranslate true}}
<li>
<label>{{_ "Target_Language"}}</label>
<div>
{{#if editing 'autoTranslateLanguage'}}
<label>
<select name="autoTranslateLanguage">
{{#each supportedLanguages}}
<option value="{{language}}" selected={{$eq language autoTranslateLanguage}}>{{$or name language}}</option>
{{/each}}
</select>
</label>
<button type="button" class="button cancel">{{_ "Cancel"}}</button>
<button type="button" class="button primary save">{{_ "Save"}}</button>
{{else}}
<span class="current-setting">{{languageName autoTranslateLanguage}} <i class="icon-pencil" data-edit="autoTranslateLanguage"></i></span>
{{/if}}
</div>
</li>
<li>
<label>{{_ "Display_translated_text"}}</label>
<div>
<div class="input checkbox toggle">
<input type="checkbox" id="autoTranslateDisplay" name="autoTranslateDisplay" value="1" checked="{{$eq autoTranslateDisplay true}}"/>
<label for="autoTranslateDisplay"></label>
</div>
</div>
</li>
{{/if}}
</ul>
</form>
</div>
{{/requiresPermission}}
</div>
</template>

@ -106,6 +106,12 @@ Template.autoTranslateFlexTab.onCreated(function() {
if (err) {
return handleError(err);
}
// Update all visible messages to reflect this setting
if (field === 'autoTranslate' || field === 'autoTranslateDisplay') {
RocketChat.models.Messages.update({ rid: Session.get('openedRoom') }, { $unset: { autoTranslateShowInverse: 1 }, $set: { random: Random.id() } }, { multi: true });
}
this.editing.set();
});
}

@ -27,6 +27,7 @@ Package.onUse(function(api) {
api.addFiles([
'server/settings.js',
'server/autotranslate.js',
'server/permissions.js',
'server/models/Messages.js',
'server/models/Subscriptions.js',
'server/methods/saveSettings.js',

@ -68,7 +68,7 @@ class AutoTranslate {
if (this.enabled && this.apiKey && message.msg) {
Meteor.defer(() => {
const translations = {};
const targetLanguages = RocketChat.models.Subscriptions.getAutoTranslateLanguagesByRoom(room._id);
const targetLanguages = RocketChat.models.Subscriptions.getAutoTranslateLanguagesByRoomAndNotUser(room._id, message.u && message.u._id);
message.html = s.escapeHTML(String(message.msg));
message = this.tokenize(message);

@ -1,5 +1,9 @@
Meteor.methods({
'autoTranslate.getSupportedLanguages'(targetLanguage) {
if (!RocketChat.authz.hasPermission(Meteor.userId(), 'auto-translate')) {
throw new Meteor.Error('error-action-now-allowed', 'Auto-Translate is not allowed', { method: 'autoTranslate.saveSettings'});
}
return RocketChat.AutoTranslate.getSupportedLanguages(targetLanguage);
}
});

@ -4,6 +4,10 @@ Meteor.methods({
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'saveAutoTranslateSettings' });
}
if (!RocketChat.authz.hasPermission(Meteor.userId(), 'auto-translate')) {
throw new Meteor.Error('error-action-now-allowed', 'Auto-Translate is not allowed', { method: 'autoTranslate.saveSettings'});
}
check(rid, String);
check(field, String);
check(value, String);

@ -57,11 +57,12 @@ RocketChat.models.Subscriptions.updateAutoTranslateDisplayById = function(_id, a
return this.update(query, update);
};
RocketChat.models.Subscriptions.getAutoTranslateLanguagesByRoom = function(rid) {
RocketChat.models.Subscriptions.getAutoTranslateLanguagesByRoomAndNotUser = function(rid, userId) {
const subscriptionsRaw = RocketChat.models.Subscriptions.model.rawCollection();
const distinct = Meteor.wrapAsync(subscriptionsRaw.distinct, subscriptionsRaw);
const query = {
rid: rid,
'u._id': { $ne: userId },
autoTranslate: true
};
return distinct('autoTranslateLanguage', query);

@ -0,0 +1,5 @@
Meteor.startup(() => {
if (RocketChat.models && RocketChat.models.Permissions) {
RocketChat.models.Permissions.createOrUpdate('auto-translate', ['admin']);
}
});

@ -1475,6 +1475,7 @@
"To_install_RocketChat_Livechat_in_your_website_copy_paste_this_code_above_the_last_body_tag_on_your_site": "To install Rocket.Chat Livechat in your website, copy &amp; paste this code above the last <strong>&lt;/body&gt;</strong> tag on your site.",
"to_see_more_details_on_how_to_integrate": "to see more details on how to integrate.",
"To_users": "To Users",
"Toggle_original_translated": "Toggle original/translated",
"Topic": "Topic",
"Travel_and_Places": "Travel & Places",
"Transcript_Enabled": "Ask visitor if they would like a transcript after chat closed",

@ -19,42 +19,42 @@
}
}
*/
[class^="icon-"]:before, [class*=" icon-"]:before {
font-family: "fontello";
font-style: normal;
font-weight: normal;
speak: none;
display: inline-block;
text-decoration: inherit;
width: 1em;
margin-right: .2em;
text-align: center;
/* opacity: .8; */
/* For safety - reset parent styles, that can break glyph codes*/
font-variant: normal;
text-transform: none;
/* fix buttons height, for twitter bootstrap */
line-height: 1em;
/* Animation center compensation - margins should be symmetric */
/* remove if not needed */
margin-left: .2em;
/* you can be more comfortable with increased icons size */
/* font-size: 120%; */
/* Font smoothing. That was taken from TWBS */
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
/* Uncomment for 3D effect */
/* text-shadow: 1px 1px 1px rgba(127, 127, 127, 0.3); */
}
.icon-parking:before { content: '\21'; } /* '!' */
.icon-bedroom:before { content: '\22'; } /* '&quot;' */
.icon-elevator:before { content: '\23'; } /* '#' */
@ -540,4 +540,4 @@
.icon-no-newline:before { content: '\e98d'; } /* '' */
.icon-tools:before { content: '\e98e'; } /* '' */
.icon-tape:before { content: '\e98f'; } /* '' */
.icon-language:before { content: '\f1ab'; } /* '' */
.icon-language:before { content: '\f1ab'; } /* '' */

@ -40,8 +40,9 @@ Template.message.helpers
return 'system'
showTranslated: ->
subscription = RocketChat.models.Subscriptions.findOne({ rid: Session.get('openedRoom') }, { fields: { autoTranslate: 1, autoTranslateLanguage: 1, autoTranslateDisplay: 1 } });
return this.u?._id isnt Meteor.userId() and not this.autoTranslateShowOriginal and subscription?.autoTranslate is true and subscription.autoTranslateDisplay is true and subscription.autoTranslateLanguage and RocketChat.settings.get('AutoTranslate_Enabled')
if RocketChat.settings.get('AutoTranslate_Enabled') and this.u?._id isnt Meteor.userId() and !RocketChat.MessageTypes.isSystemMessage(this)
subscription = RocketChat.models.Subscriptions.findOne({ rid: this.rid }, { fields: { autoTranslate: 1, autoTranslateLanguage: 1, autoTranslateDisplay: 1 } });
return subscription.autoTranslate && !!subscription?.autoTranslateDisplay isnt !!this.autoTranslateShowInverse
edited: ->
return Template.instance().wasEdited

Loading…
Cancel
Save