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

feat: Read flag creator (#7357)

This commit is contained in:
Mateusz Kwasniewski 2024-06-11 15:22:52 +02:00 committed by GitHub
parent 576dd04dc5
commit c1656d8630
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 79 additions and 1 deletions

View File

@ -21,7 +21,7 @@ import type {
PartialSome,
} from '../../types';
import FeatureToggleStore from './feature-toggle-store';
import { ensureStringValue, mapValues } from '../../util';
import { ensureStringValue, generateImageUrl, mapValues } from '../../util';
import type { IFeatureProjectUserParams } from './feature-toggle-controller';
import type { Db } from '../../db/db';
import { isAfter } from 'date-fns';
@ -453,6 +453,22 @@ class FeatureStrategiesStore implements IFeatureStrategiesStore {
acc.stale = r.stale;
acc.createdAt = r.created_at;
if (r.user_id) {
const name =
r.user_name ||
r.user_username ||
r.user_email ||
'unknown';
acc.createdBy = {
id: r.user_id,
name,
imageUrl: generateImageUrl({
id: r.user_id,
email: r.user_email,
username: name,
}),
};
}
acc.type = r.type;
if (!acc.environments[r.environment]) {
acc.environments[r.environment] = {

View File

@ -132,3 +132,37 @@ test('Should not be possible auto-enable feature flag without CREATE_FEATURE_STR
.post(`${url}/${name}/environments/default/on`)
.expect(403);
});
test('Should read flag creator', async () => {
const email = 'user@getunleash.io';
const url = '/api/admin/projects/default/features/';
const name = 'creator.flag';
const user = await app.services.userService.createUser(
{
email,
rootRole: RoleName.EDITOR,
},
TEST_AUDIT_USER,
);
await db.stores.featureToggleStore.create('default', {
name,
createdByUserId: user.id,
});
await app.request.post('/auth/demo/login').send({
email,
});
const { body: feature } = await app.request
.get(`${url}/${name}`)
.expect(200);
expect(feature.createdBy).toEqual({
id: user.id,
name: 'user@getunleash.io',
imageUrl:
'https://gravatar.com/avatar/3957b71c0a6d2528f03b423f432ed2efe855d263400f960248a1080493d9d68a?s=42&d=retro&r=g',
});
});

View File

@ -73,6 +73,29 @@ export const featureSchema = {
example: '2023-01-28T15:21:39.975Z',
description: 'The date the feature was created',
},
createdBy: {
type: 'object',
description: 'User who created the feature flag',
additionalProperties: false,
required: ['id', 'name', 'imageUrl'],
properties: {
id: {
description: 'The user id',
type: 'integer',
example: 123,
},
name: {
description: 'Name of the user',
type: 'string',
example: 'User',
},
imageUrl: {
description: `URL used for the user profile image`,
type: 'string',
example: 'https://example.com/242x200.png',
},
},
},
archivedAt: {
type: 'string',
format: 'date-time',

View File

@ -61,6 +61,11 @@ export interface FeatureToggleDTO {
impressionData?: boolean;
variants?: IVariant[];
createdByUserId?: number;
createdBy?: {
id: number;
name: string;
imageUrl: string;
};
}
export interface FeatureToggle extends FeatureToggleDTO {