Skip to content
This repository has been archived by the owner on Aug 9, 2021. It is now read-only.

Commit

Permalink
Merge branch 'feature/better_reenrollment' of github.com-btry:btry/gl…
Browse files Browse the repository at this point in the history
…pi-plugin into feature/better_reenrollment

Signed-off-by: Thierry Bugier <[email protected]>
  • Loading branch information
btry committed Oct 19, 2018
2 parents 037f589 + 63847dc commit 5e06e95
Show file tree
Hide file tree
Showing 27 changed files with 193 additions and 61 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ env:
- AFTER_SUCCESS_BRANCH=9.3/bugfixes
- secure: Y9sG3lZ3Fn3t5BXvcMJQxWsdSUVQgF4M08E6oouYrRc95HEj3ZwZOqp6Df58u8CQFA0EKJyvCBLn8UicvHGMKAD0RwGLBdSP4Ji9gJRZkyMZi79awSshdva/c8dqVQrRd4asuTNQfcagVJpNDnY8sYusw504JUilK3vFVp+39nNZUkcvT69NGVIlXzgHTYinBkVuqDhf5eVtcLcaESLEshrg+5ZERdm+0KifdJVREzhicJxofnmTl/wBsIP7XiQqspljf2/SxLqreGmWXYXUfqIwIOVtsd9fkZChQCz8USC7P427tH6styRDYuMCtvA9b/T/XacSdKFbuDezff3NbIM3b5BebDyCrOK5MGSOdRUY5RuyZN4R5LjePUE++9QNCUPeDSkfb23v0VfuqXIRAxfdtik517GzFy6O7/e6FU1msVZlGQED7Uek9nqnupj+0lIq+99Jcm1UCNJu1NTL2Tv80XXqySaxyE4Sedq/FiYAsy1bo2cg2367I2b4FhFXaJCKkFHcdjHXAeurkRy/brSPhBNoOO5/GA3RepUErgly4P8TLZqHNZv8rgMUoQ88sdwDyXG7dY4UwWiTlCkxMBTqBqJanlTMA9zn2bYyMDioTGnA7+VYAA8cddjFOMVrmmuFJ+YV2x1+5B5qd+Wt8RPwcPQDyqaiN5amb1HGeMA=
matrix:
- GLPI_BRANCH=9.3.0 FI_BRANCH=glpi9.3+1.0
- GLPI_BRANCH=9.3/bugfixes FI_BRANCH=glpi9.3+1.0
- GLPI_BRANCH=9.3.0 FI_BRANCH=glpi9.3+1.1
- GLPI_BRANCH=9.3/bugfixes FI_BRANCH=glpi9.3
- GLPI_BRANCH=master FI_BRANCH=master

php:
Expand Down
9 changes: 1 addition & 8 deletions inc/agent.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,14 +397,7 @@ public function canUpdateItem() {
return false;
}

// the active profile is guest user, then check the user is
// owner of the item's computer
$computer = $this->getComputer();
if ($computer === null) {
return false;
}

