e6399b180e
Fixes #20193 **Bug Description:** Previously, workspace member avatars failed to render correctly in table views and relation chips (such as the Account Owner field). While the avatar picker dropdown correctly fetched fresh GraphQL data, table views and chips relied on the cached defaultAvatarUrl or avatarUrl fields, which were frequently resolving to empty strings or failing to parse external OAuth URLs correctly. **Root Cause:** - Empty String Defaults: Deleting an avatar or failing to retrieve one defaulted the database state to an empty string ("") instead of null, which caused frontend image components to break rather than render their fallback states. - Missing Permanent URLs: The WorkspaceMemberTranspiler was strictly expecting internal signed URLs. If an avatar was an external OAuth URL, it incorrectly returned an empty string, breaking SSO profile pictures. - Missing Fallbacks: New users lacked a proper Gravatar fallback assignment upon workspace creation. **Changes Made:** - user-workspace.service.ts: Updated the avatar computation logic during user creation to implement a reliable Gravatar fallback and correctly set missing avatars to null instead of empty strings. Updated the storage to use permanent file URLs. - file-url.service.ts: Implemented a getRawFileUrl method to support rendering permanent, non-expiring file URLs for avatars. - workspace-member-transpiler.service.ts: Refactored the URL transpilation logic to gracefully pass through external OAuth URLs (e.g., Google/Microsoft profile pictures) instead of stripping them. - WorkspaceMemberPictureUploader.tsx: Fixed the frontend removal logic so that deleting a profile picture sets the avatarUrl to null (consistent with the backend) rather than an empty string. **Testing:** - Verified that avatars correctly display in relation chips and table views. - Verified that external OAuth avatars load properly. - Verified that deleting an avatar correctly resets the UI to the fallback initials component. Co-authored-by: Charles Bochet <charles@twenty.com> Co-authored-by: Cursor <cursoragent@cursor.com>
137 lines
3.8 KiB
TypeScript
137 lines
3.8 KiB
TypeScript
import { createOneFieldMetadata } from 'test/integration/metadata/suites/field-metadata/utils/create-one-field-metadata.util';
|
|
import { createOneObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/create-one-object-metadata.util';
|
|
import { deleteOneObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/delete-one-object-metadata.util';
|
|
import { updateOneObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/update-one-object-metadata.util';
|
|
import { extractRecordIdsAndDatesAsExpectAny } from 'test/utils/extract-record-ids-and-dates-as-expect-any';
|
|
import {
|
|
eachTestingContextFilter,
|
|
type EachTestingContext,
|
|
} from 'twenty-shared/testing';
|
|
import { FieldMetadataType } from 'twenty-shared/types';
|
|
|
|
import { type UpdateObjectPayload } from 'src/engine/metadata-modules/object-metadata/dtos/update-object.input';
|
|
|
|
type TestingRuntimeContext = {
|
|
objectMetadataId: string;
|
|
numberFieldMetadataId: string;
|
|
};
|
|
|
|
type CreateOneObjectMetadataItemTestingContext = EachTestingContext<
|
|
| ((args: TestingRuntimeContext) => Partial<UpdateObjectPayload>)
|
|
| Partial<UpdateObjectPayload>
|
|
>[];
|
|
|
|
const labelIdentifierFailingTestsUseCase: CreateOneObjectMetadataItemTestingContext =
|
|
[
|
|
{
|
|
title: 'when labelIdentifier is not a uuid',
|
|
context: {
|
|
labelIdentifierFieldMetadataId: 'not-a-uuid',
|
|
},
|
|
},
|
|
{
|
|
title: 'when labelIdentifier is not a known field metadata id',
|
|
context: {
|
|
labelIdentifierFieldMetadataId: '42422020-f49c-4159-8751-76a24f47b360',
|
|
},
|
|
},
|
|
{
|
|
title: 'when labelIdentifier is not a TEXT or NAME field',
|
|
context: ({ numberFieldMetadataId }) => ({
|
|
labelIdentifierFieldMetadataId: numberFieldMetadataId,
|
|
}),
|
|
},
|
|
];
|
|
|
|
const imageIdentifierFailingTestsUseCase: CreateOneObjectMetadataItemTestingContext =
|
|
[
|
|
{
|
|
title: 'when imageIdentifier is not a uuid',
|
|
context: {
|
|
imageIdentifierFieldMetadataId: 'not-a-uuid',
|
|
},
|
|
},
|
|
];
|
|
|
|
const allTestsUseCases = [
|
|
...labelIdentifierFailingTestsUseCase,
|
|
...imageIdentifierFailingTestsUseCase,
|
|
];
|
|
|
|
describe('Object metadata update should fail', () => {
|
|
let objectMetadataId: string;
|
|
let numberFieldMetadataId: string;
|
|
|
|
beforeAll(async () => {
|
|
const { data } = await createOneObjectMetadata({
|
|
expectToFail: false,
|
|
input: {
|
|
labelPlural: 'whatevers',
|
|
labelSingular: 'whatever',
|
|
namePlural: 'whatevers',
|
|
nameSingular: 'whatever',
|
|
},
|
|
});
|
|
|
|
objectMetadataId = data.createOneObject.id;
|
|
|
|
const {
|
|
data: { createOneField },
|
|
} = await createOneFieldMetadata({
|
|
expectToFail: false,
|
|
input: {
|
|
objectMetadataId: objectMetadataId,
|
|
name: 'testName',
|
|
label: 'Test name',
|
|
isLabelSyncedWithName: true,
|
|
type: FieldMetadataType.NUMBER,
|
|
},
|
|
});
|
|
|
|
numberFieldMetadataId = createOneField.id;
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await updateOneObjectMetadata({
|
|
expectToFail: false,
|
|
input: {
|
|
idToUpdate: objectMetadataId,
|
|
updatePayload: {
|
|
isActive: false,
|
|
},
|
|
},
|
|
});
|
|
await deleteOneObjectMetadata({
|
|
input: {
|
|
idToDelete: objectMetadataId,
|
|
},
|
|
});
|
|
});
|
|
|
|
it.each(eachTestingContextFilter(allTestsUseCases))(
|
|
'$title',
|
|
async ({ context }) => {
|
|
const updatePayload =
|
|
typeof context === 'function'
|
|
? context({
|
|
numberFieldMetadataId,
|
|
objectMetadataId,
|
|
})
|
|
: context;
|
|
|
|
const { errors } = await updateOneObjectMetadata({
|
|
input: {
|
|
idToUpdate: objectMetadataId,
|
|
updatePayload,
|
|
},
|
|
expectToFail: true,
|
|
});
|
|
|
|
expect(errors).toBeDefined();
|
|
expect(errors).toMatchSnapshot(
|
|
extractRecordIdsAndDatesAsExpectAny(errors),
|
|
);
|
|
},
|
|
);
|
|
});
|