Skip to content

Commit

Permalink
fixed #239 ユーザー一覧を表示する関連項目のリストに、管理者でない場合は自分のみしか表示されない不具合を修正
Browse files Browse the repository at this point in the history
  • Loading branch information
Remicck committed Aug 12, 2021
1 parent 54f9b5e commit fc984e3
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions modules/Users/models/ListView.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,26 +65,39 @@ public function getListViewMassActions($linkParams) {
* Functions returns the query
* @return string
*/
public function getQuery() {
public function getQuery()
{
$listQuery = parent::getQuery();
$searchKey = $this->get('search_key');
$db = PearDatabase::getInstance();
$db = PearDatabase::getInstance();

if(!empty($searchKey)) {
if (!empty($searchKey)) {
$listQueryComponents = explode(" WHERE vtiger_users.status='Active' AND", $listQuery);
$listQuery = implode(' WHERE ', $listQueryComponents);
}
$listQuery .= " AND (vtiger_users.user_name != 'admin' OR vtiger_users.is_owner = 1)";

// Impose non-admin restrictions.
$user = vglobal('current_user');
if(!is_admin($user)){
$listQuery .= " AND vtiger_users.id = ?";
$param[] = $user->id;
if (!is_admin($user)) {
// getAccessibleUsersを使い、inで処理を行う
$listQuery .= " AND vtiger_users.id IN (";
$currentUser = Users_Record_Model::getCurrentUserModel();
$userList = $currentUser->getAccessibleUsers();
$isFirst = true;
foreach ($userList as $id => $name) {
if (!$isFirst) {
$listQuery .= ", ";
}
$listQuery .= "?";
$param[] = $id;
$isFirst = false;
}
$listQuery .= ")";
//TODO: Consider user based on Role-heirarchy
}
return $db->convert2Sql($listQuery, $param);
}
}

/**
* Function to get the list view entries
Expand Down

0 comments on commit fc984e3

Please sign in to comment.