Skip to content

Commit

Permalink
chore: remove manual anonymization of outgoing project owners (#8252)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
thomasheartman authored Sep 26, 2024
1 parent ceb21fb commit a7e0743
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 54 deletions.
21 changes: 0 additions & 21 deletions src/lib/features/project/project-owners-read-model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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$/),
},
],
});
});
});
26 changes: 6 additions & 20 deletions src/lib/features/project/project-owners-read-model.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -35,7 +35,6 @@ export class ProjectOwnersReadModel implements IProjectOwnersReadModel {

private async getAllProjectUsersByRole(
roleId: number,
anonymizeProjectOwners: boolean = false,
): Promise<Record<string, UserProjectOwner[]>> {
const usersResult = await this.db
.select(
Expand All @@ -54,20 +53,13 @@ export class ProjectOwnersReadModel implements IProjectOwnersReadModel {
.join(`${T.USERS} as user`, 'ru.user_id', 'user.id');
const usersDict: Record<string, UserProjectOwner[]> = {};

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 ||
processSensitiveData(user?.email),
email: processSensitiveData(user?.email),
name: user?.name || user?.username || user?.email,
email: user?.email,
imageUrl: generateImageUrl(user),
};

Expand Down Expand Up @@ -112,16 +104,11 @@ export class ProjectOwnersReadModel implements IProjectOwnersReadModel {
return groupsDict;
}

async getAllProjectOwners(
anonymizeProjectOwners: boolean = false,
): Promise<ProjectOwnersDictionary> {
async getAllProjectOwners(): Promise<ProjectOwnersDictionary> {
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<
Expand All @@ -142,9 +129,8 @@ export class ProjectOwnersReadModel implements IProjectOwnersReadModel {

async addOwners<T extends { id: string }>(
projects: T[],
anonymizeProjectOwners: boolean = false,
): Promise<WithProjectOwners<T>> {
const owners = await this.getAllProjectOwners(anonymizeProjectOwners);
const owners = await this.getAllProjectOwners();

return ProjectOwnersReadModel.addOwnerData(projects, owners);
}
Expand Down
1 change: 0 additions & 1 deletion src/lib/features/project/project-owners-read-model.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,5 @@ export type WithProjectOwners<T extends { id: string }> = (T & {
export interface IProjectOwnersReadModel {
addOwners<T extends { id: string }>(
projects: T[],
anonymizeProjectOwners?: boolean,
): Promise<WithProjectOwners<T>>;
}
8 changes: 1 addition & 7 deletions src/lib/features/project/project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,7 @@ export default class ProjectService {
async addOwnersToProjects(
projects: ProjectForUi[],
): Promise<ProjectForUi[]> {
const anonymizeProjectOwners = this.flagResolver.isEnabled(
'anonymizeProjectOwners',
);
return this.projectOwnersReadModel.addOwners(
projects,
anonymizeProjectOwners,
);
return this.projectOwnersReadModel.addOwners(projects);
}

async getProject(id: string): Promise<IProject> {
Expand Down
5 changes: 0 additions & 5 deletions src/lib/types/experimental.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export type IFlagKey =
| 'manyStrategiesPagination'
| 'enableLegacyVariants'
| 'navigationSidebar'
| 'anonymizeProjectOwners'
| 'extendedMetrics'
| 'removeUnsafeInlineStyleSrc'
| 'originMiddleware'
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit a7e0743

Please sign in to comment.