Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(federation-v2): can not assign to readonly property #name #35397

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-code-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ env:

jobs:
code-check:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

name: ${{ matrix.check == 'ts' && 'TypeScript' || 'Code Lint' }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-test-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ env:

jobs:
test:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
env:
RC_DOCKERFILE: ${{ inputs.rc-dockerfile }}.${{ (matrix.mongodb-version == '7.0' && 'debian' && false) || 'alpine' }}
RC_DOCKER_TAG: ${{ inputs.rc-docker-tag }}.${{ (matrix.mongodb-version == '7.0' && 'debian' && false) || 'alpine' }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ env:

jobs:
test:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

name: Unit Tests

Expand Down
22 changes: 11 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jobs:

notify-draft-services:
name: 🚀 Notify external services - draft
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
needs: [release-versions]
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -136,7 +136,7 @@ jobs:
packages-build:
name: 📦 Build Packages
needs: [release-versions, notify-draft-services]
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Github Info
run: |
Expand Down Expand Up @@ -225,7 +225,7 @@ jobs:
build:
name: 📦 Meteor Build - coverage
needs: [release-versions, packages-build]
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

steps:
- name: Collect Workflow Telemetry
Expand Down Expand Up @@ -256,7 +256,7 @@ jobs:
name: 📦 Meteor Build - official
needs: [tests-done, release-versions, packages-build]
if: (github.event_name == 'release' || github.ref == 'refs/heads/develop')
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

steps:
- name: Collect Workflow Telemetry
Expand Down Expand Up @@ -331,7 +331,7 @@ jobs:
build-gh-docker-coverage:
name: 🚢 Build Docker Images for Testing
needs: [build, release-versions, build-matrix-rust-bindings-for-alpine]
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

env:
RC_DOCKERFILE: ${{ needs.release-versions.outputs.rc-dockerfile }}.${{ matrix.platform }}
Expand Down Expand Up @@ -376,7 +376,7 @@ jobs:
build-gh-docker:
name: 🚢 Build Docker Images for Production
needs: [build-prod, release-versions]
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

env:
RC_DOCKERFILE: ${{ needs.release-versions.outputs.rc-dockerfile }}.${{ matrix.platform }}
Expand Down Expand Up @@ -563,7 +563,7 @@ jobs:

tests-done:
name: ✅ Tests Done
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
needs: [checks, test-unit, test-api, test-ui, test-api-ee, test-ui-ee, test-ui-ee-no-watcher]
if: always()
steps:
Expand Down Expand Up @@ -601,7 +601,7 @@ jobs:

deploy:
name: 🚀 Publish build assets
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
if: github.event_name == 'release' || github.ref == 'refs/heads/develop'
needs: [build-gh-docker, release-versions]

Expand Down Expand Up @@ -655,7 +655,7 @@ jobs:

docker-image-publish:
name: 🚀 Publish Docker Image (main)
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
needs: [deploy, release-versions]

strategy:
Expand Down Expand Up @@ -765,7 +765,7 @@ jobs:

services-docker-image-publish:
name: 🚀 Publish Docker Image (services)
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
needs: [deploy, release-versions]

strategy:
Expand Down Expand Up @@ -854,7 +854,7 @@ jobs:

notify-services:
name: 🚀 Notify external services
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
needs:
- services-docker-image-publish
- docker-image-publish
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export abstract class AbstractFederationApplicationService {
return;
}
if (federatedUser.shouldUpdateDisplayName(displayName)) {
await this.internalUserAdapter.updateRealName(federatedUser.getInternalReference(), displayName);
await this.internalUserAdapter.updateRealName(federatedUser.getInternalReferenceCopy(), displayName);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IUser } from '@rocket.chat/core-typings';
import { UserStatus } from '@rocket.chat/core-typings';
import { UserStatus, copyUserObject } from '@rocket.chat/core-typings';
import { ObjectId } from 'mongodb'; // This should not be in the domain layer, but its a known "problem"

import { isAnInternalIdentifier } from './FederatedRoom';
Expand Down Expand Up @@ -70,6 +70,10 @@ export class FederatedUser {
});
}

public getInternalReferenceCopy(): IUser {
return copyUserObject(this.internalReference);
}

public getStorageRepresentation(): Readonly<IUser> {
return {
_id: this.internalId,
Expand Down
38 changes: 38 additions & 0 deletions packages/core-typings/src/IUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ export interface IUser extends IRocketChatRecord {
reason?: string;
// TODO: move this to a specific federation user type
federated?: boolean;
// @deprecated
federation?: {
avatarUrl?: string;
searchedServerNames?: string[];
Expand All @@ -220,6 +221,43 @@ export interface IUser extends IRocketChatRecord {
isOAuthUser?: boolean; // client only field
}

export const copyUserEmail = (email: IUserEmail) => ({
...email,
});

export const copyUserSettings = (setting: IUserSettings) => ({
...setting,
...(setting.preferences && { preferences: { ...setting.preferences } }),
});

export const copyUserBanners = (banners: IUser['banners']) => ({
...(banners &&
Object.entries(banners).map((banner) => {
const [key, value] = banner;
return {
[key]: {
...value,
...(value.textArguments?.length && { textArguments: [...value.textArguments] }),
...(value.modifiers?.length && { modifiers: [...value.modifiers] }),
},
};
})),
});

// ignores deprecated properties
export const copyUserObject = (user: IUser) => ({
...user,
...(user.roles?.length && { roles: [...user.roles] }),
...(user.emails?.length && { emails: user.emails.map(copyUserEmail) }),
...(user.oauth?.authorizedClients?.length && { oauth: { authorizedClients: [...user.oauth.authorizedClients] } }),
...(user.e2e && { e2e: { ...user.e2e } }),
...(user.customFields && { customFields: { ...user.customFields } }),
...(user.settings && { settings: copyUserSettings(user.settings) }),
...(user.banners && { banners: copyUserBanners(user.banners) }),
...(user.importIds && { importIds: { ...user.importIds } }),
...(user.roomRolePriorities && { roomRolePriorities: { ...user.roomRolePriorities } }),
});

export interface IRegisterUser extends IUser {
username: string;
name: string;
Expand Down
Loading