Ejemplo n.º 1
0
/** Function to check if the currently logged in user is permitted to perform the specified action
 * @param $module -- Module Name:: Type varchar
 * @param $actionname -- Action Name:: Type varchar
 * @param $recordid -- Record Id:: Type integer
 * @returns yes or no. If Yes means this action is allowed for the currently logged in user. If no means this action is not allowed for the currently logged in user
 *
 */
function isPermitted($module, $actionname, $record_id = '')
{
    $log = vglobal('log');
    $log->debug("Entering isPermitted(" . $module . "," . $actionname . "," . $record_id . ") method ...");
    $adb = PearDatabase::getInstance();
    $current_user = vglobal('current_user');
    global $seclog;
    require 'user_privileges/user_privileges_' . $current_user->id . '.php';
    require 'user_privileges/sharing_privileges_' . $current_user->id . '.php';
    $permission = 'no';
    if (($module == 'Users' || $module == 'Home' || $module == 'uploads') && $_REQUEST['parenttab'] != 'Settings') {
        //These modules dont have security right now
        $permission = 'yes';
        $log->debug("Exiting isPermitted method ...");
        return $permission;
    }
    //Checking the Access for the Settings Module
    if ($module == 'Settings' || $module == 'Administration' || $module == 'System' || $_REQUEST['parenttab'] == 'Settings') {
        if (!$is_admin) {
            $permission = 'no';
        } else {
            $permission = 'yes';
        }
        $log->debug("Exiting isPermitted method ...");
        return $permission;
    }
    //Retreiving the Tabid and Action Id
    $tabid = getTabid($module);
    $actionid = getActionid($actionname);
    $checkModule = $module;
    if ($checkModule == 'Events') {
        $checkModule = 'Calendar';
    }
    if (vtlib_isModuleActive($checkModule)) {
        //Checking whether the user is admin
        if ($is_admin) {
            $permission = 'yes';
            $log->debug("Exiting isPermitted method ...");
            return $permission;
        }
        //If no actionid, then allow action is vtiger_tab permission is available
        if ($actionid === '') {
            if ($profileTabsPermission[$tabid] == 0) {
                $permission = 'yes';
                $log->debug("Exiting isPermitted method ...");
            } else {
                $permission = 'no';
            }
            return $permission;
        }
        $action = getActionname($actionid);
        //Checking for view all permission
        if ($profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) {
            if ($actionid == 3 || $actionid == 4) {
                $permission = 'yes';
                $log->debug("Exiting isPermitted method ...");
                return $permission;
            }
        }
        //Checking for edit all permission
        if ($profileGlobalPermission[2] == 0) {
            if ($actionid == 3 || $actionid == 4 || $actionid == 0 || $actionid == 1) {
                $permission = 'yes';
                $log->debug("Exiting isPermitted method ...");
                return $permission;
            }
        }
        //Checking for vtiger_tab permission
        if ($profileTabsPermission[$tabid] != 0) {
            $permission = 'no';
            $log->debug("Exiting isPermitted method ...");
            return $permission;
        }
        //Checking for Action Permission
        if (strlen($profileActionPermission[$tabid][$actionid]) < 1 && $profileActionPermission[$tabid][$actionid] == '') {
            $permission = 'yes';
            $log->debug("Exiting isPermitted method ...");
            return $permission;
        }
        if ($profileActionPermission[$tabid][$actionid] != 0 && $profileActionPermission[$tabid][$actionid] != '') {
            $permission = 'no';
            $log->debug("Exiting isPermitted method ...");
            return $permission;
        }
        //Checking and returning true if recorid is null
        if ($record_id == '') {
            $permission = 'yes';
            $log->debug("Exiting isPermitted method ...");
            return $permission;
        }
        //If modules is Products,Vendors,Faq,PriceBook then no sharing
        if ($record_id != '') {
            if (getTabOwnedBy($module) == 1) {
                $permission = 'yes';
                $log->debug("Exiting isPermitted method ...");
                return $permission;
            }
        }
        //Retreiving the RecordOwnerId
        $recOwnType = '';
        $recOwnId = '';
        $recordOwnerArr = getRecordOwnerId($record_id);
        $shownerids = Vtiger_SharedOwner_UIType::getSharedOwners($record_id, $module);
        foreach ($recordOwnerArr as $type => $id) {
            $recOwnType = $type;
            $recOwnId = $id;
        }
        //Retreiving the default Organisation sharing Access
        $others_permission_id = $defaultOrgSharingPermission[$tabid];
        if (in_array($current_user->id, $shownerids) || count(array_intersect($shownerids, $current_user_groups)) > 0) {
            $permission = 'yes';
            $log->debug('Exiting isPermitted method ... - Shared Owner');
            return $permission;
        }
        if ($recOwnType == 'Users') {
            //Checking if the Record Owner is the current User
            if ($current_user->id == $recOwnId) {
                $permission = 'yes';
                $log->debug('Exiting isPermitted method ...');
                return $permission;
            }
            //Checking if the Record Owner is the Subordinate User
            foreach ($subordinate_roles_users as $roleid => $userids) {
                if (in_array($recOwnId, $userids)) {
                    $permission = 'yes';
                    $log->debug('Exiting isPermitted method ...');
                    return $permission;
                }
            }
        } elseif ($recOwnType == 'Groups') {
            //Checking if the record owner is the current user's group
            if (in_array($recOwnId, $current_user_groups)) {
                $permission = 'yes';
                $log->debug("Exiting isPermitted method ...");
                return $permission;
            }
        }
        $role = getRoleInformation($current_user->roleid);
        if (($actionid == 3 || $actionid == 4) && $role['previewrelatedrecord'] != 0 || ($actionid == 0 || $actionid == 1) && $role['editrelatedrecord'] != 0) {
            $parentRecord = Users_Privileges_Model::getParentRecord($record_id, $module, $role['previewrelatedrecord']);
            if ($parentRecord) {
                $recordMetaData = Vtiger_Functions::getCRMRecordMetadata($parentRecord);
                if ($role['permissionsrelatedfield'] == 0) {
                    $relatedPermission = $current_user->id == $recordMetaData['smownerid'];
                } else {
                    if ($role['permissionsrelatedfield'] == 1) {
                        $relatedPermission = in_array($current_user->id, Vtiger_SharedOwner_UIType::getSharedOwners($parentRecord, $recordMetaData['setype']));
                    } else {
                        if ($role['permissionsrelatedfield'] == 2) {
                            $relatedPermission = $current_user->id == $recordMetaData['smownerid'] || in_array($current_user->id, Vtiger_SharedOwner_UIType::getSharedOwners($parentRecord, $recordMetaData['setype']));
                        }
                    }
                }
                if ($relatedPermission) {
                    $permission = 'yes';
                    $log->debug('Exiting isPermitted method ... - Parent Record Owner');
                    return $permission;
                }
            }
        }
        //Checking for Default Org Sharing permission
        if ($others_permission_id == 0) {
            if ($actionid == 1 || $actionid == 0) {
                $permission = isReadWritePermittedBySharing($module, $tabid, $actionid, $record_id);
                $log->debug("Exiting isPermitted method ...");
                return $permission;
            } elseif ($actionid == 2) {
                $permission = 'no';
                $log->debug("Exiting isPermitted method ...");
                return $permission;
            } else {
                $permission = 'yes';
                $log->debug("Exiting isPermitted method ...");
                return $permission;
            }
        } elseif ($others_permission_id == 1) {
            if ($actionid == 2) {
                $permission = 'no';
                $log->debug("Exiting isPermitted method ...");
                return $permission;
            } else {
                $permission = 'yes';
                $log->debug("Exiting isPermitted method ...");
                return $permission;
            }
        } elseif ($others_permission_id == 2) {
            $permission = 'yes';
            $log->debug("Exiting isPermitted method ...");
            return $permission;
        } elseif ($others_permission_id == 3) {
            if ($actionid == 3 || $actionid == 4) {
                $permission = isReadPermittedBySharing($module, $tabid, $actionid, $record_id);
                $log->debug("Exiting isPermitted method ...");
                return $permission;
            } elseif ($actionid == 0 || $actionid == 1) {
                if ($module == 'Calendar') {
                    $permission = 'no';
                } else {
                    $permission = isReadWritePermittedBySharing($module, $tabid, $actionid, $record_id);
                }
                $log->debug("Exiting isPermitted method ...");
                return $permission;
            } elseif ($actionid == 2) {
                $permission = 'no';
                return $permission;
            } else {
                $permission = 'yes';
                $log->debug("Exiting isPermitted method ...");
                return $permission;
            }
        } else {
            $permission = 'yes';
        }
    } else {
        $permission = 'no';
    }
    $log->debug("Exiting isPermitted method ...");
    return $permission;
}
Ejemplo n.º 2
0
 function getUserAccessConditionsQuerySR($module, $current_user = false, $relatedRecord = false)
 {
     if ($current_user == false) {
         $current_user = vglobal('current_user');
     }
     require 'user_privileges/user_privileges_' . $current_user->id . '.php';
     require 'user_privileges/sharing_privileges_' . $current_user->id . '.php';
     global $shared_owners;
     $is_admin = is_admin($current_user);
     $sharedParameter = $securityParameter = '';
     $query = '';
     $tabId = getTabid($module);
     if ($relatedRecord) {
         $role = getRoleInformation($current_user->roleid);
         if ($role['listrelatedrecord'] != 0) {
             $rparentRecord = Users_Privileges_Model::getParentRecord($relatedRecord, false, $role['listrelatedrecord']);
             if ($rparentRecord) {
                 $relatedRecord = $rparentRecord;
             }
             $recordMetaData = Vtiger_Functions::getCRMRecordMetadata($relatedRecord);
             $recordPermission = Users_Privileges_Model::isPermitted($recordMetaData['setype'], 'DetailView', $relatedRecord);
             if (!$recordPermission) {
                 throw new AppException('LBL_PERMISSION_DENIED');
             }
             if ($recordMetaData['smownerid'] == $current_user->id) {
                 return '';
             }
         }
     }
     if ($is_admin == false && $profileGlobalPermission[1] == 1 && $profileGlobalPermission[2] == 1 && $defaultOrgSharingPermission[$tabId] == 3) {
         $securityParameter = $this->getUserAccessConditionsQuery($module, $current_user);
         $shownerid = array_merge([$current_user->id], $current_user_groups);
         $sharedParameter .= 'vtiger_crmentity.crmid IN (SELECT DISTINCT crmid FROM u_yf_crmentity_showners WHERE userid IN (' . implode(',', $shownerid) . '))';
     }
     if ($shared_owners == true) {
         if ($securityParameter != '') {
             $query .= " AND ( ({$securityParameter}) OR ({$sharedParameter}) )";
         } elseif ($sharedParameter != '') {
             $query .= ' AND (' . $sharedParameter . ')';
         }
     } else {
         $query .= $securityParameter;
     }
     return $query;
 }