ISSUE-720 Fix diff logic for calendar access (#721)
This commit is contained in:
@@ -134,16 +134,39 @@ function CalendarPopover({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
async function updateCalendarInvites(calLink: string) {
|
async function updateCalendarInvites(
|
||||||
|
calLink: string,
|
||||||
|
initialUsers: UserWithAccess[]
|
||||||
|
) {
|
||||||
const normaliseEmail = (u: UserWithAccess) =>
|
const normaliseEmail = (u: UserWithAccess) =>
|
||||||
u.email?.trim().toLowerCase() ?? "";
|
u.email?.trim().toLowerCase() ?? "";
|
||||||
|
|
||||||
|
const initialMap = new Map(
|
||||||
|
initialUsers
|
||||||
|
.filter((u) => !!normaliseEmail(u))
|
||||||
|
.map((u) => [normaliseEmail(u), u])
|
||||||
|
);
|
||||||
|
|
||||||
const currentMap = new Map(
|
const currentMap = new Map(
|
||||||
usersWithAccess
|
usersWithAccess
|
||||||
.filter((u) => !!normaliseEmail(u))
|
.filter((u) => !!normaliseEmail(u))
|
||||||
.map((u) => [normaliseEmail(u), u])
|
.map((u) => [normaliseEmail(u), u])
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const hasChanges =
|
||||||
|
usersWithAccess.some((u) => {
|
||||||
|
const email = normaliseEmail(u);
|
||||||
|
if (!email) return false;
|
||||||
|
const initial = initialMap.get(email);
|
||||||
|
return !initial || initial.accessRight !== u.accessRight;
|
||||||
|
}) ||
|
||||||
|
initialUsers.some(
|
||||||
|
(u) => !!normaliseEmail(u) && !currentMap.has(normaliseEmail(u))
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!hasChanges || !canManageInvites) return;
|
||||||
|
|
||||||
|
// Send all remaining users in `set`: the server treats it as the full list
|
||||||
const set = usersWithAccess
|
const set = usersWithAccess
|
||||||
.filter((u) => !!normaliseEmail(u))
|
.filter((u) => !!normaliseEmail(u))
|
||||||
.map((u) => ({
|
.map((u) => ({
|
||||||
@@ -151,12 +174,10 @@ function CalendarPopover({
|
|||||||
[accessRightToDavProp(u.accessRight)]: true,
|
[accessRightToDavProp(u.accessRight)]: true,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const remove = initialUsersRef.current
|
const remove = initialUsers
|
||||||
.filter((u) => !!normaliseEmail(u) && !currentMap.has(normaliseEmail(u)))
|
.filter((u) => !!normaliseEmail(u) && !currentMap.has(normaliseEmail(u)))
|
||||||
.map((u) => ({ "dav:href": `mailto:${normaliseEmail(u)}` }));
|
.map((u) => ({ "dav:href": `mailto:${normaliseEmail(u)}` }));
|
||||||
|
|
||||||
if ((set.length === 0 && remove.length === 0) || !canManageInvites) return;
|
|
||||||
|
|
||||||
await dispatch(
|
await dispatch(
|
||||||
updateDelegationCalendarAsync({
|
updateDelegationCalendarAsync({
|
||||||
calId: calendar?.id,
|
calId: calendar?.id,
|
||||||
@@ -194,9 +215,12 @@ function CalendarPopover({
|
|||||||
const handleSave = async () => {
|
const handleSave = async () => {
|
||||||
if (!name.trim()) return;
|
if (!name.trim()) return;
|
||||||
if (calendar) {
|
if (calendar) {
|
||||||
|
// Snapshot before any await: handleClose resets the ref immediately after
|
||||||
|
// calling handleSave(), so we must read it synchronously here.
|
||||||
|
const initialUsersSnapshot = [...initialUsersRef.current];
|
||||||
try {
|
try {
|
||||||
await updateCalendar(calendar.id, calendar.link);
|
await updateCalendar(calendar.id, calendar.link);
|
||||||
await updateCalendarInvites(calendar.link);
|
await updateCalendarInvites(calendar.link, initialUsersSnapshot);
|
||||||
} catch {
|
} catch {
|
||||||
setSaveError(t("error.title"));
|
setSaveError(t("error.title"));
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user