mirror of
https://github.com/Unleash/unleash.git
synced 2025-12-21 20:06:40 +01:00
make context field fetch differentiate based on project ID (#11151)
Implements the minimum number of changes in the back end to make the get operations work separately for project / global context. Avoids going to the store for now, instead doing filtering in the service. --------- Co-authored-by: kwasniew <kwasniewski.mateusz@gmail.com>
This commit is contained in:
parent
9d14ebad1a
commit
4ef2050669
@ -54,6 +54,16 @@ class ContextService {
|
||||
return this.contextFieldStore.getAll();
|
||||
}
|
||||
|
||||
async getAllWithoutProject(): Promise<IContextField[]> {
|
||||
const allFields = await this.contextFieldStore.getAll();
|
||||
return allFields.filter((field) => !field.project);
|
||||
}
|
||||
|
||||
async getAllForProject(projectId: string): Promise<IContextField[]> {
|
||||
const allFields = await this.contextFieldStore.getAll();
|
||||
return allFields.filter((field) => field.project === projectId);
|
||||
}
|
||||
|
||||
async getContextField(name: string): Promise<IContextField> {
|
||||
const field = await this.contextFieldStore.get(name);
|
||||
if (field === undefined) {
|
||||
|
||||
@ -41,6 +41,7 @@ import type { CreateContextFieldSchema } from '../../openapi/spec/create-context
|
||||
import { extractUserIdFromUser } from '../../util/index.js';
|
||||
import type { LegalValueSchema } from '../../openapi/index.js';
|
||||
import type { WithTransactional } from '../../db/transaction.js';
|
||||
import type { IFlagResolver } from '../../types/index.js';
|
||||
|
||||
interface ContextParam {
|
||||
contextField: string;
|
||||
@ -58,6 +59,8 @@ export class ContextController extends Controller {
|
||||
|
||||
private openApiService: OpenApiService;
|
||||
|
||||
private flagResolver: IFlagResolver;
|
||||
|
||||
constructor(
|
||||
config: IUnleashConfig,
|
||||
{
|
||||
@ -74,6 +77,7 @@ export class ContextController extends Controller {
|
||||
this.transactionalContextService = transactionalContextService;
|
||||
const prefix = mode === 'global' ? '' : '/:projectId/context';
|
||||
const beta = mode === 'project';
|
||||
this.flagResolver = config.flagResolver;
|
||||
|
||||
this.route({
|
||||
method: 'get',
|
||||
@ -281,14 +285,27 @@ export class ContextController extends Controller {
|
||||
}
|
||||
|
||||
async getContextFields(
|
||||
_req: Request,
|
||||
req: Request<{ projectId?: string }>,
|
||||
res: Response<ContextFieldsSchema>,
|
||||
): Promise<void> {
|
||||
res.status(200)
|
||||
.json(
|
||||
serializeDates(await this.transactionalContextService.getAll()),
|
||||
)
|
||||
.end();
|
||||
if (this.flagResolver.isEnabled('projectContextFields')) {
|
||||
const { projectId } = req.params;
|
||||
const getContextFields = projectId
|
||||
? this.transactionalContextService.getAllForProject(projectId)
|
||||
: this.transactionalContextService.getAllWithoutProject();
|
||||
|
||||
res.status(200)
|
||||
.json(serializeDates(await getContextFields))
|
||||
.end();
|
||||
} else {
|
||||
res.status(200)
|
||||
.json(
|
||||
serializeDates(
|
||||
await this.transactionalContextService.getAll(),
|
||||
),
|
||||
)
|
||||
.end();
|
||||
}
|
||||
}
|
||||
|
||||
async getContextField(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user