return $_SESSION['glpiID'] == $computer->getField('users_id');
return $_SESSION['glpiID'] == $this->fields[User::getForeignKeyField()];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion inc/policyboolean.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function integrityCheck($value, $itemtype, $itemId) {
* @param integer $itemId
* @return array|bool
*/
public function getMqttMessage($value, $itemtype, $itemId) {
public function getBrokerMessage($value, $itemtype, $itemId) {
if (!$this->integrityCheck($value, $itemtype, $itemId)) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion inc/policydeployapplication.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function integrityCheck($value, $itemtype, $itemId) {
* @param integer $itemId
* @return array|boolean
*/
public function getMqttMessage($value, $itemtype, $itemId) {
public function getBrokerMessage($value, $itemtype, $itemId) {
$decodedValue = json_decode($value, JSON_OBJECT_AS_ARRAY);
if (!$this->integrityCheck($decodedValue, $itemtype, $itemId)) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion inc/policydeployfile.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function integrityCheck($value, $itemtype, $itemId) {
* @param integer $itemId
* @return array|bool
*/
public function getMqttMessage($value, $itemtype, $itemId) {
public function getBrokerMessage($value, $itemtype, $itemId) {
$decodedValue = json_decode($value, JSON_OBJECT_AS_ARRAY);
if (!$this->integrityCheck($decodedValue, $itemtype, $itemId)) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion inc/policydropdown.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function integrityCheck($value, $itemtype, $itemId) {
* @param integer $itemId
* @return array|bool
*/
public function getMqttMessage($value, $itemtype, $itemId) {
public function getBrokerMessage($value, $itemtype, $itemId) {
if (!$this->integrityCheck($value, $itemtype, $itemId)) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion inc/policyinteger.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function integrityCheck($value, $itemtype, $itemId) {
* @param integer $itemId
* @return array|bool
*/
public function getMqttMessage($value, $itemtype, $itemId) {
public function getBrokerMessage($value, $itemtype, $itemId) {
if (!$this->integrityCheck($value, $itemtype, $itemId)) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion inc/policyinterface.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function conflictCheck($value, $itemtype, $itemId, PluginFlyvemdmNotifiab
* @param integer $itemId the id of an item
* @return array
*/
public function getMqttMessage($value, $itemtype, $itemId);
public function getBrokerMessage($value, $itemtype, $itemId);

/**
* Translate type_data field
Expand Down
2 changes: 1 addition & 1 deletion inc/policyremoveapplication.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function unicityCheck($value, $itemtype, $itemId, PluginFlyvemdmNotifiabl
* @param integer $itemId
* @return array|boolean
*/
public function getMqttMessage($value, $itemtype, $itemId) {
public function getBrokerMessage($value, $itemtype, $itemId) {
if (!$this->integrityCheck($value, $itemtype, $itemId)) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion inc/policyremovefile.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function unicityCheck($value, $itemtype, $itemId, PluginFlyvemdmNotifiabl
* @param integer $itemId
* @return array|boolean
*/
public function getMqttMessage($value, $itemtype, $itemId) {
public function getBrokerMessage($value, $itemtype, $itemId) {
if (! $this->integrityCheck($value, $itemtype, $itemId)) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion inc/policystring.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function __construct(PluginFlyvemdmPolicy $policy) {
* @param integer $itemId
* @return array|bool
*/
public function getMqttMessage($value, $itemtype, $itemId) {
public function getBrokerMessage($value, $itemtype, $itemId) {
if (!$this->integrityCheck($value, $itemtype, $itemId)) {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions inc/task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ public function publishPolicy(PluginFlyvemdmNotifiableInterface $item) {
$policy->getFromDB($this->fields[$policyFk]);
$policyName = $policy->getField('symbol');
$taskId = $this->getID();
$policyMessage = $appliedPolicy->getMqttMessage(
$policyMessage = $appliedPolicy->getBrokerMessage(
$this->fields['value'],
$this->fields['itemtype'],
$this->fields['items_id']
Expand Down Expand Up @@ -463,7 +463,7 @@ protected function buildMqttMessage($policiesToApply) {
$groupToEncode = [];
foreach ($policiesToApply as $policyToApply) {
$policy = $policyToApply['policyData'];
$policyMessage = $policy->getMqttMessage(
$policyMessage = $policy->getBrokerMessage(
$policyToApply['value'],
$policyToApply['itemtype'],
$policyToApply['items_id']
Expand Down
6 changes: 3 additions & 3 deletions install/install.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public function isPluginInstalled() {
global $DB;

// Check tables of the plugin between 1.1 and 2.0 releases
$result = $DB->query("SHOW TABLES LIKE 'glpi_plugin_flyvemdm_%'");
$result = $DB->query("SHOW TABLES LIKE 'glpi_plugin_flyvemdm\\_%'");
if ($result) {
if ($DB->numrows($result) > 0) {
return true;
Expand Down Expand Up @@ -272,7 +272,7 @@ protected function createGuestProfileAccess() {
Config::setConfigurationValues('flyvemdm', ['guest_profiles_id' => $profileId]);
$profileRight = new ProfileRight();
$profileRight->updateProfileRights($profileId, [
PluginFlyvemdmAgent::$rightname => READ | CREATE,
PluginFlyvemdmAgent::$rightname => READ | CREATE | UPDATE,
PluginFlyvemdmFile::$rightname => READ,
PluginFlyvemdmPackage::$rightname => READ,
]);
Expand Down Expand Up @@ -440,7 +440,7 @@ public function createNotificationTargetInvitation() {
'language' => '',
'subject' => addcslashes($data['subject'], "'\""),
'content_text' => addcslashes($data['content_text'], "'\""),
'content_html' => addcslashes(htmlentities($contentHtml), "'\""),
'content_html' => addcslashes(htmlentities($contentHtml, ENT_NOQUOTES | ENT_HTML401), "'\""),
]);

// Create the notification
Expand Down
2 changes: 1 addition & 1 deletion install/upgrade_to_2_0.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ public function upgrade(Migration $migration) {
]);
$policyFactory = new PluginFlyvemdmPolicyFactory();
$appliedPolicy = $policyFactory->createFromDBByID($row['plugin_flyvemdm_policies_id']);
$policyMessage = $appliedPolicy->getMqttMessage(
$policyMessage = $appliedPolicy->getBrokerMessage(
$row['value'],
$row['itemtype'],
$row['items_id']
Expand Down
13 changes: 9 additions & 4 deletions tests/before_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,21 @@ composer install --no-dev --no-interaction
mkdir plugins/fusioninventory && git clone --depth=35 $FI_SOURCE -b $FI_BRANCH plugins/fusioninventory
IFS=/ read -a repo <<< $TRAVIS_REPO_SLUG
mv ../${repo[1]} plugins/flyvemdm

# patch settings
PATCH_ARGS="-p1 -N --batch"

# patch Fusion Inventory when needed
cd plugins/fusioninventory
if [[ $FI_BRANCH == "glpi9.2+1.0" ]] ; then patch -p1 --batch < ../flyvemdm/tests/patches/fi-fix-obsolete-query.patch; fi
if [[ $FI_BRANCH == "master" ]] ; then patch -p1 --batch < ../flyvemdm/tests/patches/fi-raise-max-version.patch; fi
if [[ $FI_BRANCH == "master" ]] ; then patch $PATCH_ARGS < ../flyvemdm/tests/patches/fusioninventory/fi-raise-max-version.patch; fi
if [[ $FI_BRANCH == "master" ]] ; then patch $PATCH_ARGS < ../flyvemdm/tests/patches/fusioninventory/compat-glpi-9-3-2.diff; fi
if [[ $FI_BRANCH == "glpi9.3" ]] ; then patch $PATCH_ARGS < ../flyvemdm/tests/patches/fusioninventory/compat-glpi-9-3-2.diff; fi
cd ../..

# patch GLPI when needed
if [[ $GLPI_BRANCH == "9.2.1" ]] ; then patch -p1 --batch < plugins/flyvemdm/tests/patches/10f8dabfc5e20bb5a4e7d4ba4b93706871156a8a.diff; fi

# prepare plugin to test
cd plugins/flyvemdm
if [[ $GLPI_BRANCH == "master" ]] ; then patch -p1 --batch < tests/patches/glpi-allow-test-on-master-branch.patch; fi
if [[ $GLPI_BRANCH == "master" ]] ; then patch $PATCH_ARGS < tests/patches/allow-test-on-master-branch.patch; fi
composer install --no-interaction

142 changes: 142 additions & 0 deletions tests/patches/fusioninventory/compat-glpi-9-3-2.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
diff --git a/inc/collectrule.class.php b/inc/collectrule.class.php
index 55e700c0f..9df0c229b 100644
--- a/inc/collectrule.class.php
+++ b/inc/collectrule.class.php
@@ -115,7 +115,7 @@ class PluginFusioninventoryCollectRule extends Rule {
* @param array $params
* @return array
*/
- function executeActions($output, $params) {
+ function executeActions($output, $params, array $input = []) {

PluginFusioninventoryToolbox::logIfExtradebug(
"pluginFusioninventory-rules-collect",
@@ -181,7 +181,7 @@ class PluginFusioninventoryCollectRule extends Rule {
default:
//plugins actions
$executeaction = clone $this;
- $output = $executeaction->executePluginsActions($action, $output, $params);
+ $output = $executeaction->executePluginsActions($action, $output, $params, $input);
break;

}
diff --git a/inc/formatconvert.class.php b/inc/formatconvert.class.php
index 506cb2aec..59ad31d96 100644
--- a/inc/formatconvert.class.php
+++ b/inc/formatconvert.class.php
@@ -1598,7 +1598,8 @@ class PluginFusioninventoryFormatconvert {
'VERSION' => 'version',
'COMMENTS' => 'comment',
'INSTALLDATE' => 'date_install',
- 'SYSTEM_CATEGORY' => '_system_category']);
+ 'SYSTEM_CATEGORY' => '_system_category',
+ 'OPERATIONG_SYSTEM' => 'operatingsystems_id']);
if (!isset($array_tmp['name'])
|| $array_tmp['name'] == '') {
if (isset($a_softwares['GUID'])
@@ -1632,11 +1633,13 @@ class PluginFusioninventoryFormatconvert {
//for software dictionnary
if ($nb_RuleDictionnarySoftware > 0) {
$rule_input = [
- "name" => $array_tmp['name'],
- "manufacturer" => $array_tmp['manufacturers_id'],
- "old_version" => $array_tmp['version'],
- "entities_id" => $entities_id_software,
- "_system_category" => $array_tmp['_system_category']
+ "name" => $array_tmp['name'],
+ "manufacturer" => $array_tmp['manufacturers_id'],
+ "old_version" => $array_tmp['version'],
+ "entities_id" => $entities_id_software,
+ "operatingsystems_id" => $array_tmp['operatingsystems_id'],
+ "_system_category" => $array_tmp['_system_category'],
+ "device_id" => isset($a_inventory['Computer']['device_id']) ? $a_inventory['Computer']['device_id'] : 0,
];
$res_rule = $rulecollection->processAllRules($rule_input);
}
diff --git a/inc/inventorycomputerinventory.class.php b/inc/inventorycomputerinventory.class.php
index 8b0a1186c..aae4783a3 100644
--- a/inc/inventorycomputerinventory.class.php
+++ b/inc/inventorycomputerinventory.class.php
@@ -474,6 +474,7 @@ class PluginFusioninventoryInventoryComputerInventory {
$a_computerinventory,
$items_id);
}
+ $a_computerinventory['Computer']['device_id'] = $this->device_id;
$a_computerinventory = $pfFormatconvert->computerSoftwareTransformation(
$a_computerinventory,
$entities_id);
@@ -581,7 +582,7 @@ class PluginFusioninventoryInventoryComputerInventory {
'computer');
}
} else if ($itemtype == 'PluginFusioninventoryUnmanaged') {
-
+ $a_computerinventory['Computer']['device_id'] = $this->device_id;
$a_computerinventory = $pfFormatconvert->computerSoftwareTransformation(
$a_computerinventory,
$entities_id);
diff --git a/inc/inventoryruleentity.class.php b/inc/inventoryruleentity.class.php
index c4e57a977..a13e1ad7f 100644
--- a/inc/inventoryruleentity.class.php
+++ b/inc/inventoryruleentity.class.php
@@ -117,7 +117,7 @@ class PluginFusioninventoryInventoryRuleEntity extends Rule {
* @param array $params
* @return array
*/
- function executeActions($output, $params) {
+ function executeActions($output, $params, array $input = []) {

PluginFusioninventoryToolbox::logIfExtradebug(
"pluginFusioninventory-rules-entity",
@@ -395,7 +395,7 @@ class PluginFusioninventoryInventoryRuleEntity extends Rule {
if ($this->checkCriterias($input)) {
unset($output["_no_rule_matches"]);
$refoutput = $output;
- $output = $this->executeActions($output, $params);
+ $output = $this->executeActions($output, $params, $input);
if (!isset($output['pass_rule'])) {
$this->updateOnlyCriteria($options, $refoutput, $output);
//Hook
diff --git a/inc/inventoryruleimport.class.php b/inc/inventoryruleimport.class.php
index a9454f521..f60115f41 100644
--- a/inc/inventoryruleimport.class.php
+++ b/inc/inventoryruleimport.class.php
@@ -716,7 +716,7 @@ class PluginFusioninventoryInventoryRuleImport extends Rule {
* @param array $params
* @return array
*/
- function executeActions($output, $params) {
+ function executeActions($output, $params, array $input = []) {
if (isset($params['class'])) {
$class = $params['class'];
} else if (isset($_SESSION['plugin_fusioninventory_classrulepassed'])) {
diff --git a/inc/inventoryrulelocation.class.php b/inc/inventoryrulelocation.class.php
index f0e8edeab..05ddf6199 100644
--- a/inc/inventoryrulelocation.class.php
+++ b/inc/inventoryrulelocation.class.php
@@ -117,7 +117,7 @@ class PluginFusioninventoryInventoryRuleLocation extends Rule {
* @param array $params
* @return array
*/
- function executeActions($output, $params) {
+ function executeActions($output, $params, array $input = []) {

PluginFusioninventoryToolbox::logIfExtradebug(
"pluginFusioninventory-rules-location",
diff --git a/phpunit/1_Unit/SoftwareUpdateTest.php b/phpunit/1_Unit/SoftwareUpdateTest.php
index d5203f33a..f30f94428 100644
--- a/phpunit/1_Unit/SoftwareUpdateTest.php
+++ b/phpunit/1_Unit/SoftwareUpdateTest.php
@@ -162,9 +162,12 @@ class SoftwareUpdateTest extends RestoreDatabase_TestCase {
'PUBLISHER' => 'fusioninventory team',
'NAME' => 'fusioninventory',
'VERSION' => '0.85+1.0',
- 'SYSTEM_CATEGORY' => 'devel'
+ 'SYSTEM_CATEGORY' => 'devel',
+ 'OPERATIONG_SYSTEM' => 0
];

+ $a_software['Computer']['device_id'] = 0;
+
$pfFormatconvert = new PluginFusioninventoryFormatconvert();
$a_return = $pfFormatconvert->computerSoftwareTransformation($a_software, 0);

Loading

0 comments on commit 5e06e95

Please sign in to comment.