Introduction
We recently had a requirement in Power Apps Partner Portal where the client specifically wanted Portal search option you see in the navigation bar to be seen and accessible ONLY for users who logs into the portal. With this, non-authenticated users will have no unauthorized access to CRM data visible in portal even via search.
As most of you all might know, the site setting titled “Search/Enabled” and setting the value as “false” COMPLETELY hide the Portal search option irrespective of whether you have logged into the portal or not. So that was not an option for us since we wanted to show the search option once the user has logged into the portal.
So, the next option we had in our mind was the typical way of using Web Page Access Control Rules. We did try adding the rules to the already existing system created web page “Search” as shown below:
“Search Page-Admin Access” was created for users with Administrator’s web role and the other one “Search Page-Non Admin Access” was created for users with Authenticated Users web role. Usually, this would make the page invisible if the user is not logged in. But in our case, though the search icon (as seen in the screenshot below) was still visible, but because we added the web page access control rules, when we tried to search something it automatically redirected to sign in page. This would ensure that you cannot see search results without logging to the portal.
Though this was half serving the purpose (i.e., users who have not logged in to the portal can’t use search functionality properly), our main motive of making the Search option NOT visible to whoever did not login to the portal was still an issue.
It’s in that situation after some research, we figured a solution for this problem.
- Go to the Web Templates section and click on the template named “Header”.
- Now search for “search” in the template as seen below:
- Now add the below code:
{% if user %}
Just above the already present line written below:
{% assign search_enabled = settings[‘Search/Enabled’] | boolean | default:true %}
- And also add the below code:
{% endif %}
Just above the already present line written below:
<li class=”divider-vertical” aria-hidden=”true”></li>
The whole code changes will look like this:
Basically, what we did is we are checking if any user details found for logged in users, then only display the search icon or else not. And this is how it’s reflected in portal as shown below and the search icon is hidden!!
And the search is visible once the user logs in to the portal as shown below:
Conclusion:
In this way, by editing the header template as explained above we can hide the portal search in the navigation bar from users who have not logged in to the portal.