Hiding the functionalities based on the user

Hello Helical Insight Team,

I am using helical insight version 5.0 GA. I want to hide some options like save, logout and other options when the user is not admin. How can that be done?

Thank you
Netta.

Hello ,
You can achieve this functionality by pasting the below js code in loginbody.jsp file
Location : …\hi\apache-tomcat-9\webapps\hi-ee\WEB-INF\jsp\login
Code :

<script>
    const fetching = () => {
      const stores = new Set();
      const traverse = (element) => {
        let store =
          element?.memoizedState?.element?.props?.store
          || element?.pendingProps?.store
          || element?.stateNode?.store;

        if (store) {
          stores.add(store);
        }

        if (element.child) {
          traverse(element.child);
        }
      };
      const reactRoot = Array.from(document.querySelectorAll("*[id]")).find((el) => el?._reactRootContainer?._internalRoot?.current);
      const internalRoot = reactRoot._reactRootContainer._internalRoot.current;
      traverse(internalRoot);

      let loggedInUserDetails = [...stores][0].getState().app.applicationSettingsData.userData.user
      CheckingUserName(loggedInUserDetails)
      CheckingRole(loggedInUserDetails)

    }
   
   const removingElements = () =>{
     let saveEl = document.querySelector('.hi-navbar-right .ant-list-items li:nth-child(2)')
      let shareEl = document.querySelector('.hi-navbar-right .ant-list-items li:nth-child(3)')
      let exportEl = document.querySelector('.hi-navbar-right .ant-list-items li:nth-child(5)')
      saveEl.style.display = 'none';
      saveEl.style.visibility = 'hidden';
      shareEl.style.display = 'none';
      shareEl.style.visibility = 'hidden';
      exportEl.style.display = 'none';
      exportEl.style.visibility = 'hidden';
    
    let dropDownEl = document.querySelector('.hi-navbar-body .ant-list .ant-spin-nested-loading .ant-list-items .ant-list-item .ant-dropdown-trigger')
      dropDownEl.style.display = 'none';
      dropDownEl.style.visibility = 'hidden';
   }
  
    const CheckingUserName = (loggedInUserDetails) => {
    console.log('hello this is my world')
    let all_el = document.querySelector('.hi-navbar-right .ant-list-items')
    console.log(all_el)
     let loggedInUser = loggedInUserDetails.name;

      if (loggedInUser != 'hiadmin') {
          removingElements();
      }
    }

    const CheckingRole = (loggedInUserDetails) => {
      let isAdmin = loggedInUserDetails.roles.some((role) => role === 'ROLE_ADMIN');
      if (!isAdmin) {
        let lastDropdownMenu = document.querySelector('.ant-list>.ant-spin-nested-loading>.ant-spin-container>.ant-list-items>.ant-list-item>div>.ant-dropdown-trigger>.ant-typography');
        lastDropdownMenu.style.display = 'none';
      }

    }

    function handleHashChange() {
      let hash = window.location.hash;
      if (hash === '#/helical-report') {
        fetching()
      }
    }

    window.addEventListener("hashchange", handleHashChange);

  </script>

Here we are getting the username of the person logged In and hiding save , export , share and logout options if the username is not ‘hiadmin’. You can write this condition on any data of the user like role, organization name, profile etc.

Thank You,
Helical Insight.