Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: return 404 if the project doesn't exist #8362

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { OnboardingReadModel } from '../onboarding/onboarding-read-model';
import { FakeOnboardingReadModel } from '../onboarding/fake-onboarding-read-model';
import { AccessStore } from '../../db/access-store';
import FakeAccessStore from '../../../test/fixtures/fake-access-store';
import ProjectStore from '../project/project-store';
import FakeProjectStore from '../../../test/fixtures/fake-project-store';

export const createPersonalDashboardService = (
db: Db,
Expand All @@ -37,6 +39,12 @@ export const createPersonalDashboardService = (
new PrivateProjectChecker(stores, config),
new AccountStore(db, config.getLogger),
new AccessStore(db, config.eventBus, config.getLogger),
new ProjectStore(
db,
config.eventBus,
config.getLogger,
config.flagResolver,
),
);
};

Expand All @@ -54,5 +62,6 @@ export const createFakePersonalDashboardService = (config: IUnleashConfig) => {
new FakePrivateProjectChecker(),
new FakeAccountStore(),
new FakeAccessStore(),
new FakeProjectStore(),
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,14 @@ test('should return personal dashboard project details', async () => {
});
});

test("should return 404 if the project doesn't exist", async () => {
await loginUser('[email protected]');

await app.request
.get(`/api/admin/personal-dashboard/${randomId()}`)
.expect(404);
});

test('should return Unleash admins', async () => {
await loginUser('[email protected]');
const adminRoleId = 1;
Expand Down
12 changes: 12 additions & 0 deletions src/lib/features/personal-dashboard/personal-dashboard-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
import type { IProjectReadModel } from '../project/project-read-model-type';
import type { IPrivateProjectChecker } from '../private-project/privateProjectCheckerType';
import type {
IProjectStore,
IAccessStore,
IAccountStore,
IEvent,
Expand All @@ -21,6 +22,7 @@ import type { FeatureEventFormatter } from '../../addons/feature-event-formatter
import { generateImageUrl } from '../../util';
import type { PersonalDashboardProjectDetailsSchema } from '../../openapi';
import type { IRoleWithProject } from '../../types/stores/access-store';
import { NotFoundError } from '../../error';

export class PersonalDashboardService {
private personalDashboardReadModel: IPersonalDashboardReadModel;
Expand All @@ -41,6 +43,8 @@ export class PersonalDashboardService {

private accessStore: IAccessStore;

private projectStore: IProjectStore;

constructor(
personalDashboardReadModel: IPersonalDashboardReadModel,
projectOwnersReadModel: IProjectOwnersReadModel,
Expand All @@ -51,6 +55,7 @@ export class PersonalDashboardService {
privateProjectChecker: IPrivateProjectChecker,
accountStore: IAccountStore,
accessStore: IAccessStore,
projectStore: IProjectStore,
) {
this.personalDashboardReadModel = personalDashboardReadModel;
this.projectOwnersReadModel = projectOwnersReadModel;
Expand All @@ -61,6 +66,7 @@ export class PersonalDashboardService {
this.privateProjectChecker = privateProjectChecker;
this.accountStore = accountStore;
this.accessStore = accessStore;
this.projectStore = projectStore;
}

getPersonalFeatures(userId: number): Promise<PersonalFeature[]> {
Expand Down Expand Up @@ -105,6 +111,12 @@ export class PersonalDashboardService {
userId: number,
projectId: string,
): Promise<PersonalDashboardProjectDetailsSchema> {
if (!(await this.projectStore.hasProject(projectId))) {
thomasheartman marked this conversation as resolved.
Show resolved Hide resolved
throw new NotFoundError(
`No project with id "${projectId}" exists.`,
);
}

const formatEvents = (recentEvents: IEvent[]) =>
recentEvents.map((event) => ({
summary: this.featureEventFormatter.format(event).text,
Expand Down
Loading