Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into fix/…
Browse files Browse the repository at this point in the history
…readmessages

* 'develop' of github.com:RocketChat/Rocket.Chat:
  [NEW] Setting to only send plain text emails (#16065)
  Regression: Fix status bar margins (#16438)
  [NEW] Check the Omnichannel service status per Department (#16425)
  [IMPROVE] Show more information related to the Omnichannel room closing data (#16414)
  Fix index creation for apps_logs collection (#16401)
  Revert message properties validation (#16395)
  [FIX] Rooms not being marked as read sometimes (#16397)
  Update apps engine to 1.12.0-beta.2496 (#16398)
  [FIX] Container heights (#16388)
  Regression: App deletion wasn’t returning the correct information (#16360)
  • Loading branch information
ggazzo committed Feb 3, 2020
2 parents f1e20b8 + b634bc4 commit 6663679
Show file tree
Hide file tree
Showing 25 changed files with 179 additions and 174 deletions.
4 changes: 2 additions & 2 deletions app/apps/server/bridges/livechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export class AppLivechatBridge {
this.orch = orch;
}

isOnline() {
return Livechat.online();
isOnline(department) {
return Livechat.online(department);
}

async createMessage(message, appId) {
Expand Down
2 changes: 1 addition & 1 deletion app/apps/server/bridges/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class AppMessageBridge {

const convertedMessage = this.orch.getConverters().get('messages').convertAppMessage(message);

const sentMessage = executeSendMessage(convertedMessage.u._id, convertedMessage, true);
const sentMessage = executeSendMessage(convertedMessage.u._id, convertedMessage);

return sentMessage._id;
}
Expand Down
14 changes: 6 additions & 8 deletions app/apps/server/communication/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,14 +461,12 @@ export class AppsRestApi {
return API.v1.notFound(`No App found by the id of: ${ this.urlParams.id }`);
}

manager.remove(prl.getID())
.then(() => {
const info = prl.getInfo();
info.status = prl.getStatus();

API.v1.success({ app: info });
})
.catch((err) => API.v1.failure(err));
Promise.await(manager.remove(prl.getID()));

const info = prl.getInfo();
info.status = prl.getStatus();

return API.v1.success({ app: info });
},
});

Expand Down
30 changes: 2 additions & 28 deletions app/lib/server/functions/sendMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { Apps } from '../../../apps/server';
import { Markdown } from '../../../markdown/server';
import { isURL, isRelativeURL } from '../../../utils/lib/isURL';
import { FileUpload } from '../../../file-upload/server';
import { Users } from '../../../models/server';

/**
* IMPORTANT
Expand Down Expand Up @@ -144,42 +143,17 @@ const validateMessage = (message) => {
}
};

const validateUserIdentity = (message, _id) => {
if (!message.alias && !message.avatar) {
return;
}
const forbiddenPropsToChangeWhenUserIsNotABot = ['avatar'];
const user = Users.findOneById(_id, { fields: { roles: 1, name: 1 } });
/**
* If the query returns no user, the message has likely
* been sent by a Livechat Visitor, so we don't need to
* validate whether the sender is a bot.
*/
if (!user) {
return;
}
const userIsNotABot = !user.roles.includes('bot');
const messageContainsAnyForbiddenProp = Object.keys(message).some((key) => forbiddenPropsToChangeWhenUserIsNotABot.includes(key));
if (userIsNotABot && (messageContainsAnyForbiddenProp || (typeof message.alias !== 'undefined' && message.alias !== user.name))) {
throw new Error('You are not authorized to change message properties');
}
};

export const sendMessage = function(user, message, room, upsert = false, trustedSender = false) {
export const sendMessage = function(user, message, room, upsert = false) {
if (!user || !message || !room._id) {
return false;
}
const { _id, username, name } = user;

if (!trustedSender) {
validateUserIdentity(message, _id);
}

validateMessage(message);

if (!message.ts) {
message.ts = new Date();
}
const { _id, username, name } = user;
message.u = {
_id,
username,
Expand Down
4 changes: 2 additions & 2 deletions app/lib/server/methods/sendMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { RateLimiter } from '../lib';
import { canSendMessage } from '../../../authorization/server';
import { SystemLogger } from '../../../logger/server';

export function executeSendMessage(uid, message, trustedSender = false) {
export function executeSendMessage(uid, message) {
if (message.tmid && !settings.get('Threads_enabled')) {
throw new Meteor.Error('error-not-allowed', 'not-allowed', {
method: 'sendMessage',
Expand Down Expand Up @@ -73,7 +73,7 @@ export function executeSendMessage(uid, message, trustedSender = false) {
}

metrics.messagesSent.inc(); // TODO This line needs to be moved to it's proper place. See the comments on: https://github.com/RocketChat/Rocket.Chat/pull/5736
return sendMessage(user, message, room, false, trustedSender);
return sendMessage(user, message, room, false);
} catch (error) {
if (error === 'error-not-allowed') {
throw new Meteor.Error('error-not-allowed');
Expand Down
8 changes: 8 additions & 0 deletions app/lib/server/startup/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { settings } from '../../../settings';

settings.addGroup('Email', function() {
this.section('Style', function() {
this.add('email_plain_text_only', false, {
type: 'boolean',
});

this.add('email_style', `html, body, .body { font-family: -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen,Ubuntu,Cantarell,'Helvetica Neue','Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol','Meiryo UI',Arial,sans-serif; }
body, .body {
Expand Down Expand Up @@ -103,6 +107,10 @@ settings.addGroup('Email', function() {
multiline: true,
i18nLabel: 'email_style_label',
i18nDescription: 'email_style_description',
enableQuery: {
_id: 'email_plain_text_only',
value: false,
},
});
});

Expand Down
1 change: 1 addition & 0 deletions app/livechat/client/views/app/tabbar/visitorInfo.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ <h3>{{_ "Conversation"}}</h3>
{{#if sms}}<li><i class="i con-mobile"></i>{{_ "SMS_Enabled"}}</li>{{/if}}
{{#if topic}}<li><strong>{{_ "Topic"}}</strong>: {{{RocketChatMarkdown topic}}}</li>{{/if}}
{{#if tags}}<li><strong>{{_ "Tags"}}</strong>: {{joinTags}}</li>{{/if}}
{{#if closedAt}}<li><strong>{{_ "Closed_At"}}</strong>: {{roomClosedDateTime}} <strong>{{_ "by"}}:</strong> {{roomClosedBy}}</li>{{/if}}
{{/with}}
{{#with department}}
{{#if name}}<li><strong>{{_ "Department"}}</strong>: {{name}}</li>{{/if}}
Expand Down
22 changes: 22 additions & 0 deletions app/livechat/client/views/app/tabbar/visitorInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { hasRole, hasPermission, hasAtLeastOnePermission } from '../../../../../
import './visitorInfo.html';
import { APIClient } from '../../../../../utils/client';
import { RoomManager } from '../../../../../ui-utils/client';
import { DateFormat } from '../../../../../lib/client';

const isSubscribedToRoom = () => {
const data = Template.currentData();
Expand Down Expand Up @@ -198,6 +199,27 @@ Template.visitorInfo.helpers({
canForwardGuest() {
return hasPermission('transfer-livechat-guest');
},

roomClosedDateTime() {
const { closedAt } = this;
return DateFormat.formatDateAndTime(closedAt);
},

roomClosedBy() {
const { closedBy = {}, servedBy = {} } = this;
let { closer } = this;

if (closer === 'user') {
if (servedBy._id !== closedBy._id) {
return closedBy.username;
}

closer = 'agent';
}

const closerLabel = closer.charAt(0).toUpperCase() + closer.slice(1);
return t(`${ closerLabel }`);
},
});

Template.visitorInfo.events({
Expand Down
4 changes: 2 additions & 2 deletions app/livechat/server/api/lib/livechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { Livechat } from '../../lib/Livechat';
import { callbacks } from '../../../../callbacks/server';
import { normalizeAgent } from '../../lib/Helper';

export function online() {
return Livechat.online();
export function online(department) {
return Livechat.online(department);
}

export function findTriggers() {
Expand Down
6 changes: 3 additions & 3 deletions app/livechat/server/api/v1/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ API.v1.addRoute('livechat/config', {
try {
check(this.queryParams, {
token: Match.Maybe(String),
department: Match.Maybe(String),
});

const config = settings();
if (!config.enabled) {
return API.v1.success({ config: { enabled: false } });
}

const status = online();

const { token } = this.queryParams;
const { token, department } = this.queryParams;
const status = online(department);
const guest = token && findGuest(token);

let room;
Expand Down
10 changes: 5 additions & 5 deletions app/livechat/server/lib/Livechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ export const Livechat = {
},
}),

online() {
online(department) {
if (settings.get('Livechat_accept_chats_with_no_agents')) {
return true;
}

if (settings.get('Livechat_assign_new_conversation_to_bot')) {
const botAgents = Livechat.getBotAgents();
const botAgents = Livechat.getBotAgents(department);
if (botAgents && botAgents.count() > 0) {
return true;
}
}

const onlineAgents = Livechat.getOnlineAgents();
const onlineAgents = Livechat.getOnlineAgents(department);
return (onlineAgents && onlineAgents.count() > 0) || settings.get('Livechat_accept_chats_with_no_agents');
},

Expand Down Expand Up @@ -355,10 +355,10 @@ export const Livechat = {
// Retreive the closed room
room = LivechatRooms.findOneByIdOrName(rid);

sendMessage(user, message, room);
sendMessage(user || visitor, message, room);

if (servedBy) {
Subscriptions.hideByRoomIdAndUserId(rid, servedBy._id);
Subscriptions.removeByRoomIdAndUserId(rid, servedBy._id);
}
Messages.createCommandWithRoomIdAndUser('promptTranscript', rid, closeData.closedBy);

Expand Down
8 changes: 4 additions & 4 deletions app/livechat/server/lib/QueueManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ import { Livechat } from './Livechat';

export const QueueManager = {
async requestRoom({ guest, message, roomInfo, agent }) {
if (!Livechat.online()) {
throw new Meteor.Error('no-agent-online', 'Sorry, no online agents');
}

check(message, Match.ObjectIncluding({
rid: String,
}));
Expand All @@ -23,6 +19,10 @@ export const QueueManager = {
department: Match.Maybe(String),
}));

if (!Livechat.online(guest.department)) {
throw new Meteor.Error('no-agent-online', 'Sorry, no online agents');
}

const { rid } = message;
const name = (roomInfo && roomInfo.fname) || guest.name || guest.username;

Expand Down
12 changes: 11 additions & 1 deletion app/mailer/server/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ export const replaceEscaped = (str, data = {}) => replace(str, {
return ret;
}, {}),
});
export const wrap = (html, data = {}) => replaceEscaped(body.replace('{{body}}', html), data);
export const wrap = (html, data = {}) => {
if (settings.get('email_plain_text_only')) {
return replace(html, data);
}

return replaceEscaped(body.replace('{{body}}', html), data);
};
export const inlinecss = (html) => juice.inlineContent(html, Settings.get('email_style'));
export const getTemplate = (template, fn, escape = true) => {
let html = '';
Expand Down Expand Up @@ -103,6 +109,10 @@ export const sendNoWrap = ({ to, from, replyTo, subject, html, text, headers })
text = stripHtml(html);
}

if (settings.get('email_plain_text_only')) {
html = undefined;
}

Meteor.defer(() => Email.send({ to, from, replyTo, subject, html, text, headers }));
};

Expand Down
4 changes: 2 additions & 2 deletions app/models/server/models/_Base.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { BaseDb } from './_BaseDb';
import { oplogEvents } from '../oplogEvents';

export class Base {
constructor(nameOrModel) {
this._db = new BaseDb(nameOrModel, this);
constructor(nameOrModel, options) {
this._db = new BaseDb(nameOrModel, this, options);
this.model = this._db.model;
this.collectionName = this._db.collectionName;
this.name = this._db.name;
Expand Down
4 changes: 2 additions & 2 deletions app/models/server/models/_BaseDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ try {
}

export class BaseDb extends EventEmitter {
constructor(model, baseModel) {
constructor(model, baseModel, options = {}) {
super();

if (Match.test(model, String)) {
Expand Down Expand Up @@ -68,7 +68,7 @@ export class BaseDb extends EventEmitter {
};
this.on('newListener', handleListener);

this.tryEnsureIndex({ _updatedAt: 1 });
this.tryEnsureIndex({ _updatedAt: 1 }, options._updatedAtIndexOptions);
}

get baseName() {
Expand Down
3 changes: 1 addition & 2 deletions app/models/server/models/apps-logs-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import { Base } from './_Base';

export class AppsLogsModel extends Base {
constructor() {
super('apps_logs');
super('apps_logs', { _updatedAtIndexOptions: { expireAfterSeconds: 60 * 60 * 24 * 30 } });

this.tryEnsureIndex({ appId: 1 });
this.tryEnsureIndex({ _updatedAt: 1 }, { expireAfterSeconds: 60 * 60 * 24 * 30 });
}

// Bypass trash collection
Expand Down
2 changes: 2 additions & 0 deletions app/theme/client/imports/general/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ button {

display: flex;

overflow: hidden;

flex: 1 1 auto;

height: 100%;
Expand Down
1 change: 1 addition & 0 deletions app/theme/client/imports/general/base_old.css
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
top: 0;

width: 100%;
margin-top: 0 !important;
padding: 2px;

border-width: 0 0 1px;
Expand Down
2 changes: 0 additions & 2 deletions app/ui-utils/client/lib/readMessages.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Meteor } from 'meteor/meteor';
import { Session } from 'meteor/session';
import _ from 'underscore';
import EventEmitter from 'wolfy87-eventemitter';

import { RoomHistoryManager } from './RoomHistoryManager';
Expand All @@ -23,7 +22,6 @@ export const readMessage = new class extends EventEmitter {
constructor() {
super();
this.debug = false;
// this.read = this.readNow;
this.enable();
}

Expand Down
Loading

0 comments on commit 6663679

Please sign in to comment.