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

[Gitar] Cleaning up stale flag: anonymiseEventLog with value true #819

Closed
wants to merge 1 commit into from
Closed
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
1 change: 0 additions & 1 deletion src/lib/__snapshots__/create-config.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ exports[`should create default config 1`] = `
"experiments": {
"addonUsageMetrics": false,
"adminTokenKillSwitch": false,
"anonymiseEventLog": false,
"anonymizeProjectOwners": false,
"archiveProjects": false,
"automatedActions": false,
Expand Down
6 changes: 1 addition & 5 deletions src/lib/features/events/event-search-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import type { IEvent } from '../../types';
import { anonymiseKeys, extractUserIdFromUser } from '../../util';

const ANON_KEYS = ['email', 'username', 'createdBy'];
const version = 1 as const;
export default class EventSearchController extends Controller {
private eventService: EventService;

Expand Down Expand Up @@ -97,9 +96,6 @@ export default class EventSearchController extends Controller {
}

maybeAnonymiseEvents(events: IEvent[]): IEvent[] {
if (this.flagResolver.isEnabled('anonymiseEventLog')) {
return anonymiseKeys(events, ANON_KEYS);
}
return events;
return anonymiseKeys(events, ANON_KEYS);
}
}
17 changes: 7 additions & 10 deletions src/lib/features/feature-search/feature-search-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,13 @@ export default class FeatureSearchController extends Controller {
maybeAnonymise(
features: IFeatureSearchOverview[],
): IFeatureSearchOverview[] {
if (this.flagResolver.isEnabled('anonymiseEventLog')) {
return features.map((feature) => ({
...feature,
createdBy: {
...feature.createdBy,
name: anonymise(feature.createdBy.name),
},
}));
}
return features;
return features.map((feature) => ({
...feature,
createdBy: {
...feature.createdBy,
name: anonymise(feature.createdBy.name),
},
}));
}

async searchFeatures(
Expand Down
23 changes: 10 additions & 13 deletions src/lib/features/feature-search/feature.search.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ beforeAll(async () => {
experimental: {
flags: {
strictSchemaValidation: true,
anonymiseEventLog: true,
},
},
},
Expand Down Expand Up @@ -211,24 +210,22 @@ test('should paginate with offset', async () => {
await app.createFeature('my_feature_c');
await app.createFeature('my_feature_d');

const { body: firstPage, headers: firstHeaders } =
await searchFeaturesWithOffset({
query: 'feature',
offset: '0',
limit: '2',
});
const { body: firstPage } = await searchFeaturesWithOffset({
query: 'feature',
offset: '0',
limit: '2',
});

expect(firstPage).toMatchObject({
features: [{ name: 'my_feature_a' }, { name: 'my_feature_b' }],
total: 4,
});

const { body: secondPage, headers: secondHeaders } =
await searchFeaturesWithOffset({
query: 'feature',
offset: '2',
limit: '2',
});
const { body: secondPage } = await searchFeaturesWithOffset({
query: 'feature',
offset: '2',
limit: '2',
});

expect(secondPage).toMatchObject({
features: [{ name: 'my_feature_c' }, { name: 'my_feature_d' }],
Expand Down
17 changes: 4 additions & 13 deletions src/lib/features/feature-toggle/feature-toggle-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -699,10 +699,7 @@ export default class ProjectFeaturesController extends Controller {
}

maybeAnonymise(feature: FeatureToggleView): FeatureToggleView {
if (
this.flagResolver.isEnabled('anonymiseEventLog') &&
feature.createdBy
) {
if (feature.createdBy) {
return {
...feature,
...(feature.collaborators
Expand Down Expand Up @@ -754,7 +751,7 @@ export default class ProjectFeaturesController extends Controller {
res: Response<FeatureSchema>,
): Promise<void> {
const { projectId, featureName } = req.params;
const { createdAt, ...data } = req.body;
const { ...data } = req.body;
if (data.name && data.name !== featureName) {
throw new BadDataError('Cannot change name of feature flag');
}
Expand Down Expand Up @@ -842,7 +839,7 @@ export default class ProjectFeaturesController extends Controller {
res: Response<FeatureEnvironmentSchema>,
): Promise<void> {
const { environment, featureName, projectId } = req.params;
const { defaultStrategy, ...environmentInfo } =
const { ...environmentInfo } =
await this.featureService.getEnvironmentInfo(
projectId,
environment,
Expand All @@ -852,13 +849,7 @@ export default class ProjectFeaturesController extends Controller {
const result = {
...environmentInfo,
strategies: environmentInfo.strategies.map((strategy) => {
const {
strategyName,
projectId: project,
environment: environmentId,
createdAt,
...rest
} = strategy;
const { strategyName, ...rest } = strategy;
return { ...rest, name: strategyName };
}),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ beforeAll(async () => {
experimental: {
flags: {
strictSchemaValidation: true,
anonymiseEventLog: true,
},
},
},
Expand Down
4 changes: 1 addition & 3 deletions src/lib/features/segment/admin-segment.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,7 @@ const validateSegment = (
beforeAll(async () => {
const customOptions = {
experimental: {
flags: {
anonymiseEventLog: true,
},
flags: {},
},
};

Expand Down
18 changes: 5 additions & 13 deletions src/lib/features/segment/segment-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,9 @@ export class SegmentsController extends Controller {
const { strategyId } = req.params;
const segments = await this.segmentService.getByStrategy(strategyId);

const responseBody = this.flagResolver.isEnabled('anonymiseEventLog')
? {
segments: anonymiseKeys(segments, ['createdBy']),
}
: { segments };
const responseBody = {
segments: anonymiseKeys(segments, ['createdBy']),
};

this.openApiService.respondWithValidation(
200,
Expand Down Expand Up @@ -427,11 +425,7 @@ export class SegmentsController extends Controller {
): Promise<void> {
const id = Number(req.params.id);
const segment = await this.segmentService.get(id);
if (this.flagResolver.isEnabled('anonymiseEventLog')) {
res.json(anonymiseKeys(segment, ['createdBy']));
} else {
res.json(segment);
}
res.json(anonymiseKeys(segment, ['createdBy']));
}

async createSegment(
Expand Down Expand Up @@ -459,9 +453,7 @@ export class SegmentsController extends Controller {
const segments = await this.segmentService.getAll();

const response = {
segments: this.flagResolver.isEnabled('anonymiseEventLog')
? anonymiseKeys(segments, ['createdBy'])
: segments,
segments: anonymiseKeys(segments, ['createdBy']),
};

this.openApiService.respondWithValidation<SegmentsSchema>(
Expand Down
5 changes: 1 addition & 4 deletions src/lib/routes/admin-api/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,7 @@ export default class EventController extends Controller {
}

maybeAnonymiseEvents(events: IEvent[]): IEvent[] {
if (this.flagResolver.isEnabled('anonymiseEventLog')) {
return anonymiseKeys(events, ANON_KEYS);
}
return events;
return anonymiseKeys(events, ANON_KEYS);
}

async getEvents(
Expand Down
6 changes: 2 additions & 4 deletions src/lib/routes/admin-api/events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ import {
ProjectUserRemovedEvent,
} from '../../types/events';
import { TEST_AUDIT_USER } from '../../types';

const TEST_USER_ID = -9999;
async function getSetup(anonymise: boolean = false) {
async function getSetup() {
const base = `/random${Math.round(Math.random() * 1000)}`;
const stores = createStores();
const config = createTestConfig({
server: { baseUriPath: base },
experimental: { flags: { anonymiseEventLog: anonymise } },
experimental: { flags: {} },
});
const services = createServices(stores, config);
const app = await getApp(config, stores, services);
Expand Down
12 changes: 4 additions & 8 deletions src/lib/routes/admin-api/user-admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,7 @@ export default class UserAdminController extends Controller {
typeof q === 'string' && q.length > 1
? await this.userService.search(q)
: [];
if (this.flagResolver.isEnabled('anonymiseEventLog')) {
users = this.anonymiseUsers(users);
}
users = this.anonymiseUsers(users);
this.openApiService.respondWithValidation(
200,
res,
Expand All @@ -474,9 +472,7 @@ export default class UserAdminController extends Controller {
accountType: u.accountType,
} as IUser;
});
if (this.flagResolver.isEnabled('anonymiseEventLog')) {
users = this.anonymiseUsers(users);
}
users = this.anonymiseUsers(users);

const allGroups = await this.groupService.getAll();
const groups = allGroups.map((g) => {
Expand Down Expand Up @@ -565,7 +561,7 @@ export default class UserAdminController extends Controller {
>,
res: Response<CreateUserResponseSchema>,
): Promise<void> {
const { user, params, body } = req;
const { params, body } = req;
const { id } = params;
const { name, email, rootRole } = body;

Expand Down Expand Up @@ -596,7 +592,7 @@ export default class UserAdminController extends Controller {
}

async deleteUser(req: IAuthRequest, res: Response): Promise<void> {
const { user, params } = req;
const { params } = req;
const { id } = params;

await this.throwIfScimUser({ id: Number(id) });
Expand Down
2 changes: 0 additions & 2 deletions src/lib/types/experimental.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { getDefaultVariant } from 'unleash-client/lib/variant';

export type IFlagKey =
| 'accessLogs'
| 'anonymiseEventLog'
| 'encryptEmails'
| 'enableLicense'
| 'enableLicenseChecker'
Expand Down Expand Up @@ -72,7 +71,6 @@ export type IFlagKey =
export type IFlags = Partial<{ [key in IFlagKey]: boolean | Variant }>;

const flags: IFlags = {
anonymiseEventLog: false,
enableLicense: false,
enableLicenseChecker: false,
embedProxy: parseEnvVarBoolean(
Expand Down
4 changes: 1 addition & 3 deletions src/lib/users/inactive/inactive-users-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ export class InactiveUsersController extends Controller {
): Promise<void> {
this.logger.info('Hitting inactive users');
let inactiveUsers = await this.inactiveUsersService.getInactiveUsers();
if (this.flagResolver.isEnabled('anonymiseEventLog')) {
inactiveUsers = this.anonymiseUsers(inactiveUsers);
}
inactiveUsers = this.anonymiseUsers(inactiveUsers);
this.openApiService.respondWithValidation(
200,
res,
Expand Down
1 change: 0 additions & 1 deletion src/server-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ process.nextTick(async () => {
flags: {
embedProxy: true,
embedProxyFrontend: true,
anonymiseEventLog: false,
responseTimeWithAppNameKillSwitch: false,
stripHeadersOnAPI: true,
celebrateUnleash: true,
Expand Down
2 changes: 1 addition & 1 deletion src/test/e2e/api/admin/user-admin.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ test('generates USER_UPDATED event', async () => {
test('Anonymises name, username and email fields if anonymiseEventLog flag is set', async () => {
const anonymisedApp = await setupAppWithCustomConfig(
stores,
{ experimental: { flags: { anonymiseEventLog: true } } },
{ experimental: { flags: {} } },
db.rawDatabase,
);
await anonymisedApp.request
Expand Down
Loading