1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

chore: remove manual anonymization of outgoing project owners (#8252)

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.
This commit is contained in:
Thomas Heartman 2024-09-26 11:29:18 +02:00 committed by GitHub
parent ceb21fbe51
commit a7e0743d88
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 7 additions and 54 deletions

View File

@ -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$/),
},
],
});
});
});

View File

@ -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,
@ -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(
@ -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),
};
@ -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<
@ -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);
}

View File

@ -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>>;
}

View File

@ -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> {

View File

@ -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,