diff --git a/src/lib/features/personal-dashboard/personal-dashboard-controller.e2e.test.ts b/src/lib/features/personal-dashboard/personal-dashboard-controller.e2e.test.ts index b8b81d728e..efef09eeaf 100644 --- a/src/lib/features/personal-dashboard/personal-dashboard-controller.e2e.test.ts +++ b/src/lib/features/personal-dashboard/personal-dashboard-controller.e2e.test.ts @@ -175,3 +175,15 @@ test('should return projects where users are part of a group', async () => { ], }); }); + +test('should return personal dashboard project details', async () => { + await loginUser('new_user@test.com'); + const { body } = await app.request.get( + `/api/admin/personal-dashboard/default`, + ); + + expect(body).toMatchObject({ + owners: [{}], + roles: [{}], + }); +}); diff --git a/src/lib/features/personal-dashboard/personal-dashboard-controller.ts b/src/lib/features/personal-dashboard/personal-dashboard-controller.ts index a7e1f3d21f..555af985c5 100644 --- a/src/lib/features/personal-dashboard/personal-dashboard-controller.ts +++ b/src/lib/features/personal-dashboard/personal-dashboard-controller.ts @@ -10,8 +10,10 @@ import Controller from '../../routes/controller'; import type { Response } from 'express'; import type { IAuthRequest } from '../../routes/unleash-types'; import type { PersonalDashboardService } from './personal-dashboard-service'; - -const PATH = ''; +import { + personalDashboardProjectDetailsSchema, + type PersonalDashboardProjectDetailsSchema, +} from '../../openapi/spec/personal-dashboard-project-details-schema'; export default class PersonalDashboardController extends Controller { private openApiService: OpenApiService; @@ -34,7 +36,7 @@ export default class PersonalDashboardController extends Controller { this.route({ method: 'get', - path: PATH, + path: '', handler: this.getPersonalDashboard, permission: NONE, middleware: [ @@ -51,6 +53,28 @@ export default class PersonalDashboardController extends Controller { }), ], }); + + this.route({ + method: 'get', + path: '/:projectId', + handler: this.getPersonalDashboardProjectDetails, + permission: NONE, + middleware: [ + openApiService.validPath({ + tags: ['Unstable'], + summary: 'Get personal project details', + description: + 'Return personal dashboard project events, owners, user roles and onboarding status', + operationId: 'getPersonalDashboardProjectDetails', + responses: { + 200: createResponseSchema( + 'personalDashboardProjectDetailsSchema', + ), + ...getStandardResponses(401, 403, 404), + }, + }), + ], + }); } async getPersonalDashboard( @@ -73,4 +97,21 @@ export default class PersonalDashboardController extends Controller { { projects, flags }, ); } + + async getPersonalDashboardProjectDetails( + req: IAuthRequest<{ projectId: string }>, + res: Response, + ): Promise { + const user = req.user; + + this.openApiService.respondWithValidation( + 200, + res, + personalDashboardProjectDetailsSchema.$id, + { + owners: [{ ownerType: 'user', name: 'placeholder' }], + roles: [{ name: 'placeholder', id: 0, type: 'project' }], + }, + ); + } } diff --git a/src/lib/openapi/spec/index.ts b/src/lib/openapi/spec/index.ts index 8b6fa7457e..4341ec77c9 100644 --- a/src/lib/openapi/spec/index.ts +++ b/src/lib/openapi/spec/index.ts @@ -133,6 +133,7 @@ export * from './patch-schema'; export * from './patches-schema'; export * from './pats-schema'; export * from './permission-schema'; +export * from './personal-dashboard-project-details-schema'; export * from './personal-dashboard-schema'; export * from './playground-constraint-schema'; export * from './playground-feature-schema'; diff --git a/src/lib/openapi/spec/personal-dashboard-project-details-schema.ts b/src/lib/openapi/spec/personal-dashboard-project-details-schema.ts new file mode 100644 index 0000000000..390c5d11ae --- /dev/null +++ b/src/lib/openapi/spec/personal-dashboard-project-details-schema.ts @@ -0,0 +1,49 @@ +import type { FromSchema } from 'json-schema-to-ts'; +import { projectSchema } from './project-schema'; + +export const personalDashboardProjectDetailsSchema = { + $id: '#/components/schemas/personalDashboardProjectDetailsSchema', + type: 'object', + description: 'Project details in personal dashboard', + additionalProperties: false, + required: ['owners', 'roles'], + properties: { + owners: projectSchema.properties.owners, + roles: { + type: 'array', + description: 'The list of roles that the user has in this project.', + minItems: 1, + items: { + type: 'object', + description: 'An Unleash role.', + additionalProperties: false, + required: ['name', 'id', 'type'], + properties: { + name: { + type: 'string', + example: 'Owner', + description: 'The name of the role', + }, + id: { + type: 'integer', + example: 4, + description: 'The id of the role', + }, + type: { + type: 'string', + enum: ['custom', 'project', 'root', 'custom-root'], + example: 'project', + description: 'The type of the role', + }, + }, + }, + }, + }, + components: { + schemas: {}, + }, +} as const; + +export type PersonalDashboardProjectDetailsSchema = FromSchema< + typeof personalDashboardProjectDetailsSchema +>; diff --git a/src/lib/openapi/spec/personal-dashboard-schema.ts b/src/lib/openapi/spec/personal-dashboard-schema.ts index 6275561909..8277ab53c2 100644 --- a/src/lib/openapi/spec/personal-dashboard-schema.ts +++ b/src/lib/openapi/spec/personal-dashboard-schema.ts @@ -1,5 +1,4 @@ import type { FromSchema } from 'json-schema-to-ts'; -import { projectSchema } from './project-schema'; export const personalDashboardSchema = { $id: '#/components/schemas/personalDashboardSchema', @@ -47,42 +46,6 @@ export const personalDashboardSchema = { example: 10, description: 'The number of features this project has', }, - owners: projectSchema.properties.owners, - roles: { - type: 'array', - description: - 'The list of roles that the user has in this project.', - minItems: 1, - items: { - type: 'object', - description: 'An Unleash role.', - additionalProperties: false, - required: ['name', 'id', 'type'], - properties: { - name: { - type: 'string', - example: 'Owner', - description: 'The name of the role', - }, - id: { - type: 'integer', - example: 4, - description: 'The id of the role', - }, - type: { - type: 'string', - enum: [ - 'custom', - 'project', - 'root', - 'custom-root', - ], - example: 'project', - description: 'The type of the role', - }, - }, - }, - }, }, }, description: