1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-20 00:08:02 +01:00

fix: hardcoded stickiness and mode fields (#5342)

This PR fixes an issue where project overview would return hardcoded
project mode and stickiness fields.
This commit is contained in:
Fredrik Strand Oseberg 2023-11-17 12:32:13 +01:00 committed by GitHub
parent 572610a0d8
commit fd453f5af7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 64 additions and 3 deletions

View File

@ -128,17 +128,30 @@ class ProjectStore implements IProjectStore {
const projectTimer = this.timer('getProjectsWithCount');
let projects = this.db(TABLE)
.leftJoin('features', 'features.project', 'projects.id')
.leftJoin(
'project_settings',
'project_settings.project',
'projects.id',
)
.orderBy('projects.name', 'asc');
if (query) {
projects = projects.where(query);
}
let selectColumns = [
this.db.raw(
'projects.id, projects.name, projects.description, projects.health, projects.updated_at, projects.created_at, count(features.name) FILTER (WHERE features.archived_at is null) AS number_of_features',
),
'project_settings.default_stickiness',
'project_settings.project_mode',
] as (string | Raw<any>)[];
let groupByColumns = ['projects.id'];
let groupByColumns = [
'projects.id',
'project_settings.default_stickiness',
'project_settings.project_mode',
];
if (userId) {
projects = projects.leftJoin(`favorite_projects`, function () {
@ -172,6 +185,7 @@ class ProjectStore implements IProjectStore {
const memberMap = new Map<string, number>(
memberCount.map((c) => [c.project, Number(c.count)]),
);
return projectsWithFeatureCount.map((projectWithCount) => {
return {
...projectWithCount,
@ -192,8 +206,8 @@ class ProjectStore implements IProjectStore {
memberCount: Number(row.number_of_users) || 0,
updatedAt: row.updated_at,
createdAt: row.created_at,
mode: 'open',
defaultStickiness: 'default',
mode: row.project_mode || 'open',
defaultStickiness: row.default_stickiness || 'default',
};
}

View File

@ -177,6 +177,7 @@ export default class ProjectService {
query,
userId,
);
if (this.flagResolver.isEnabled('privateProjects') && userId) {
const projectAccess =
await this.privateProjectChecker.getUserAccessibleProjects(

View File

@ -1999,3 +1999,49 @@ test('deleting a project with no archived toggles should not result in an error'
await projectService.createProject(project, user);
await projectService.deleteProject(project.id, user);
});
test('should get project settings with mode', async () => {
const projectOne = {
id: 'mode-private',
name: 'New project',
description: 'Desc',
mode: 'open' as const,
defaultStickiness: 'default',
};
const projectTwo = {
id: 'mode-open',
name: 'New project',
description: 'Desc',
mode: 'open' as const,
defaultStickiness: 'default',
};
const updatedProject = {
id: 'mode-private',
name: 'New name',
description: 'Desc',
mode: 'private' as const,
defaultStickiness: 'clientId',
};
const { mode, id, ...rest } = updatedProject;
await projectService.createProject(projectOne, user);
await projectService.createProject(projectTwo, user);
await projectService.updateProject({ id, ...rest }, user);
await projectService.updateProjectEnterpriseSettings({ mode, id }, user);
const projects = await projectService.getProjects();
const foundProjectOne = projects.find(
(project) => projectOne.id === project.id,
);
const foundProjectTwo = projects.find(
(project) => projectTwo.id === project.id,
);
expect(foundProjectOne!.mode).toBe('private');
expect(foundProjectOne!.defaultStickiness).toBe('clientId');
expect(foundProjectTwo!.mode).toBe('open');
expect(foundProjectTwo!.defaultStickiness).toBe('default');
});