Edgard 5 роки тому
батько
коміт
42e639f540
6 змінених файлів з 237 додано та 12 видалено
  1. 3 0
      composer.json
  2. 56 3
      composer.lock
  3. 11 0
      hook.php
  4. 123 0
      inc/profile.class.php
  5. 33 9
      inc/provider.class.php
  6. 11 0
      inc/provider_user.class.php

+ 3 - 0
composer.json

@@ -17,5 +17,8 @@
         "platform": {
             "php": "7.1.2"
         }
+    },
+    "require": {
+        "galbar/jsonpath": "^1.1"
     }
 }

+ 56 - 3
composer.lock

@@ -4,8 +4,61 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "74275a109c221b0ce3813266b1c6c246",
-    "packages": [],
+    "content-hash": "2c4e26302ad265cff738f455e868a8f2",
+    "packages": [
+        {
+            "name": "galbar/jsonpath",
+            "version": "1.1",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/Galbar/JsonPath-PHP.git",
+                "reference": "36d3ac57b1a62ff507d7751d797a9e03ffbd1385"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/Galbar/JsonPath-PHP/zipball/36d3ac57b1a62ff507d7751d797a9e03ffbd1385",
+                "reference": "36d3ac57b1a62ff507d7751d797a9e03ffbd1385",
+                "shasum": ""
+            },
+            "require": {
+                "php": ">=5.4"
+            },
+            "require-dev": {
+                "phpunit/phpunit": "~4.0",
+                "sami/sami": ">=3.3.0",
+                "satooshi/php-coveralls": ">=1.0.1"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-0": {
+                    "JsonPath\\": "src/Galbar/",
+                    "Utilities\\": "src/Galbar/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "Apache-2.0"
+            ],
+            "authors": [
+                {
+                    "name": "Alessio Linares",
+                    "email": "alessio@alessio.cc",
+                    "role": "Software Engineer"
+                }
+            ],
+            "description": "JSONPath implementation for querying and updating JSON objects",
+            "keywords": [
+                "json",
+                "jsonpath",
+                "path"
+            ],
+            "support": {
+                "issues": "https://github.com/Galbar/JsonPath-PHP/issues",
+                "source": "https://github.com/Galbar/JsonPath-PHP/tree/1.1"
+            },
+            "time": "2020-06-01T15:18:22+00:00"
+        }
+    ],
     "packages-dev": [
         {
             "name": "dealerdirect/phpcodesniffer-composer-installer",
@@ -358,5 +411,5 @@
     "platform-overrides": {
         "php": "7.1.2"
     },
-    "plugin-api-version": "1.1.0"
+    "plugin-api-version": "2.0.0"
 }

+ 11 - 0
hook.php

@@ -181,6 +181,17 @@ function plugin_singlesignon_install() {
                 ADD `color` varchar(7) DEFAULT NULL";
       $DB->query($query) or die("error adding picture column " . $DB->error());
    }
+   if (version_compare($currentVersion, "1.3.0", '<')) {
+      $query = "CREATE TABLE `glpi_plugin_singlesignon_providers_users` (
+         `id` int(11) NOT NULL AUTO_INCREMENT,
+         `plugin_singlesignon_providers_id` int(11) NOT NULL DEFAULT '0',
+         `users_id` int(11) NOT NULL DEFAULT '0',
+         `remote_id` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+         PRIMARY KEY (`id`),
+         UNIQUE KEY `unicity` (`plugin_singlesignon_providers_id`,`users_id`)
+       ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
+      $DB->query($query) or die("error creating glpi_plugin_singlesignon_providers_users " . $DB->error());
+   }
 
    Config::setConfigurationValues('singlesignon', [
       'version' => PLUGIN_SINGLESIGNON_VERSION,

+ 123 - 0
inc/profile.class.php

@@ -0,0 +1,123 @@
+<?php
+
+class PluginSinglesignonProfile extends CommonDBTM {
+
+    const READMY = 1;
+    const CHANGENAME = 1024;
+
+    //Não usa tabela própria
+    static protected $notable = true;
+
+    function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) {
+
+        if (!$withtemplate) {
+            if ($item->getType() == 'Profile') {
+                return __('Live Helper Chat');
+            }
+        }
+        return '';
+    }
+
+    function getRights($interface = 'central') {
+        $values = [
+            self::READMY     => 'Visualizar',
+            self::CHANGENAME => 'Alterar Nome',
+        ];
+        return $values;
+    }
+
+    /**
+     *
+     * @param Profile $profile
+     */
+    function showForm($profile) {
+        $canedit = Session::haveRightsOr(Profile::$rightname, [CREATE, UPDATE, PURGE]);
+
+        echo "<div class='spaced'>";
+        if ($canedit) {
+            echo "<form name='form' action=\"" . Toolbox::getItemTypeFormURL('Profile') . "\" method='post'>";
+        }
+
+        $matrix_options = [
+            'canedit'       => $canedit,
+            'default_class' => 'tab_bg_2',
+        ];
+
+        $rights = [
+            [
+                'rights' => Profile::getRightsFor('PluginLivehelperchatProfile', 'central'),
+                'label'  => 'Widget',
+                'field'  => 'plugin_livehelperchat_widget'
+            ],
+            [
+                'rights' => Profile::getRightsFor('PluginLivehelperchatChat', 'central'),
+                'label'  => 'Visualizar Chat do Ticket',
+                'field'  => 'plugin_livehelperchat_chat'
+            ],
+        ];
+
+        $matrix_options['title'] = 'Live Helper Chat';
+        $profile->displayRightsChoiceMatrix($rights, $matrix_options);
+
+        if ($canedit) {
+            //Botão
+            echo "<div class='center'>";
+            echo "<input type='hidden' name='id' value='" . $profile->fields['id'] . "'>";
+            echo "<input type='submit' name='update' value=\"" . _sx('button', 'Save') . "\" class='submit'>";
+            echo "</div>\n";
+            Html::closeForm();
+        }
+
+        echo "</div>";
+    }
+
+    static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) {
+        if ($item->getType() == 'Profile') {
+            $config = new self();
+            $config->showForm($item);
+        }
+        return true;
+    }
+
+    static function install() {
+        $profile_widget = 'plugin_livehelperchat_widget';
+        $profile_chat = 'plugin_livehelperchat_chat';
+
+        $profileRight = new ProfileRight();
+
+        $profiles = $profileRight->find("`name` = 'livehelperchat'", '', '');
+        //Se existir permissões antigas, renomea-las
+        if (!empty($profiles)) {
+            foreach ($profiles as $profile) {
+                $profile['name'] = $profile_widget;
+                $profileRight->update($profile);
+            }
+        }
+
+        /**
+         * Widget
+         */
+        $profileWidget = $profileRight->find("`name` = '$profile_widget'", '', 1);
+        //Caso não existir, criar novos profiles
+        if (empty($profileWidget)) {
+            ProfileRight::addProfileRights([$profile_widget]);
+            ProfileRight::updateProfileRightAsOtherRight($profile_widget, PluginLivehelperchatProfile::READMY, '');
+            ProfileRight::updateProfileRightAsOtherRight($profile_widget, PluginLivehelperchatProfile::CHANGENAME, '');
+        }
+
+        /**
+         * Chat Ticket
+         */
+        $profileChat = $profileRight->find("`name` = '$profile_chat'", '', 1);
+        //Caso não existir, criar novos profiles
+        if (empty($profileChat)) {
+            ProfileRight::addProfileRights([$profile_chat]);
+            ProfileRight::updateProfileRightAsOtherRight($profile_chat, READ, '');
+        }
+    }
+
+    static function uninstall() {
+        ProfileRight::deleteProfileRights(['plugin_livehelperchat_widget']);
+    }
+
+}

+ 33 - 9
inc/provider.class.php

@@ -326,19 +326,22 @@ class PluginSinglesignonProvider extends CommonDBTM {
          return false;
       }
 
-      if (isset($input["_blank_bgcolor"])
+      if (
+         isset($input["_blank_bgcolor"])
          && $input["_blank_bgcolor"]
       ) {
          $input['bgcolor'] = '';
       }
 
-      if (isset($input["_blank_color"])
+      if (
+         isset($input["_blank_color"])
          && $input["_blank_color"]
       ) {
          $input['color'] = '';
       }
 
-      if (isset($input["_blank_picture"])
+      if (
+         isset($input["_blank_picture"])
          && $input["_blank_picture"]
       ) {
          $input['picture'] = '';
@@ -376,7 +379,7 @@ class PluginSinglesignonProvider extends CommonDBTM {
          unset($opt['id']);
          if (isset($options[$optid])) {
             $message = "Duplicate key $optid ({$options[$optid]['name']}/{$opt['name']}) in " .
-            get_class($this) . " searchOptions!";
+               get_class($this) . " searchOptions!";
             Toolbox::logDebug($message);
          }
          foreach ($opt as $k => $v) {
@@ -625,12 +628,12 @@ class PluginSinglesignonProvider extends CommonDBTM {
       switch ($ma->getAction()) {
          case 'DoIt':
             echo "&nbsp;<input type='hidden' name='toto' value='1'>" .
-            Html::submit(_x('button', 'Post'), ['name' => 'massiveaction']) .
-            " " . __('Write in item history', 'example');
+               Html::submit(_x('button', 'Post'), ['name' => 'massiveaction']) .
+               " " . __('Write in item history', 'example');
             return true;
          case 'do_nothing':
             echo "&nbsp;" . Html::submit(_x('button', 'Post'), ['name' => 'massiveaction']) .
-            " " . __('but do nothing :)', 'example');
+               " " . __('but do nothing :)', 'example');
             return true;
       }
       return parent::showMassiveActionsSubForm($ma);
@@ -1078,6 +1081,27 @@ class PluginSinglesignonProvider extends CommonDBTM {
       return $auth->auth_succeded;
    }
 
+   public function linkUser($user_id) {
+      /** @var User */
+      $user = User::getById($user_id);
+      if (!$user) {
+         return;
+      }
+
+      $resource_array = $this->getResourceOwner();
+
+      if (!$resource_array) {
+         return false;
+      }
+
+      $link = new PluginSinglesignonProvider_User();
+      return $link->add([
+         'plugin_singlesignon_providers_id' => $this->fields['id'],
+         'users_id' => $user_id,
+         'remote_id' => $resource_array['id'],
+      ]);
+   }
+
    /**
     * Generate a URL to callback
     * Some providers don't accept query string, it convert to PATH
@@ -1171,8 +1195,8 @@ class PluginSinglesignonProvider extends CommonDBTM {
          // Iterate on possible suffix while dest exists.
          // This case will almost never exists as dest is based on an unique id.
          $dest = $basePath
-         . '/' . $subdirectory
-         . '/' . $filename . ($i > 0 ? '_' . $i : '') . '.' . $ext;
+            . '/' . $subdirectory
+            . '/' . $filename . ($i > 0 ? '_' . $i : '') . '.' . $ext;
          $i++;
       } while (file_exists($dest));
 

+ 11 - 0
inc/provider_user.class.php

@@ -0,0 +1,11 @@
+<?php
+
+class PluginSinglesignonProvider_User extends CommonDBRelation {
+
+   // From CommonDBRelation
+   static public $itemtype_1   = 'PluginSinglesignonProvider';
+   static public $items_id_1   = 'plugin_singlesignon_providers_id';
+
+   static public $itemtype_2 = 'User';
+   static public $items_id_2 = 'users_id';
+}