Rework locale computation on BE (#13247)
Context: Users are complaining to see their workspace in a language they don't know. This behavior is transient, happens on data model update and disappear on refresh I've check the cache for users that got the issue and did not spot any weird language ==> I think we somehow fallback the the request header locale. I feel we should always use the userWorkspace.locale, request locale should not be used in BE in my opinion except for unauthenticated endpoints. I'm also adding logs to understand the locale issue In this PR: rename user.workspaces into user.userWorkspaces which is more correct improve / simplify LOCALES typing
This commit is contained in:
+3
-3
@@ -91,7 +91,7 @@ describe('AdminPanelService', () => {
|
||||
const mockUser = {
|
||||
id: 'user-id',
|
||||
email: 'user@example.com',
|
||||
workspaces: [
|
||||
userWorkspaces: [
|
||||
{
|
||||
workspace: {
|
||||
id: 'workspace-id',
|
||||
@@ -114,12 +114,12 @@ describe('AdminPanelService', () => {
|
||||
expect.objectContaining({
|
||||
where: expect.objectContaining({
|
||||
id: 'user-id',
|
||||
workspaces: {
|
||||
userWorkspaces: {
|
||||
workspaceId: 'workspace-id',
|
||||
workspace: { allowImpersonation: true },
|
||||
},
|
||||
}),
|
||||
relations: ['workspaces', 'workspaces.workspace'],
|
||||
relations: { userWorkspaces: { workspace: true } },
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
@@ -39,14 +39,14 @@ export class AdminPanelService {
|
||||
const user = await this.userRepository.findOne({
|
||||
where: {
|
||||
id: userId,
|
||||
workspaces: {
|
||||
userWorkspaces: {
|
||||
workspaceId,
|
||||
workspace: {
|
||||
allowImpersonation: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
relations: ['workspaces', 'workspaces.workspace'],
|
||||
relations: { userWorkspaces: { workspace: true } },
|
||||
});
|
||||
|
||||
userValidator.assertIsDefinedOrThrow(
|
||||
@@ -59,14 +59,14 @@ export class AdminPanelService {
|
||||
|
||||
const loginToken = await this.loginTokenService.generateLoginToken(
|
||||
user.email,
|
||||
user.workspaces[0].workspace.id,
|
||||
user.userWorkspaces[0].workspace.id,
|
||||
);
|
||||
|
||||
return {
|
||||
workspace: {
|
||||
id: user.workspaces[0].workspace.id,
|
||||
id: user.userWorkspaces[0].workspace.id,
|
||||
workspaceUrls: this.domainManagerService.getWorkspaceUrls(
|
||||
user.workspaces[0].workspace,
|
||||
user.userWorkspaces[0].workspace,
|
||||
),
|
||||
},
|
||||
loginToken,
|
||||
@@ -101,7 +101,7 @@ export class AdminPanelService {
|
||||
firstName: targetUser.firstName,
|
||||
lastName: targetUser.lastName,
|
||||
},
|
||||
workspaces: targetUser.workspaces.map((userWorkspace) => ({
|
||||
workspaces: targetUser.userWorkspaces.map((userWorkspace) => ({
|
||||
id: userWorkspace.workspace.id,
|
||||
name: userWorkspace.workspace.displayName ?? '',
|
||||
totalUsers: userWorkspace.workspace.workspaceUsers.length,
|
||||
|
||||
Reference in New Issue
Block a user