kthcloud / console

kthcloud web console
https://cloud.cbh.kth.se
MIT License
3 stars 3 forks source link

Hide GPU page from users without permissions #297

Closed Phillezi closed 1 month ago

Phillezi commented 1 month ago

Hide GPU page from users without useGpus permission and not admin

242

If a users role.permissions does not include "useGpus" and user is not an admin they will be redirected from the /gpu page if they try to access it, the button doesnt get rendered if the user isn't either an admin or has the useGpus permission.

I used "useGpus" as the permission to check since to my knowledge it is the permission that is present in the role.permissions array if a user should be able to access GPUs. Got it from here and here. Let me know if I misunderstood or if there are more permissions that needs to be checked.

The logic for redirecting a user when they try to access the page is inspired from the way it is handled in the admin page, and looks like this.

  useEffect(() => {
    if (!user) return;
    if (!user.role.permissions.includes("useGpus") && !user.admin) {
      enqueueSnackbar(t("not-permitted-to-gpu-page"), {
        variant: "error",
      });
      navigate("/deploy");
    }
  }, [user]);

user without "useGpus" in their permissions array sees: image user without permissions trying to access it through the url in english image user without permissions trying to access it through the url in swedish image

pierrelefevre commented 1 month ago

Wow, nice work! There is a link to the GPU page in the top menu as well, perhaps that can be hidden too?

Phillezi commented 1 month ago

oh forgot about that, on it