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’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 ListView for most modules in Vtiger CRM is handled by the Vtiger_ListView_Model.php
file, which is located in the following path:
/modules/Vtiger/models/ListView.php
You will be modifying this file to restrict access based on whether the user is an admin.
2. Modify the ListView Code
In the Vtiger_ListView_Model.php
file, locate the function that handles the ListView logic (this may vary depending on the module). You need to add a check for whether the user is an admin.
Insert the following code at the beginning of the function responsible for rendering the ListView:
$currentUser = Users_Record_Model::getCurrentUserModel();
if (!$currentUser->isAdminUser()) {
// Prevent access for non-admin users
header('Location: index.php?module=Home&view=Index'); // Redirect to the homepage or any other page
exit; // Stop further execution
}
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.
3. Apply Across Multiple Modules
If you want to restrict access to ListView across all modules (Contacts, Leads, Accounts, etc.), you can either:
- Apply the same logic in each module’s
ListView.php
file located in/modules/<ModuleName>/views/ListView.php
. - Centralize this restriction by adding the logic in the core
Vtiger_ListView_Model.php
file, which affects all modules that inherit from this model.
4. Testing the Changes
After modifying the code:
- Log in as a non-admin user and try to access any ListView (e.g., Contacts or Leads).
- The non-admin user should be redirected to the home page or be denied access based on the code you inserted.
5. Optional: Show an Error Message
Instead of a redirect, you could also display an error message to the user if they try to access the ListView:
if (!$currentUser->isAdminUser()) {
echo "<h1>Access Denied</h1>";
exit;
}
Conclusion
- File to Modify:
/modules/Vtiger/models/ListView.php
(or similar ListView file for the module). - Add Admin Check: Use
Users_Record_Model::getCurrentUserModel()->isAdminUser()
to check if the user is an admin. - Redirect Non-Admin Users: Redirect them to another page or show an error message if they attempt to access the ListView.
This approach will restrict non-admin users from accessing the ListView across the CRM, based on your customization.
To limit ListView 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 best Vtiger hosting solutions.