Fix: Freigaberollen korrekt filtern und speichern
- Korrigiere normalizeApprovalPermissions: verwende Set für korrekte Deduplizierung - Füge getAvailableApprovalRoles hinzu, um basierend auf der Benutzerrolle die verfügbaren Freigaberollen zu bestimmen: - ADMIN (Vorstand): Vorstand A, Vorstand B - FINANCE (Finanz-AG): Finanz-AG - MEMBER (AG-Mitglied): Keine - Aktualisiere renderApprovalPermissionSelector mit rollenbasierter Filterung - Verhindere Auswahl inkompatibler Kombinationen (z.B. Vorstand A + B zusammen)
This commit is contained in:
@@ -97,6 +97,17 @@ export function canDeleteExpense(
|
||||
return viewerId === creatorId && approvalStatus === "PENDING" && !paidAt && !documentedAt;
|
||||
}
|
||||
|
||||
export function getAvailableApprovalRoles(role: AppRole): ApprovalTypeValue[] {
|
||||
switch (role) {
|
||||
case "ADMIN":
|
||||
return ["CHAIR_A", "CHAIR_B"];
|
||||
case "FINANCE":
|
||||
return ["FINANCE"];
|
||||
case "MEMBER":
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export function normalizeApprovalPermissions(
|
||||
_role: AppRole,
|
||||
approvalPermissions: ApprovalTypeValue[] | null | undefined,
|
||||
@@ -104,9 +115,18 @@ export function normalizeApprovalPermissions(
|
||||
) {
|
||||
const rawPermissions = approvalPermissions ?? (approvalPreference ? [approvalPreference] : []);
|
||||
|
||||
return APPROVAL_FLOW.filter(
|
||||
(approvalType, index) => rawPermissions.includes(approvalType) && rawPermissions.indexOf(approvalType) === index
|
||||
) as ApprovalTypeValue[];
|
||||
// Deduplizierung: behalte jeden Eintrag nur beim ersten Vorkommen
|
||||
const seen = new Set<ApprovalTypeValue>();
|
||||
const unique: ApprovalTypeValue[] = [];
|
||||
for (const perm of rawPermissions) {
|
||||
if (!seen.has(perm)) {
|
||||
seen.add(perm);
|
||||
unique.push(perm);
|
||||
}
|
||||
}
|
||||
|
||||
// Sortiere nach der Reihenfolge in APPROVAL_FLOW
|
||||
return APPROVAL_FLOW.filter((type) => unique.includes(type)) as ApprovalTypeValue[];
|
||||
}
|
||||
|
||||
export function getLegacyApprovalPreference(approvalPermissions: ApprovalTypeValue[]) {
|
||||
|
||||
Reference in New Issue
Block a user