diff --git a/src/lib/db/project-store.ts b/src/lib/db/project-store.ts index fdf01d431f..f62a5422ec 100644 --- a/src/lib/db/project-store.ts +++ b/src/lib/db/project-store.ts @@ -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)[]; - 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( 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', }; } diff --git a/src/lib/services/project-service.ts b/src/lib/services/project-service.ts index 0683c4883c..e8ccf71bfb 100644 --- a/src/lib/services/project-service.ts +++ b/src/lib/services/project-service.ts @@ -177,6 +177,7 @@ export default class ProjectService { query, userId, ); + if (this.flagResolver.isEnabled('privateProjects') && userId) { const projectAccess = await this.privateProjectChecker.getUserAccessibleProjects( diff --git a/src/test/e2e/services/project-service.e2e.test.ts b/src/test/e2e/services/project-service.e2e.test.ts index efbd717a99..e077d1c18c 100644 --- a/src/test/e2e/services/project-service.e2e.test.ts +++ b/src/test/e2e/services/project-service.e2e.test.ts @@ -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'); +});