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

chore: remove manual anonymization of outgoing project owners #8252

Merged
merged 3 commits into from
Sep 26, 2024
Merged
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
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 @@ -258,13 +258,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