Skip to content

Commit

Permalink
Merge branch 'develop' into fix/thread429
Browse files Browse the repository at this point in the history
  • Loading branch information
scuciatto authored Oct 12, 2023
2 parents 2f00cda + 82839a4 commit bf646a2
Show file tree
Hide file tree
Showing 32 changed files with 287 additions and 204 deletions.
5 changes: 5 additions & 0 deletions .changeset/lucky-vans-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fixed issue with file attachments in rooms' messages export having no content
5 changes: 5 additions & 0 deletions .changeset/wicked-jars-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Handle the username update in the background
11 changes: 7 additions & 4 deletions apps/meteor/app/file-upload/server/config/AmazonS3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ const get: FileUploadClass['get'] = async function (this: FileUploadClass, file,

const copy: FileUploadClass['copy'] = async function (this: FileUploadClass, file, out) {
const fileUrl = await this.store.getRedirectURL(file);
if (fileUrl) {
const request = /^https:/.test(fileUrl) ? https : http;
request.get(fileUrl, (fileRes) => fileRes.pipe(out));
} else {
if (!fileUrl) {
out.end();
return;
}

const request = /^https:/.test(fileUrl) ? https : http;
return new Promise((resolve) => {
request.get(fileUrl, (fileRes) => fileRes.pipe(out).on('finish', () => resolve()));
});
};

const AmazonS3Uploads = new FileUploadClass({
Expand Down
11 changes: 7 additions & 4 deletions apps/meteor/app/file-upload/server/config/GoogleStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ const get: FileUploadClass['get'] = async function (this: FileUploadClass, file,
const copy: FileUploadClass['copy'] = async function (this: FileUploadClass, file, out) {
const fileUrl = await this.store.getRedirectURL(file, false);

if (fileUrl) {
const request = /^https:/.test(fileUrl) ? https : http;
request.get(fileUrl, (fileRes) => fileRes.pipe(out));
} else {
if (!fileUrl) {
out.end();
return;
}

const request = /^https:/.test(fileUrl) ? https : http;
return new Promise((resolve) => {
request.get(fileUrl, (fileRes) => fileRes.pipe(out).on('finish', () => resolve()));
});
};

const GoogleCloudStorageUploads = new FileUploadClass({
Expand Down
4 changes: 3 additions & 1 deletion apps/meteor/app/file-upload/server/config/Webdav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ const get: FileUploadClass['get'] = async function (this: FileUploadClass, file,
};

const copy: FileUploadClass['copy'] = async function (this: FileUploadClass, file, out) {
(await this.store.getReadStream(file._id, file)).pipe(out);
return new Promise(async (resolve) => {
(await this.store.getReadStream(file._id, file)).pipe(out).on('finish', () => resolve());
});
};

const WebdavUploads = new FileUploadClass({
Expand Down
1 change: 1 addition & 0 deletions apps/meteor/app/lib/server/functions/saveUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ export const saveUser = async function (userId, userData) {
_id: userData._id,
username: userData.username,
name: userData.name,
updateUsernameInBackground: true,
}))
) {
throw new Meteor.Error('error-could-not-save-identity', 'Could not save user identity', {
Expand Down
129 changes: 93 additions & 36 deletions apps/meteor/app/lib/server/functions/saveUserIdentity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { IUser } from '@rocket.chat/core-typings';
import { Messages, VideoConference, LivechatDepartmentAgents, Rooms, Subscriptions, Users } from '@rocket.chat/models';

import { SystemLogger } from '../../../../server/lib/logger/system';
import { FileUpload } from '../../../file-upload/server';
import { _setRealName } from './setRealName';
import { _setUsername } from './setUsername';
Expand All @@ -11,7 +13,17 @@ import { validateName } from './validateName';
* @param {object} changes changes to the user
*/

export async function saveUserIdentity({ _id, name: rawName, username: rawUsername }: { _id: string; name?: string; username?: string }) {
export async function saveUserIdentity({
_id,
name: rawName,
username: rawUsername,
updateUsernameInBackground = false,
}: {
_id: string;
name?: string;
username?: string;
updateUsernameInBackground?: boolean; // TODO: remove this
}) {
if (!_id) {
return false;
}
Expand Down Expand Up @@ -48,46 +60,91 @@ export async function saveUserIdentity({ _id, name: rawName, username: rawUserna

// if coming from old username, update all references
if (previousUsername) {
if (usernameChanged && typeof rawUsername !== 'undefined') {
const fileStore = FileUpload.getStore('Avatars');
const previousFile = await fileStore.model.findOneByName(previousUsername);
const file = await fileStore.model.findOneByName(username);
if (file) {
await fileStore.model.deleteFile(file._id);
}
if (previousFile) {
await fileStore.model.updateFileNameById(previousFile._id, username);
}

await Messages.updateAllUsernamesByUserId(user._id, username);
await Messages.updateUsernameOfEditByUserId(user._id, username);

const cursor = Messages.findByMention(previousUsername);
for await (const msg of cursor) {
const updatedMsg = msg.msg.replace(new RegExp(`@${previousUsername}`, 'ig'), `@${username}`);
await Messages.updateUsernameAndMessageOfMentionByIdAndOldUsername(msg._id, previousUsername, username, updatedMsg);
}

await Rooms.replaceUsername(previousUsername, username);
await Rooms.replaceMutedUsername(previousUsername, username);
await Rooms.replaceUsernameOfUserByUserId(user._id, username);
await Subscriptions.setUserUsernameByUserId(user._id, username);

await LivechatDepartmentAgents.replaceUsernameOfAgentByUserId(user._id, username);
const handleUpdateParams = {
username,
previousUsername,
rawUsername,
usernameChanged,
user,
name,
previousName,
rawName,
nameChanged,
};
if (updateUsernameInBackground) {
setImmediate(async () => {
try {
await updateUsernameReferences(handleUpdateParams);
} catch (err) {
SystemLogger.error(err);
}
});
} else {
await updateUsernameReferences(handleUpdateParams);
}
}

return true;
}

// update other references if either the name or username has changed
if (usernameChanged || nameChanged) {
// update name and fname of 1-on-1 direct messages
await Subscriptions.updateDirectNameAndFnameByName(previousUsername, rawUsername && username, rawName && name);
async function updateUsernameReferences({
username,
previousUsername,
rawUsername,
usernameChanged,
user,
name,
previousName,
rawName,
nameChanged,
}: {
username: string;
previousUsername: string;
rawUsername?: string;
usernameChanged: boolean;
user: IUser;
name: string;
previousName: string | undefined;
rawName?: string;
nameChanged: boolean;
}): Promise<void> {
if (usernameChanged && typeof rawUsername !== 'undefined') {
const fileStore = FileUpload.getStore('Avatars');
const previousFile = await fileStore.model.findOneByName(previousUsername);
const file = await fileStore.model.findOneByName(username);
if (file) {
await fileStore.model.deleteFile(file._id);
}
if (previousFile) {
await fileStore.model.updateFileNameById(previousFile._id, username);
}

// update name and fname of group direct messages
await updateGroupDMsName(user);
await Messages.updateAllUsernamesByUserId(user._id, username);
await Messages.updateUsernameOfEditByUserId(user._id, username);

// update name and username of users on video conferences
await VideoConference.updateUserReferences(user._id, username || previousUsername, name || previousName);
const cursor = Messages.findByMention(previousUsername);
for await (const msg of cursor) {
const updatedMsg = msg.msg.replace(new RegExp(`@${previousUsername}`, 'ig'), `@${username}`);
await Messages.updateUsernameAndMessageOfMentionByIdAndOldUsername(msg._id, previousUsername, username, updatedMsg);
}

await Rooms.replaceUsername(previousUsername, username);
await Rooms.replaceMutedUsername(previousUsername, username);
await Rooms.replaceUsernameOfUserByUserId(user._id, username);
await Subscriptions.setUserUsernameByUserId(user._id, username);

await LivechatDepartmentAgents.replaceUsernameOfAgentByUserId(user._id, username);
}

return true;
// update other references if either the name or username has changed
if (usernameChanged || nameChanged) {
// update name and fname of 1-on-1 direct messages
await Subscriptions.updateDirectNameAndFnameByName(previousUsername, rawUsername && username, rawName && name);

// update name and fname of group direct messages
await updateGroupDMsName(user);

// update name and username of users on video conferences
await VideoConference.updateUserReferences(user._id, username || previousUsername, name || previousName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ type RoomForewordUsernameListItemProps = {
useRealName: boolean;
};

// TODO: Improve `Tag` a11y to be used as a link
const RoomForewordUsernameListItem: VFC<RoomForewordUsernameListItemProps> = ({ username, href, useRealName }) => {
const { data, isLoading, isError } = useUserInfoQuery({ username });

return (
<Box mi={4} is='a' href={href}>
<Box mi={4} is='a' href={href} style={{ textDecoration: 'none' }}>
<Tag icon={<Icon name='user' size='x20' />} className='mention-link' data-username={username} large>
{isLoading && <Skeleton variant='rect' />}
{!isLoading && isError && username}
Expand Down
8 changes: 0 additions & 8 deletions apps/meteor/packages/rocketchat-i18n/i18n/ar.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -4299,10 +4299,6 @@
"Troubleshoot_Disable_Presence_Broadcast_Alert": "يمنع هذا الإعداد كل المثيلات من إرسال تغييرات الحالة للمستخدمين إلى عملائهم مع الاحتفاظ بحالة تواجد كل المستخدمين من التحميل الأول!",
"Troubleshoot_Disable_Sessions_Monitor": "تعطيل شاشة مراقبة الجلسات",
"Troubleshoot_Disable_Sessions_Monitor_Alert": "يوقف هذا الإعداد معالجة جلسات المستخدم، ما يتسبب في توقف الإحصاءات عن العمل بشكل صحيح!",
"Troubleshoot_Disable_Statistics_Generator": "تعطيل منشئ الإحصاءات",
"Troubleshoot_Disable_Statistics_Generator_Alert": "يوقف هذا الإعداد معالجة كل الإحصاءات، ما يجعل صفحة المعلومات قديمة حتى ينقر شخص ما على زر التحديث وقد يتسبب في فقد معلومات أخرى حول النظام!",
"Troubleshoot_Disable_Workspace_Sync": "تعطيل مزامنة مساحة العمل",
"Troubleshoot_Disable_Workspace_Sync_Alert": "يوقف هذا الإعداد مزامنة هذا الخادم مع سحابة Rocket.Chat وقد يتسبب في حدوث مشاكل مع تراخيص السوق والمؤسسة!",
"True": "صحيح",
"Try_now": "المحاولة الآن",
"Try_searching_in_the_marketplace_instead": "محاولة البحث في السوق بدلاً من ذلك",
Expand Down Expand Up @@ -4855,8 +4851,6 @@
"onboarding.page.requestTrial.subtitle": "جرب أفضل خطة إصدار Enterprise لمدة 30 يومًا مجانًا",
"onboarding.page.magicLinkEmail.title": "أرسلنا لك رابط تسجيل الدخول عبر البريد الإلكتروني",
"onboarding.page.magicLinkEmail.subtitle": "انقر فوق الرابط الموجود في البريد الإلكتروني الذي أرسلناه لك للتو لتسجيل الدخول إلى مساحة العمل الخاصة بك. <1>ستنتهي صلاحية الرابط خلال 30 دقيقة.</1>",
"onboarding.page.organizationInfoPage.title": "بعض التفاصيل الإضافية...",
"onboarding.page.organizationInfoPage.subtitle": "ستساعدنا هذه على تخصيص مساحة العمل الخاصة بك.",
"onboarding.form.adminInfoForm.title": "معلومات المسؤول",
"onboarding.form.adminInfoForm.subtitle": "نحتاج إلى هذا لإنشاء ملف شخصي مسؤول داخل مساحة العمل الخاصة بك",
"onboarding.form.adminInfoForm.fields.fullName.label": "الاسم الكامل",
Expand Down Expand Up @@ -4885,10 +4879,8 @@
"onboarding.form.registeredServerForm.included.externalProviders": "التكامل مع مقدمي الخدمات الخارجيين (WhatsApp وFacebook وTelegram وTwitter)",
"onboarding.form.registeredServerForm.included.apps": "الوصول إلى تطبيقات السوق",
"onboarding.form.registeredServerForm.fields.accountEmail.inputLabel": "البريد الإلكتروني لحساب السحابة",
"onboarding.form.registeredServerForm.fields.accountEmail.tooltipLabel": "لتسجيل الخادم الخاص بك، نحتاج إلى توصيله بحسابك السحابي. إذا كان لديك حساب سابقًا، فسنقوم بربطه تلقائيًا. وإن لم يكن لديك، فسيتم إنشاء حساب جديد",
"onboarding.form.registeredServerForm.fields.accountEmail.inputPlaceholder": "يرجى إدخال بريدك الإلكتروني",
"onboarding.form.registeredServerForm.keepInformed": "أبقني على اطلاع بالأخبار والأحداث",
"onboarding.form.registeredServerForm.agreeToReceiveUpdates": "يعني التسجيل موافقتي على تلقي تحديثات المنتج والأمان ذات الصلة",
"onboarding.form.standaloneServerForm.title": "تأكيد الخادم المستقل",
"onboarding.form.standaloneServerForm.servicesUnavailable": "لن تكون بعض الخدمات متاحة أو ستتطلب إعدادًا يدويًا",
"onboarding.form.standaloneServerForm.publishOwnApp": "لإرسال الإشعارات، تحتاج إلى تجميع تطبيقك الخاص ونشره على Google Play وApp Store",
Expand Down
4 changes: 0 additions & 4 deletions apps/meteor/packages/rocketchat-i18n/i18n/ca.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -4227,10 +4227,6 @@
"Troubleshoot_Disable_Presence_Broadcast_Alert": "Aquesta configuració evita que totes les instàncies enviïn els canvis d'estat dels usuaris als clients, mantenint tots els usuaris amb el seu estat de presència des de la primera càrrega!",
"Troubleshoot_Disable_Sessions_Monitor": "Desactiva el monitor de sessions",
"Troubleshoot_Disable_Sessions_Monitor_Alert": "Aquesta configuració deté el processament de les sessions de visita de l'LiveChat causant que les estadístiques deixin de funcionar!",
"Troubleshoot_Disable_Statistics_Generator": "Desactivar el generador d'estadístiques",
"Troubleshoot_Disable_Statistics_Generator_Alert": "Aquest ajust deté el processament de totes les estadístiques fent que la pàgina d'informació quedi desactualitzada fins que algú faci clic al botó d'actualització i pot causar que falti altra informació en el sistema!",
"Troubleshoot_Disable_Workspace_Sync": "Desactiva la sincronització de l'espai de treball",
"Troubleshoot_Disable_Workspace_Sync_Alert": "¡Este ajuste detiene la sincronización de este servidor con la nube de Rocket.Chat y puede causar problemas con el mercado y las licencias de las empresas!",
"True": "",
"Try_now": "Prova-ho ara",
"Tuesday": "dimarts",
Expand Down
4 changes: 0 additions & 4 deletions apps/meteor/packages/rocketchat-i18n/i18n/cs.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -3561,10 +3561,6 @@
"Troubleshoot_Disable_Presence_Broadcast_Alert": "Toto nastavení zakáže všem instancím odesílat změny stavu uživatelů a ponechat si nastavení při prvním načtení",
"Troubleshoot_Disable_Sessions_Monitor": "Zakázat monitor sessions",
"Troubleshoot_Disable_Sessions_Monitor_Alert": "Toto nastavení přestane zpracovávat uživatelské sessions a statistiky tak přestanou správně fungovat!",
"Troubleshoot_Disable_Statistics_Generator": "Zakázat generování statistik",
"Troubleshoot_Disable_Statistics_Generator_Alert": "Toto nastavení přestane zpracovávat statistiky, takže stránka s informacemi zůstane neaktuální dokud někdo nevynutí aktualizaci. Způsobuje neaktuálnost dat napříč systémem!",
"Troubleshoot_Disable_Workspace_Sync": "Zakázat synchronizaci pracovního prostoru",
"Troubleshoot_Disable_Workspace_Sync_Alert": "Toto nastavení zakáže synchronizaci s Rocket.chat cloud a může způsobit problémy s marketplace a enterprise licencemi!",
"True": "Ano",
"Try_now": "Zkusit nyní",
"Tuesday": "Úterý",
Expand Down
4 changes: 0 additions & 4 deletions apps/meteor/packages/rocketchat-i18n/i18n/da.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -3582,10 +3582,6 @@
"Troubleshoot_Disable_Presence_Broadcast_Alert": "Denne indstilling forhindrer alle instancer fra at sende statusændringerne for brugerne til deres klienter, hvilket gør, at alle brugere vil have deres status vedr. tilstedeværelse fra de blev loadet i starten!",
"Troubleshoot_Disable_Sessions_Monitor": "Deaktivér sessions-monitor",
"Troubleshoot_Disable_Sessions_Monitor_Alert": "Denne indstilling stopper behandlingen af brugersessioner og får statistikkerne til at stoppe med at virke korrekt!",
"Troubleshoot_Disable_Statistics_Generator": "Deaktivér statistik-generator",
"Troubleshoot_Disable_Statistics_Generator_Alert": "Denne indstilling stopper behandlingen af alle statistikker, hvilket gør at informationssiden forældes, indtil nogen klikker på opdateringsknappen og kan også forårsage andre manglende oplysninger rundt omkring i systemet!",
"Troubleshoot_Disable_Workspace_Sync": "Deaktivér synkronisering af Workspace",
"Troubleshoot_Disable_Workspace_Sync_Alert": "Denne indstilling stopper synkroniseringen af denne server med Rocket.Chat's cloud og kan forårsage problemer med marketplace og enteprise-licenser!",
"True": "Sandt",
"Try_now": "Forsøg nu",
"Tuesday": "tirsdag",
Expand Down
Loading

0 comments on commit bf646a2

Please sign in to comment.