{"id":9286,"date":"2024-10-09T05:29:14","date_gmt":"2024-10-09T05:29:14","guid":{"rendered":"https:\/\/www.infinitivehost.com\/knowledge-base\/?p=9286"},"modified":"2024-10-09T06:32:37","modified_gmt":"2024-10-09T06:32:37","slug":"fix-non-admin-user-listview-access-issue-in-vtiger-crm-7-1-0","status":"publish","type":"post","link":"https:\/\/www.infinitivehost.com\/knowledge-base\/fix-non-admin-user-listview-access-issue-in-vtiger-crm-7-1-0\/","title":{"rendered":"Fix Non-admin User LISTVIEW Access Issue in Vtiger CRM 7.1.0"},"content":{"rendered":"<div class='epvc-post-count'><span class='epvc-eye'><\/span>  <span class=\"epvc-count\"> 1,818<\/span><span class='epvc-label'> Views<\/span><\/div>\n<p class=\"wp-block-paragraph\">To restrict <strong>ListView<\/strong> access for non-admin users in Vtiger CRM 7.1.0 using coding, you can directly modify the core files or create custom code to check the user&#8217;s role and prevent access. Below are the steps to achieve this.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Steps to Restrict ListView Access via Code<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">1. <strong>Locate the Core ListView Code<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong>ListView<\/strong> for most modules in Vtiger CRM is handled by the <code><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">Vtiger_ListView_Model.php<\/mark><\/code> file, which is located in the following path:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">\/modules\/Vtiger\/models\/ListView.php<\/mark><\/code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You will be modifying this file to restrict access based on whether the user is an admin.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">2. <strong>Modify the ListView Code<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">In the <code><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">Vtiger_ListView_Model.php<\/mark><\/code> file, locate the function that handles the <strong>ListView<\/strong> logic (this may vary depending on the module). You need to add a check for whether the user is an admin.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Insert the following code at the beginning of the function responsible for rendering the <strong>ListView<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">$currentUser = Users_Record_Model::getCurrentUserModel();\nif (!$currentUser->isAdminUser()) {\n    \/\/ Prevent access for non-admin users\n    header('Location: index.php?module=Home&amp;view=Index'); \/\/ Redirect to the homepage or any other page\n    exit; \/\/ Stop further execution\n}<\/mark><\/code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This block of code will check if the logged-in user is a non-admin. If they are not an admin, it will redirect them to the home page or any other page of your choice.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">3. <strong>Apply Across Multiple Modules<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">If you want to restrict access to <strong>ListView<\/strong> across all modules (Contacts, Leads, Accounts, etc.), you can either:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Apply the same logic in each module&#8217;s <code><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">ListView.php<\/mark><\/code> file located in <code><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">\/modules\/&lt;ModuleName>\/views\/ListView.php<\/mark><\/code>.<\/li>\n\n\n\n<li>Centralize this restriction by adding the logic in the core <code><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">Vtiger_ListView_Model.php<\/mark><\/code> file, which affects all modules that inherit from this model.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">4. <strong>Testing the Changes<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">After modifying the code:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Log in as a non-admin user<\/strong> and try to access any <strong>ListView<\/strong> (e.g., Contacts or Leads).<\/li>\n\n\n\n<li>The non-admin user should be redirected to the home page or be denied access based on the code you inserted.<\/li>\n<\/ol>\n\n\n\n<h4 class=\"wp-block-heading\">5. <strong>Optional: Show an Error Message<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Instead of a redirect, you could also display an error message to the user if they try to access the <strong>ListView<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">if (!$currentUser->isAdminUser()) {\n    echo \"&lt;h1>Access Denied&lt;\/h1>\";\n    exit;\n}<\/mark><\/code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Conclusion<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>File to Modify<\/strong>: <code><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">\/modules\/Vtiger\/models\/ListView.php<\/mark><\/code> (or similar ListView file for the module).<\/li>\n\n\n\n<li><strong>Add Admin Check<\/strong>: Use <code><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">Users_Record_Model::getCurrentUserModel()->isAdminUser()<\/mark><\/code> to check if the user is an admin.<\/li>\n\n\n\n<li><strong>Redirect Non-Admin Users<\/strong>: Redirect them to another page or show an error message if they attempt to access the <strong>ListView<\/strong>.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">This approach will restrict non-admin users from accessing the <strong>ListView<\/strong> across the CRM, based on your customization.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To limit\u00a0ListView access for all users that are not admins in Vtiger CRM 7.1.0 with the help of programming, you can simply change the essential files or develop custom programs to effortlessly check the role of any user and avoid access. Above are some of the important steps to get this with the <a href=\"https:\/\/www.infinitivehost.com\/managed-vtiger-solutions\"><mark style=\"background-color:#8ed1fc\" class=\"has-inline-color\"><strong>best Vtiger hosting solutions<\/strong><\/mark><\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1,818 Views To restrict ListView access for non-admin users in Vtiger CRM 7.1.0 using coding, you can directly modify the core files or create custom code to check the user&#8217;s role and prevent access. Below are the steps to achieve this. Steps to Restrict ListView Access via Code 1. Locate the Core ListView Code The [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[204],"tags":[],"class_list":["post-9286","post","type-post","status-publish","format-standard","hentry","category-vtiger-solutions"],"_links":{"self":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/9286","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/comments?post=9286"}],"version-history":[{"count":3,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/9286\/revisions"}],"predecessor-version":[{"id":9296,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/9286\/revisions\/9296"}],"wp:attachment":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/media?parent=9286"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/categories?post=9286"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/tags?post=9286"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}