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(hub-common): access is correctly labelled when shared #1708

Merged
merged 6 commits into from
Nov 6, 2024
17 changes: 15 additions & 2 deletions packages/common/src/events/_internal/PropertyMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,15 @@ export class EventPropertyMapper extends PropertyMapper<
const obj = mapStoreToEntity(store, entity, this.mappings);

obj.type = "Event";
obj.access = store.access.toLowerCase() as SettableAccessLevel;
const access = store.access.toLowerCase() as SettableAccessLevel;
if (
access === "private" &&
(store.readGroups.length > 0 || store.editGroups.length > 0)
) {
obj.access = "shared";
} else {
obj.access = access;
}
obj.isCanceled = store.status === EventStatus.CANCELED;
obj.isPlanned = store.status === EventStatus.PLANNED;
obj.isRemoved = store.status === EventStatus.REMOVED;
Expand Down Expand Up @@ -131,7 +139,12 @@ export class EventPropertyMapper extends PropertyMapper<

const obj = mapEntityToStore(clonedEntity, store, this.mappings);

obj.access = clonedEntity.access.toUpperCase() as EventAccess;
const access = clonedEntity.access;
if (access === "shared") {
obj.access = EventAccess.PRIVATE;
} else {
obj.access = access.toUpperCase() as EventAccess;
}

if (clonedEntity.isRemoved) {
obj.status = EventStatus.REMOVED;
Expand Down
40 changes: 39 additions & 1 deletion packages/common/test/events/_internal/PropertyMapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ describe("PropertyMapper", () => {
notifyAttendees: false,
allowRegistration: false,
type: "Event",
access: "private",
access: "shared",
isCanceled: false,
isPlanned: true,
isRemoved: false,
Expand Down Expand Up @@ -634,5 +634,43 @@ describe("PropertyMapper", () => {
editGroups: [],
} as any as IEvent);
});

it("converts a shared IHubEvent to a private Event record", () => {
eventEntity.access = "shared";
expect(propertyMapper.entityToStore(eventEntity, {})).toEqual({
allDay: false,
title: "event title",
creator: { username: "jdoe" },
permission: {
canEdit: true,
canDelete: true,
canSetAccessToOrg: true,
canSetAccessToPrivate: true,
canSetAccessToPublic: true,
canSetStatusToCancelled: true,
canSetStatusToRemoved: true,
},
orgId: "42b",
description: "event description",
id: "31c",
tags: ["tag1"],
categories: ["category1"],
timeZone: "America/New_York",
summary: "event summary",
notifyAttendees: false,
allowRegistration: false,
access: EventAccess.PRIVATE,
status: EventStatus.PLANNED,
attendanceType: [EventAttendanceType.IN_PERSON],
startDate: jasmine.any(String) as unknown as string,
startTime: jasmine.any(String) as unknown as string,
endDate: jasmine.any(String) as unknown as string,
endTime: jasmine.any(String) as unknown as string,
inPersonCapacity: 30,
location: null,
readGroups: [],
editGroups: [],
} as any as IEvent);
});
});
});
Loading