Skip to content

Commit

Permalink
feat: return project roles
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasheartman committed Oct 1, 2024
1 parent 050e53e commit 968eb11
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { AccountStore } from '../../db/account-store';
import { FakeAccountStore } from '../../../test/fixtures/fake-account-store';
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';

export const createPersonalDashboardService = (
db: Db,
Expand All @@ -34,6 +36,7 @@ export const createPersonalDashboardService = (
}),
new PrivateProjectChecker(stores, config),
new AccountStore(db, config.getLogger),
new AccessStore(db, config.eventBus, config.getLogger),
);
};

Expand All @@ -50,5 +53,6 @@ export const createFakePersonalDashboardService = (config: IUnleashConfig) => {
}),
new FakePrivateProjectChecker(),
new FakeAccountStore(),
new FakeAccessStore(),
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export default class PersonalDashboardController extends Controller {

const projectDetails =
await this.personalDashboardService.getPersonalProjectDetails(
user.id,
req.params.projectId,
);

Expand All @@ -115,8 +116,6 @@ export default class PersonalDashboardController extends Controller {
personalDashboardProjectDetailsSchema.$id,
{
...projectDetails,
owners: [{ ownerType: 'user', name: 'placeholder' }],
roles: [{ name: 'placeholder', id: 0, type: 'project' }],
},
);
}
Expand Down
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 {
IAccessStore,
IAccountStore,
IEventStore,
IOnboardingReadModel,
Expand All @@ -36,6 +37,8 @@ export class PersonalDashboardService {

private onboardingReadModel: IOnboardingReadModel;

private accessStore: IAccessStore;

constructor(
personalDashboardReadModel: IPersonalDashboardReadModel,
projectOwnersReadModel: IProjectOwnersReadModel,
Expand All @@ -45,6 +48,7 @@ export class PersonalDashboardService {
featureEventFormatter: FeatureEventFormatter,
privateProjectChecker: IPrivateProjectChecker,
accountStore: IAccountStore,
accessStore: IAccessStore,
) {
this.personalDashboardReadModel = personalDashboardReadModel;
this.projectOwnersReadModel = projectOwnersReadModel;
Expand All @@ -54,6 +58,7 @@ export class PersonalDashboardService {
this.featureEventFormatter = featureEventFormatter;
this.privateProjectChecker = privateProjectChecker;
this.accountStore = accountStore;
this.accessStore = accessStore;
}

getPersonalFeatures(userId: number): Promise<PersonalFeature[]> {
Expand Down Expand Up @@ -95,6 +100,7 @@ export class PersonalDashboardService {
}

async getPersonalProjectDetails(
userId: number,
projectId: string,
): Promise<PersonalDashboardProjectDetailsSchema> {
const recentEvents = await this.eventStore.searchEvents(
Expand All @@ -117,11 +123,26 @@ export class PersonalDashboardService {
const owners =
await this.projectOwnersReadModel.getProjectOwners(projectId);

const allRoles = await this.accessStore.getAllProjectRolesForUser(
userId,
projectId,
);

const projectRoles = allRoles
.filter((role) => ['project', 'custom'].includes(role.type))
.map((role) => ({
id: role.id,
name: role.name,
type: role.type as PersonalDashboardProjectDetailsSchema['roles'][number]['type'],
}));

console.log('project roles', projectRoles);

return {
latestEvents: formattedEvents,
onboardingStatus,
owners,
roles: [],
roles: projectRoles,
};
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib/services/access-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import FakeGroupStore from '../../test/fixtures/fake-group-store';
import { FakeAccountStore } from '../../test/fixtures/fake-account-store';
import FakeRoleStore from '../../test/fixtures/fake-role-store';
import FakeEnvironmentStore from '../features/project-environments/fake-environment-store';
import AccessStoreMock from '../../test/fixtures/fake-access-store';
import FakeAccessStore from '../../test/fixtures/fake-access-store';
import { GroupService } from '../services/group-service';
import type { IRole } from '../../lib/types/stores/access-store';
import {
Expand Down Expand Up @@ -271,7 +271,7 @@ test('throws error when trying to delete a project role in use by group', async
const accountStore = new FakeAccountStore();
const roleStore = new FakeRoleStore();
const environmentStore = new FakeEnvironmentStore();
const accessStore = new AccessStoreMock();
const accessStore = new FakeAccessStore();
accessStore.getGroupIdsForRole = groupIdResultOverride;
accessStore.getUserIdsForRole = async (): Promise<number[]> => {
return [];
Expand Down
6 changes: 3 additions & 3 deletions src/test/fixtures/fake-access-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import FakeRoleStore from './fake-role-store';
import type { PermissionRef } from '../../lib/services/access-service';

class AccessStoreMock implements IAccessStore {
export class FakeAccessStore implements IAccessStore {
fakeRolesStore: IRoleStore;

userToRoleMap: Map<number, number> = new Map();
Expand Down Expand Up @@ -327,6 +327,6 @@ class AccessStoreMock implements IAccessStore {
}
}

module.exports = AccessStoreMock;
module.exports = FakeAccessStore;

export default AccessStoreMock;
export default FakeAccessStore;

0 comments on commit 968eb11

Please sign in to comment.