mirror of
https://github.com/RocketChat/Rocket.Chat.git
synced 2025-12-28 06:47:25 +00:00
feat: update name references on oauth login (#37954)
Some checks failed
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
Code scanning - action / CodeQL-Build (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (${{ matrix.type }}) (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (${{ matrix.type }}) (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Some checks failed
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
Code scanning - action / CodeQL-Build (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (${{ matrix.type }}) (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (${{ matrix.type }}) (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
This commit is contained in:
parent
5fa150953b
commit
c8050708a0
5
.changeset/gold-trainers-shake.md
Normal file
5
.changeset/gold-trainers-shake.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
'@rocket.chat/meteor': minor
|
||||
---
|
||||
|
||||
Changes OAuth login process to update users' names throughout the whole workspace when an existing user logs in with a changed name
|
||||
@ -11,7 +11,9 @@ import _ from 'underscore';
|
||||
|
||||
import { normalizers, fromTemplate, renameInvalidProperties } from './transform_helpers';
|
||||
import { isURL } from '../../../lib/utils/isURL';
|
||||
import { client } from '../../../server/database/utils';
|
||||
import { callbacks } from '../../../server/lib/callbacks';
|
||||
import { saveUserIdentity } from '../../lib/server/functions/saveUserIdentity';
|
||||
import { notifyOnUserChange } from '../../lib/server/lib/notifyListener';
|
||||
import { registerAccessTokenService } from '../../lib/server/oauth/oauth';
|
||||
import { settings } from '../../settings/server';
|
||||
@ -366,17 +368,55 @@ export class CustomOAuth {
|
||||
}
|
||||
|
||||
const serviceIdKey = `services.${serviceName}.id`;
|
||||
const update = {
|
||||
$set: {
|
||||
name: serviceData.name,
|
||||
...(this.keyField === 'username' && serviceData.email && { emails: [{ address: serviceData.email, verified: true }] }),
|
||||
[serviceIdKey]: serviceData.id,
|
||||
const successCallbacks = [
|
||||
async () => {
|
||||
const updatedUser = await Users.findOneById(user._id, { projection: { name: 1, emails: 1, [serviceIdKey]: 1 } });
|
||||
if (updatedUser) {
|
||||
const { _id, ...diff } = updatedUser;
|
||||
void notifyOnUserChange({ clientAction: 'updated', id: user._id, diff });
|
||||
}
|
||||
},
|
||||
};
|
||||
];
|
||||
|
||||
await Users.update({ _id: user._id }, update);
|
||||
const session = client.startSession();
|
||||
try {
|
||||
// Extend the session to match the ExtendedSession type expected by saveUserIdentity
|
||||
Object.assign(session, {
|
||||
onceSuccesfulCommit: (cb) => {
|
||||
successCallbacks.push(cb);
|
||||
},
|
||||
});
|
||||
|
||||
void notifyOnUserChange({ clientAction: 'updated', id: user._id, diff: update });
|
||||
session.startTransaction();
|
||||
|
||||
const updater = Users.getUpdater();
|
||||
|
||||
if (this.keyField === 'username' && serviceData.email) {
|
||||
updater.set('emails', [{ address: serviceData.email, verified: true }]);
|
||||
}
|
||||
|
||||
updater.set(serviceIdKey, serviceData.id);
|
||||
|
||||
await saveUserIdentity({
|
||||
_id: user._id,
|
||||
name: serviceData.name,
|
||||
updater,
|
||||
session,
|
||||
updateUsernameInBackground: true,
|
||||
// Username needs to be included otherwise the name won't be updated in some collections
|
||||
username: user.username,
|
||||
});
|
||||
await Users.updateFromUpdater({ _id: user._id }, updater, { session });
|
||||
|
||||
await session.commitTransaction();
|
||||
} catch (e) {
|
||||
await session.abortTransaction();
|
||||
throw e;
|
||||
} finally {
|
||||
await session.endSession();
|
||||
}
|
||||
|
||||
void Promise.allSettled(successCallbacks.map((cb) => cb()));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user