From fe8ccf9debaf2f2064354a133c4f5768a040ac20 Mon Sep 17 00:00:00 2001 From: Thomas Heartman Date: Wed, 25 Sep 2024 12:53:25 +0200 Subject: [PATCH 1/2] chore: remove manual anonymization of outgoing project owners This change removes the flag used to anonymize project owners on the way out. It was an issue in demo when we'd forgotten to configure the email encryption. However, this issue has been resolved and we can remove this check now. --- .../project/project-owners-read-model.ts | 21 +++++-------------- .../project/project-owners-read-model.type.ts | 5 +---- src/lib/features/project/project-service.ts | 8 +------ src/lib/types/experimental.ts | 5 ----- 4 files changed, 7 insertions(+), 32 deletions(-) diff --git a/src/lib/features/project/project-owners-read-model.ts b/src/lib/features/project/project-owners-read-model.ts index c4c39dbfbd2a..90b96e12e517 100644 --- a/src/lib/features/project/project-owners-read-model.ts +++ b/src/lib/features/project/project-owners-read-model.ts @@ -1,6 +1,6 @@ import type { Db } from '../../db/db'; import { RoleName } from '../../types'; -import { anonymise, generateImageUrl } from '../../util'; +import { generateImageUrl } from '../../util'; import type { GroupProjectOwner, IProjectOwnersReadModel, @@ -36,7 +36,6 @@ export class ProjectOwnersReadModel implements IProjectOwnersReadModel { private async getAllProjectUsersByRole( roleId: number, - anonymizeProjectOwners: boolean = false, ): Promise> { const usersResult = await this.db .select( @@ -55,17 +54,13 @@ export class ProjectOwnersReadModel implements IProjectOwnersReadModel { .join(`${T.USERS} as user`, 'ru.user_id', 'user.id'); const usersDict: Record = {}; - const processSensitiveData = anonymizeProjectOwners - ? anonymise - : (x: string) => x; - usersResult.forEach((user) => { const project = user.project as string; const data: UserProjectOwner = { ownerType: 'user', name: user?.name || user?.username, - email: processSensitiveData(user?.email), + email: user?.email, imageUrl: generateImageUrl(user), }; @@ -110,16 +105,11 @@ export class ProjectOwnersReadModel implements IProjectOwnersReadModel { return groupsDict; } - async getAllProjectOwners( - anonymizeProjectOwners: boolean = false, - ): Promise { + async getAllProjectOwners(): Promise { const ownerRole = await this.db(T.ROLES) .where({ name: RoleName.OWNER }) .first(); - const usersDict = await this.getAllProjectUsersByRole( - ownerRole.id, - anonymizeProjectOwners, - ); + const usersDict = await this.getAllProjectUsersByRole(ownerRole.id); const groupsDict = await this.getAllProjectGroupsByRole(ownerRole.id); const dict: Record< @@ -140,9 +130,8 @@ export class ProjectOwnersReadModel implements IProjectOwnersReadModel { async addOwners( projects: ProjectForUi[], - anonymizeProjectOwners: boolean = false, ): Promise { - const owners = await this.getAllProjectOwners(anonymizeProjectOwners); + const owners = await this.getAllProjectOwners(); return ProjectOwnersReadModel.addOwnerData(projects, owners); } diff --git a/src/lib/features/project/project-owners-read-model.type.ts b/src/lib/features/project/project-owners-read-model.type.ts index 843f2208c234..93acffc2cb6a 100644 --- a/src/lib/features/project/project-owners-read-model.type.ts +++ b/src/lib/features/project/project-owners-read-model.type.ts @@ -22,8 +22,5 @@ export type IProjectForUiWithOwners = ProjectForUi & { }; export interface IProjectOwnersReadModel { - addOwners( - projects: ProjectForUi[], - anonymizeProjectOwners?: boolean, - ): Promise; + addOwners(projects: ProjectForUi[]): Promise; } diff --git a/src/lib/features/project/project-service.ts b/src/lib/features/project/project-service.ts index fbcec958bcba..7d4ae952153b 100644 --- a/src/lib/features/project/project-service.ts +++ b/src/lib/features/project/project-service.ts @@ -258,13 +258,7 @@ export default class ProjectService { async addOwnersToProjects( projects: ProjectForUi[], ): Promise { - const anonymizeProjectOwners = this.flagResolver.isEnabled( - 'anonymizeProjectOwners', - ); - return this.projectOwnersReadModel.addOwners( - projects, - anonymizeProjectOwners, - ); + return this.projectOwnersReadModel.addOwners(projects); } async getProject(id: string): Promise { diff --git a/src/lib/types/experimental.ts b/src/lib/types/experimental.ts index bf245a5c1df5..9df11056bc8d 100644 --- a/src/lib/types/experimental.ts +++ b/src/lib/types/experimental.ts @@ -52,7 +52,6 @@ export type IFlagKey = | 'manyStrategiesPagination' | 'enableLegacyVariants' | 'navigationSidebar' - | 'anonymizeProjectOwners' | 'extendedMetrics' | 'removeUnsafeInlineStyleSrc' | 'originMiddleware' @@ -262,10 +261,6 @@ const flags: IFlags = { process.env.UNLEASH_EXPERIMENTAL_SIDEBAR_NAVIGATION, true, ), - anonymizeProjectOwners: parseEnvVarBoolean( - process.env.UNLEASH_EXPERIMENTAL_ANONYMIZE_PROJECT_OWNERS, - false, - ), extendedMetrics: parseEnvVarBoolean( process.env.UNLEASH_EXPERIMENTAL_EXTENDED_METRICS, false, From 65fbd20fca68c87a3c4a266b7e27cfacfc5c7908 Mon Sep 17 00:00:00 2001 From: Thomas Heartman Date: Wed, 25 Sep 2024 12:59:02 +0200 Subject: [PATCH 2/2] chore: remove redundant test --- .../project/project-owners-read-model.test.ts | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/src/lib/features/project/project-owners-read-model.test.ts b/src/lib/features/project/project-owners-read-model.test.ts index eb6055e5715d..831310cc573e 100644 --- a/src/lib/features/project/project-owners-read-model.test.ts +++ b/src/lib/features/project/project-owners-read-model.test.ts @@ -361,25 +361,4 @@ describe('integration tests', () => { { name: projectIdB, owners: [{ ownerType: 'user' }] }, ]); }); - - test('anonymizes emails when asked to', async () => { - const projectId = randomId(); - await db.stores.projectStore.create({ id: projectId, name: projectId }); - - await db.stores.accessStore.addUserToRole( - owner.id, - ownerRoleId, - projectId, - ); - - const owners = await readModel.getAllProjectOwners(true); - expect(owners).toMatchObject({ - [projectId]: [ - { - name: 'Owner Name', - email: expect.stringMatching(/@unleash.run$/), - }, - ], - }); - }); });