Skip to content
Snippets Groups Projects
Unverified Commit 717dc663 authored by Kevin Aleman's avatar Kevin Aleman Committed by GitHub
Browse files

Regression: Custom fields not being saved for room (#26747)

parent 875aef86
No related branches found
No related tags found
No related merge requests found
......@@ -392,11 +392,12 @@ export const Livechat = {
const customFields = {};
if (!userId || hasPermission(userId, 'edit-livechat-room-customfields')) {
if ((!userId || hasPermission(userId, 'edit-livechat-room-customfields')) && Object.keys(livechatData).length) {
Livechat.logger.debug(`Saving custom fields for visitor ${_id}`);
const fields = LivechatCustomField.findByScope('visitor');
for await (const field of fields) {
if (!livechatData.hasOwnProperty(field._id)) {
return;
continue;
}
const value = s.trim(livechatData[field._id]);
if (value !== '' && field.regexp !== undefined && field.regexp !== '') {
......@@ -408,6 +409,7 @@ export const Livechat = {
customFields[field._id] = value;
}
updateData.livechatData = customFields;
Livechat.logger.debug(`About to update ${Object.keys(customFields).length} custom fields for visitor ${_id}`);
}
const ret = await LivechatVisitors.saveGuestById(_id, updateData);
......@@ -584,7 +586,8 @@ export const Livechat = {
const { livechatData = {} } = roomData;
const customFields = {};
if (!userId || hasPermission(userId, 'edit-livechat-room-customfields')) {
if ((!userId || hasPermission(userId, 'edit-livechat-room-customfields')) && Object.keys(livechatData).length) {
Livechat.logger.debug(`Updating custom fields on room ${roomData._id}`);
const fields = LivechatCustomField.findByScope('room');
for await (const field of fields) {
if (!livechatData.hasOwnProperty(field._id)) {
......@@ -600,9 +603,11 @@ export const Livechat = {
customFields[field._id] = value;
}
roomData.livechatData = customFields;
Livechat.logger.debug(`About to update ${Object.keys(customFields).length} custom fields on room ${roomData._id}`);
}
if (!LivechatRooms.saveRoomById(roomData)) {
Livechat.logger.debug(`Failed to save room information on room ${roomData._id}`);
return false;
}
......@@ -611,7 +616,7 @@ export const Livechat = {
});
callbacks.runAsync('livechat.saveRoom', roomData);
if (!_.isEmpty(guestData.name)) {
if (guestData?.name?.trim().length) {
const { _id: rid } = roomData;
const { name } = guestData;
return (
......
import { Meteor } from 'meteor/meteor';
import { Match, check } from 'meteor/check';
import { isOmnichannelRoom } from '@rocket.chat/core-typings';
import { hasPermission } from '../../../authorization';
import { LivechatRooms } from '../../../models/server';
......@@ -37,7 +38,7 @@ Meteor.methods({
);
const room = LivechatRooms.findOneById(roomData._id);
if (room == null || room.t !== 'l') {
if (!room || !isOmnichannelRoom(room)) {
throw new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'livechat:saveInfo' });
}
......@@ -49,7 +50,7 @@ Meteor.methods({
delete guestData.phone;
}
const ret = (await Livechat.saveGuest(guestData, userId)) && (await Livechat.saveRoomInfo(roomData, guestData, userId));
await Promise.allSettled([Livechat.saveGuest(guestData), Livechat.saveRoomInfo(roomData)]);
const user = Meteor.users.findOne({ _id: userId }, { fields: { _id: 1, username: 1 } });
......@@ -60,6 +61,6 @@ Meteor.methods({
});
});
return ret;
return true;
},
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment