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
…rewrite-announcement

* 'develop' of github.com:RocketChat/Rocket.Chat: (23 commits)
  Regression: Info Page Icon style and usage graph breaking (#20180)
  Chore: Change console.warning() to console.warn() (#20200)
  [FIX] Room's list showing all rooms with same name (#20176)
  Regression: Change sort icon (#20177)
  [FIX] Wrong userId when open own user profile (#20181)
  [FIX] Livechat.RegisterGuest method removing unset fields (#20124)
  [IMPROVE] Rewrite Prune Messages as React component (#19900)
  [FIX] Change header's favorite icon to filled star (#20174)
  [FIX] Initial values update on Account Preferences  (#19938)
  [FIX] Unable to reset password by Email if upper case character is present (#19643)
  [FIX] Video call message not translated (#18722)
  [NEW] Server Info page (#19517)
  [IMPROVE] Title for user avatar buttons (#20083)
  [FIX] Admin User Info email verified status (#20110)
  [IMPROVE] Tooltip added for Kebab menu on chat header (#20116)
  [FIX] Translate keyword for 'Showing results of' in tables (#20134)
  [FIX] Markdown added for Header Room topic (#20021)
  [FIX] Status circle in profile section (#20016)
  [FIX] Normalize messages for users in endpoint chat.getStarredMessages (#19962)
  [FIX] minWidth in FileIcon to prevent layout to broke (#19942)
  ...
  • Loading branch information
gabriellsh committed Jan 14, 2021
2 parents 7a7990a + ff5e26d commit 50d8ece
Show file tree
Hide file tree
Showing 96 changed files with 1,856 additions and 1,514 deletions.
3 changes: 3 additions & 0 deletions app/api/server/v1/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,9 @@ API.v1.addRoute('chat.getStarredMessages', { authRequired: true }, {
sort,
},
}));

messages.messages = normalizeMessagesForUser(messages.messages, this.userId);

return API.v1.success(messages);
},
});
Expand Down
6 changes: 4 additions & 2 deletions app/discussion/client/tabBar.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { useMemo, lazy, LazyExoticComponent, FC } from 'react';
import { useMemo, lazy } from 'react';

import { addAction } from '../../../client/views/room/lib/Toolbox';
import { useSetting } from '../../../client/contexts/SettingsContext';

const template = lazy(() => import('../../../client/views/room/contextualBar/Discussions'));

addAction('discussions', () => {
const discussionEnabled = useSetting('Discussion_enabled');

Expand All @@ -11,7 +13,7 @@ addAction('discussions', () => {
id: 'discussions',
title: 'Discussions',
icon: 'discussion',
template: lazy(() => import('../../../client/views/room/contextualBar/Discussions')) as LazyExoticComponent<FC>,
template,
full: true,
order: 1,
} : null), [discussionEnabled]);
Expand Down
2 changes: 1 addition & 1 deletion app/livechat/client/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Tracker.autorun((c) => {

AccountBox.addItem({
name: 'Omnichannel',
icon: 'omnichannel',
icon: 'headset',
href: '/omnichannel/current',
sideNav: 'omnichannelFlex',
condition: () => settings.get('Livechat_enabled') && hasAllPermission('view-livechat-manager'),
Expand Down
40 changes: 33 additions & 7 deletions app/livechat/server/api/v1/contact.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Match, check } from 'meteor/check';
import { Meteor } from 'meteor/meteor';

import { API } from '../../../../api/server';
import { Livechat } from '../../lib/Livechat';
import { Contacts } from '../../lib/Contacts';
import {
LivechatVisitors,
} from '../../../../models';


API.v1.addRoute('omnichannel/contact', { authRequired: true }, {
post() {
try {
Expand All @@ -15,15 +17,11 @@ API.v1.addRoute('omnichannel/contact', { authRequired: true }, {
name: String,
email: Match.Maybe(String),
phone: Match.Maybe(String),
livechatData: Match.Maybe(Object),
customFields: Match.Maybe(Object),
contactManager: Match.Maybe(Object),
});

const contactParams = this.bodyParams;
if (this.bodyParams.phone) {
contactParams.phone = { number: this.bodyParams.phone };
}
const contact = Livechat.registerGuest(contactParams);
const contact = Contacts.registerContact(this.bodyParams);

return API.v1.success({ contact });
} catch (e) {
Expand All @@ -40,3 +38,31 @@ API.v1.addRoute('omnichannel/contact', { authRequired: true }, {
return API.v1.success({ contact });
},
});


API.v1.addRoute('omnichannel/contact.search', { authRequired: true }, {
get() {
try {
check(this.queryParams, {
email: Match.Maybe(String),
phone: Match.Maybe(String),
});

const { email, phone } = this.queryParams;

if (!email && !phone) {
throw new Meteor.Error('error-invalid-params');
}

const query = Object.assign({}, {
...email && { visitorEmails: { address: email } },
...phone && { phone: { phoneNumber: phone } },
});

const contact = Promise.await(LivechatVisitors.findOne(query));
return API.v1.success({ contact });
} catch (e) {
return API.v1.failure(e);
}
},
});
65 changes: 65 additions & 0 deletions app/livechat/server/lib/Contacts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { check } from 'meteor/check';
import s from 'underscore.string';

import {
LivechatVisitors,
LivechatCustomField,
} from '../../../models';


export const Contacts = {

registerContact({ token, name, email, phone, username, customFields = {}, contactManager = {} } = {}) {
check(token, String);

let contactId;
const updateUser = {
$set: {
token,
},
};

const user = LivechatVisitors.getVisitorByToken(token, { fields: { _id: 1 } });

if (user) {
contactId = user._id;
} else {
if (!username) {
username = LivechatVisitors.getNextVisitorUsername();
}

let existingUser = null;

if (s.trim(email) !== '' && (existingUser = LivechatVisitors.findOneGuestByEmailAddress(email))) {
contactId = existingUser._id;
} else {
const userData = {
username,
ts: new Date(),
};

contactId = LivechatVisitors.insert(userData);
}
}

updateUser.$set.name = name;
updateUser.$set.phone = (phone && [{ phoneNumber: phone }]) || null;
updateUser.$set.visitorEmails = (email && [{ address: email }]) || null;

const allowedCF = LivechatCustomField.find({ scope: 'visitor' }).map(({ _id }) => _id);

const livechatData = Object.keys(customFields)
.filter((key) => allowedCF.includes(key) && customFields[key] !== '' && customFields[key] !== undefined)
.reduce((obj, key) => {
obj[key] = customFields[key];
return obj;
}, {});

updateUser.$set.livechatData = livechatData;
updateUser.$set.contactManager = (contactManager?.username && { username: contactManager.username }) || null;

LivechatVisitors.updateById(contactId, updateUser);

return contactId;
},
};
27 changes: 5 additions & 22 deletions app/livechat/server/lib/Livechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,14 @@ export const Livechat = {
return true;
},

registerGuest({ token, name, email, department, phone, username, livechatData, contactManager, connectionData } = {}) {
registerGuest({ token, name, email, department, phone, username, connectionData } = {}) {
check(token, String);

let userId;
const updateUser = {
$set: {
token,
},
$unset: { },
};

const user = LivechatVisitors.getVisitorByToken(token, { fields: { _id: 1 } });
Expand Down Expand Up @@ -235,45 +234,29 @@ export const Livechat = {
}
}

if (name) {
updateUser.$set.name = name;
}

if (phone) {
updateUser.$set.phone = [
{ phoneNumber: phone.number },
];
} else {
updateUser.$unset.phone = 1;
}

if (email && email.trim() !== '') {
updateUser.$set.visitorEmails = [
{ address: email },
];
} else {
updateUser.$unset.visitorEmails = 1;
}

if (livechatData) {
updateUser.$set.livechatData = livechatData;
} else {
updateUser.$unset.livechatData = 1;
}

if (contactManager) {
updateUser.$set.contactManager = contactManager;
} else {
updateUser.$unset.contactManager = 1;
if (name) {
updateUser.$set.name = name;
}

if (!department) {
updateUser.$unset.department = 1;
Object.assign(updateUser, { $unset: { department: 1 } });
} else {
const dep = LivechatDepartment.findOneByIdOrName(department);
updateUser.$set.department = dep && dep._id;
}
if (_.isEmpty(updateUser.$unset)) { delete updateUser.$unset; }

LivechatVisitors.updateById(userId, updateUser);

return userId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ export interface ISAMLGlobalSettings {
roleAttributeSync: boolean;
userDataFieldMap: string;
usernameNormalize: string;
channelsAttributeUpdate: boolean;
includePrivateChannelsInUpdate: boolean;
}
26 changes: 20 additions & 6 deletions app/meteor-accounts-saml/server/lib/SAML.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class SAML {
}

public static insertOrUpdateSAMLUser(userObject: ISAMLUser): {userId: string; token: string} {
const { roleAttributeSync, generateUsername, immutableProperty, nameOverwrite, mailOverwrite } = SAMLUtils.globalSettings;
const { roleAttributeSync, generateUsername, immutableProperty, nameOverwrite, mailOverwrite, channelsAttributeUpdate } = SAMLUtils.globalSettings;

let customIdentifierMatch = false;
let customIdentifierAttributeName: string | null = null;
Expand Down Expand Up @@ -144,7 +144,7 @@ export class SAML {
const userId = Accounts.insertUserDoc({}, newUser);
user = Users.findOne(userId);

if (userObject.channels) {
if (userObject.channels && channelsAttributeUpdate !== true) {
SAML.subscribeToSAMLChannels(userObject.channels, user);
}
}
Expand Down Expand Up @@ -186,6 +186,10 @@ export class SAML {
updateData.roles = globalRoles;
}

if (userObject.channels && channelsAttributeUpdate === true) {
SAML.subscribeToSAMLChannels(userObject.channels, user);
}

Users.update({
_id: user._id,
}, {
Expand Down Expand Up @@ -444,6 +448,7 @@ export class SAML {
}

private static subscribeToSAMLChannels(channels: Array<string>, user: IUser): void {
const { includePrivateChannelsInUpdate } = SAMLUtils.globalSettings;
try {
for (let roomName of channels) {
roomName = roomName.trim();
Expand All @@ -452,15 +457,24 @@ export class SAML {
}

const room = Rooms.findOneByNameAndType(roomName, 'c', {});
if (!room) {
const privRoom = Rooms.findOneByNameAndType(roomName, 'p', {});

if (privRoom && includePrivateChannelsInUpdate === true) {
addUserToRoom(privRoom._id, user);
continue;
}

if (room) {
addUserToRoom(room._id, user);
continue;
}

if (!room && !privRoom) {
// If the user doesn't have an username yet, we can't create new rooms for them
if (user.username) {
createRoom('c', roomName, user.username);
}
continue;
}

addUserToRoom(room._id, user);
}
} catch (err) {
console.error(err);
Expand Down
4 changes: 4 additions & 0 deletions app/meteor-accounts-saml/server/lib/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const globalSettings: ISAMLGlobalSettings = {
roleAttributeSync: false,
userDataFieldMap: '{"username":"username", "email":"email", "cn": "name"}',
usernameNormalize: 'None',
channelsAttributeUpdate: false,
includePrivateChannelsInUpdate: false,
};

export class SAMLUtils {
Expand Down Expand Up @@ -73,6 +75,8 @@ export class SAMLUtils {
globalSettings.nameOverwrite = Boolean(samlConfigs.nameOverwrite);
globalSettings.mailOverwrite = Boolean(samlConfigs.mailOverwrite);
globalSettings.roleAttributeSync = Boolean(samlConfigs.roleAttributeSync);
globalSettings.channelsAttributeUpdate = Boolean(samlConfigs.channelsAttributeUpdate);
globalSettings.includePrivateChannelsInUpdate = Boolean(samlConfigs.includePrivateChannelsInUpdate);

if (samlConfigs.immutableProperty && typeof samlConfigs.immutableProperty === 'string') {
globalSettings.immutableProperty = samlConfigs.immutableProperty;
Expand Down
16 changes: 16 additions & 0 deletions app/meteor-accounts-saml/server/lib/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export const getSamlConfigs = function(service: string): Record<string, any> {
logoutRequestTemplate: settings.get(`${ service }_LogoutRequest_template`),
metadataCertificateTemplate: settings.get(`${ service }_MetadataCertificate_template`),
metadataTemplate: settings.get(`${ service }_Metadata_template`),
channelsAttributeUpdate: settings.get(`${ service }_channels_update`),
includePrivateChannelsInUpdate: settings.get(`${ service }_include_private_channels_update`),
};
};

Expand Down Expand Up @@ -271,6 +273,20 @@ export const addSettings = function(name: string): void {
section: 'SAML_Section_3_Behavior',
i18nLabel: 'SAML_Custom_Logout_Behaviour',
});
settings.add(`SAML_Custom_${ name }_channels_update`, false, {
type: 'boolean',
group: 'SAML',
section: 'SAML_Section_3_Behavior',
i18nLabel: 'SAML_Custom_channels_update',
i18nDescription: 'SAML_Custom_channels_update_description',
});
settings.add(`SAML_Custom_${ name }_include_private_channels_update`, false, {
type: 'boolean',
group: 'SAML',
section: 'SAML_Section_3_Behavior',
i18nLabel: 'SAML_Custom_include_private_channels_update',
i18nDescription: 'SAML_Custom_include_private_channels_update_description',
});

// Roles Settings
settings.add(`SAML_Custom_${ name }_default_user_role`, 'user', {
Expand Down
6 changes: 4 additions & 2 deletions app/otr/client/tabBar.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { useMemo, lazy, LazyExoticComponent, FC, useEffect } from 'react';
import { useMemo, lazy, useEffect } from 'react';

import { OTR } from './rocketchat.otr';
import { useSetting } from '../../../client/contexts/SettingsContext';
import { addAction } from '../../../client/views/room/lib/Toolbox';

const template = lazy(() => import('../../../client/views/room/contextualBar/OTR'));

addAction('otr', () => {
const enabled = useSetting('OTR_Enable');

Expand All @@ -24,7 +26,7 @@ addAction('otr', () => {
id: 'otr',
title: 'OTR',
icon: 'key',
template: lazy(() => import('../../../client/views/room/contextualBar/OTR')) as LazyExoticComponent<FC>,
template,
order: 13,
full: true,
} : null), [shouldAddAction]);
Expand Down
4 changes: 3 additions & 1 deletion app/statistics/server/lib/statistics.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ export const statistics = {
statistics.appUsers = Users.find({ type: 'app' }).count();
statistics.onlineUsers = Meteor.users.find({ statusConnection: 'online' }).count();
statistics.awayUsers = Meteor.users.find({ statusConnection: 'away' }).count();
// TODO: Get statuses from the `status` property.
statistics.busyUsers = Meteor.users.find({ statusConnection: 'busy' }).count();
statistics.totalConnectedUsers = statistics.onlineUsers + statistics.awayUsers;
statistics.offlineUsers = statistics.totalUsers - statistics.onlineUsers - statistics.awayUsers;
statistics.offlineUsers = statistics.totalUsers - statistics.onlineUsers - statistics.awayUsers - statistics.busyUsers;

// Room statistics
statistics.totalRooms = Rooms.find().count();
Expand Down
3 changes: 0 additions & 3 deletions app/ui-clean-history/client/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
import './lib/startup';
import './views/cleanHistory.html';
import './views/cleanHistory';
import './views/stylesheets/cleanHistory.css';
Loading

0 comments on commit 50d8ece

Please sign in to comment.