Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix retrieving of profiles under current one #4826

Merged
merged 1 commit into from Oct 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 16 additions & 18 deletions inc/profile.class.php
Expand Up @@ -522,37 +522,35 @@ static function getUnderActiveProfileRestrictCriteria() {
&& (Session::getCurrentInterface() == 'central'
|| in_array($key, self::$helpdesk_rights))) {
$right_subqueries[] = [
'glpi_profilerights.name' => $key,
'RAW' => [
'(' . DBmysql::quoteName('glpi_profilerights.rights') . ' | ' . DBmysql::quoteValue($val) . ')' => $val
'AND' => [
'glpi_profilerights.name' => $key,
'RAW' => [
'(' . DBmysql::quoteName('glpi_profilerights.rights') . ' | ' . DBmysql::quoteValue($val) . ')' => $val
]
]
];
}
}

$dbiterator = new DBmysqlIterator(null);
$dbiterator->buildQuery(
'glpi_profilerights', [
'COUNT' => 'cpt',
'WHERE' => [
'glpi_profilerights.profiles_id' => new \QueryExpression(\DBmysql::quoteName('glpi_profiles.id')),
'OR' => $right_subqueries
]
$sub_query = new QuerySubQuery([
'FROM' => 'glpi_profilerights',
'COUNT' => 'cpt',
'WHERE' => [
'glpi_profilerights.profiles_id' => new \QueryExpression(\DBmysql::quoteName('glpi_profiles.id')),
'OR' => $right_subqueries
]
);
$sub_query = $dbiterator->getSql();
$criteria['RAW'] = [
$sub_query => count($right_subqueries)
];
]);
$criteria[] = new \QueryExpression(count($right_subqueries)." = (".$sub_query->getSubQuery().")");

if (Session::getCurrentInterface() == 'central') {
return [
'OR' => [
$criteria,
'glpi_profiles.interface' => 'helpdesk'
'glpi_profiles.interface' => 'helpdesk',
'AND' => [$criteria]
]
];
}

return $criteria;
}

Expand Down
20 changes: 20 additions & 0 deletions tests/functionnal/Profile.php
Expand Up @@ -117,4 +117,24 @@ public function testHaveUserRight(array $user, array $rightset) {
);
}
}

/**
* We try to login with tech profile and check if we can get a super-admin profile
*/
public function testGetUnderActiveProfileRestrictCriteria() {
global $DB;

$this->login('tech', 'tech');

$iterator = $DB->request([
'FROM' => \Profile::getTable(),
'WHERE' => \Profile::getUnderActiveProfileRestrictCriteria(),
'ORDER' => 'name'
]);

foreach ($iterator as $profile_found) {
$this->array($profile_found)->string['name']->isNotEqualTo('Super-Admin');
$this->array($profile_found)->string['name']->isNotEqualTo('Admin');
}
}
}