Skip to content

Commit 39defe5

Browse files
committed
Filter audit org dropdown by auditable orgs
1 parent 720b7a5 commit 39defe5

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

site/src/pages/AuditPage/AuditFilter.tsx

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -211,19 +211,36 @@ export const useOrganizationsFilterMenu = ({
211211
return null;
212212
},
213213
getOptions: async () => {
214-
const organizationsRes = await API.getOrganizations();
215-
return organizationsRes.map<SelectFilterOption>((organization) => ({
216-
label: organization.display_name || organization.name,
217-
value: organization.name,
218-
startIcon: (
219-
<UserAvatar
220-
key={organization.id}
221-
size="xs"
222-
username={organization.display_name || organization.name}
223-
avatarURL={organization.icon}
224-
/>
214+
// Only show the organizations for which you can view audit logs.
215+
const organizations = await API.getOrganizations();
216+
const permissions = await API.checkAuthorization({
217+
checks: Object.fromEntries(
218+
organizations.map((organization) => [
219+
organization.id,
220+
{
221+
object: {
222+
resource_type: "audit_log",
223+
organization_id: organization.id,
224+
},
225+
action: "read",
226+
},
227+
]),
225228
),
226-
}));
229+
});
230+
return organizations
231+
.filter((organization) => permissions[organization.id])
232+
.map<SelectFilterOption>((organization) => ({
233+
label: organization.display_name || organization.name,
234+
value: organization.name,
235+
startIcon: (
236+
<UserAvatar
237+
key={organization.id}
238+
size="xs"
239+
username={organization.display_name || organization.name}
240+
avatarURL={organization.icon}
241+
/>
242+
),
243+
}));
227244
},
228245
});
229246
};

0 commit comments

Comments
 (0)