Skip to content

Commit

Permalink
added role check for the current user in getActivePolicies
Browse files Browse the repository at this point in the history
  • Loading branch information
FitseTLT committed Dec 4, 2024
1 parent 1462048 commit ae7dd9e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ Onyx.connect({
* Filter out the active policies, which will exclude policies with pending deletion
* These are policies that we can use to create reports with in NewDot.
*/
function getActivePolicies(policies: OnyxCollection<Policy> | null): Policy[] {
function getActivePolicies(policies: OnyxCollection<Policy> | null, currentUserLogin: string | undefined): Policy[] {
return Object.values(policies ?? {}).filter<Policy>(
(policy): policy is Policy => !!policy && policy.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && !!policy.name && !!policy.id,
(policy): policy is Policy =>
!!policy && policy.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && !!policy.name && !!policy.id && !!getPolicyRole(policy, currentUserLogin),
);
}
/**
Expand Down Expand Up @@ -636,7 +637,7 @@ function getPolicy(policyID: string | undefined): OnyxEntry<Policy> {

/** Return active policies where current user is an admin */
function getActiveAdminWorkspaces(policies: OnyxCollection<Policy> | null, currentUserLogin: string | undefined): Policy[] {
const activePolicies = getActivePolicies(policies);
const activePolicies = getActivePolicies(policies, currentUserLogin);
return activePolicies.filter((policy) => shouldShowPolicy(policy, NetworkStore.isOffline(), currentUserLogin) && isPolicyAdmin(policy, currentUserLogin));
}

Expand All @@ -652,7 +653,7 @@ function canSendInvoice(policies: OnyxCollection<Policy> | null, currentUserLogi
}

function hasWorkspaceWithInvoices(currentUserLogin: string | undefined): boolean {
const activePolicies = getActivePolicies(allPolicies);
const activePolicies = getActivePolicies(allPolicies, currentUserLogin);
return activePolicies.some((policy) => shouldShowPolicy(policy, NetworkStore.isOffline(), currentUserLogin) && policy.areInvoicesEnabled);
}

Expand Down
4 changes: 2 additions & 2 deletions src/pages/workspace/WorkspaceNewRoomPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ function WorkspaceNewRoomPage() {

const workspaceOptions = useMemo(
() =>
PolicyUtils.getActivePolicies(policies)
PolicyUtils.getActivePolicies(policies, session?.email)
?.filter((policy) => policy.type !== CONST.POLICY.TYPE.PERSONAL)
.map((policy) => ({
label: policy.name,
value: policy.id,
}))
.sort((a, b) => localeCompare(a.label, b.label)) ?? [],
[policies],
[policies, session?.email],
);
const [policyID, setPolicyID] = useState<string>(() => {
if (!!activeWorkspaceOrDefaultID && workspaceOptions.some((option) => option.value === activeWorkspaceOrDefaultID)) {
Expand Down

0 comments on commit ae7dd9e

Please sign in to comment.