Skip to content

Commit

Permalink
Fix isAdmin check to not depend on oidc (#207)
Browse files Browse the repository at this point in the history
* remove admin check depending on oidc user on autogroups field

* fix admin check on peers view
  • Loading branch information
pascal-fischer authored Jun 14, 2023
1 parent a8190bf commit addd348
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
7 changes: 1 addition & 6 deletions src/components/UserEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,6 @@ const UserEdit = () => {
}
}, [form, user, currentGroups])


const isUserAdmin = (userId: string): boolean => {
return users.find(u => u.id === userId)?.role === "admin"
}

return (
<>
<div style={{ paddingTop: "13px" }}>
Expand Down Expand Up @@ -371,7 +366,7 @@ const UserEdit = () => {
placeholder="Associate groups with the user"
tagRender={blueTagRender}
dropdownRender={dropDownRender}
disabled={oidcUser && !isUserAdmin(oidcUser.sub)}
disabled={!isAdmin}
>
{tagGroups.map((m) => (
<Option key={m}>{optionRender(m)}</Option>
Expand Down
14 changes: 10 additions & 4 deletions src/views/Peers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export const Peers = () => {
const users = useSelector((state: RootState) => state.user.data);
const [addPeerModalOpen, setAddPeerModalOpen] = useState(false);
const { oidcUser } = useOidcUser();
const [isAdmin, setIsAdmin] = useState(false);

const [textToSearch, setTextToSearch] = useState("");
const [optionOnOff, setOptionOnOff] = useState("all");
Expand Down Expand Up @@ -130,9 +131,14 @@ export const Peers = () => {
});
};

const isUserAdmin = (userId: string): boolean => {
return users.find((u) => u.id === userId)?.role === "admin";
};
useEffect(() => {
if(users) {
let currentUser = users.find((user) => user.is_current)
if(currentUser) {
setIsAdmin(currentUser.role === "admin");
}
}
}, [users])

const refresh = () => {
dispatch(
Expand All @@ -153,7 +159,7 @@ export const Peers = () => {
payload: null,
})
);
if (oidcUser && isUserAdmin(oidcUser.sub))
if (isAdmin)
dispatch(
routeActions.getRoutes.request({
getAccessTokenSilently: getTokenSilently,
Expand Down

0 comments on commit addd348

Please sign in to comment.