Explorar o código

Fixed provider list for GLPI >= 9.3

Edgard %!s(int64=6) %!d(string=hai) anos
pai
achega
7056e95883
Modificáronse 5 ficheiros con 204 adicións e 148 borrados
  1. 13 0
      hook.php
  2. 115 72
      inc/provider.class.php
  3. 26 26
      locales/en_GB.po
  4. 25 25
      locales/pt_BR.po
  5. 25 25
      locales/singlesignon.pot

+ 13 - 0
hook.php

@@ -93,6 +93,19 @@ function plugin_singlesignon_install() {
       //      $DB->query($query) or die("error populate glpi_plugin_example " . $DB->error());
    }
 
+   // add display preferences
+   $query_display_pref = "SELECT id
+      FROM glpi_displaypreferences
+      WHERE itemtype = 'PluginSinglesignonProvider'";
+   $res_display_pref = $DB->query($query_display_pref);
+   if ($DB->numrows($res_display_pref) == 0) {
+      $DB->query("INSERT INTO `glpi_displaypreferences` VALUES (NULL,'PluginSinglesignonProvider','2','1','0');");
+      $DB->query("INSERT INTO `glpi_displaypreferences` VALUES (NULL,'PluginSinglesignonProvider','3','2','0');");
+      $DB->query("INSERT INTO `glpi_displaypreferences` VALUES (NULL,'PluginSinglesignonProvider','5','4','0');");
+      $DB->query("INSERT INTO `glpi_displaypreferences` VALUES (NULL,'PluginSinglesignonProvider','6','5','0');");
+      $DB->query("INSERT INTO `glpi_displaypreferences` VALUES (NULL,'PluginSinglesignonProvider','10','6','0');");
+   }
+
    Config::setConfigurationValues('singlesignon', [
       'version' => PLUGIN_SINGLESIGNON_VERSION,
    ]);

+ 115 - 72
inc/provider.class.php

@@ -53,21 +53,6 @@ class PluginSinglesignonProvider extends CommonDBTM {
       return __sso('Single Sign-on');
    }
 
-   /**
-    * @see CommonGLPI::getAdditionalMenuLinks()
-    * */
-   static function getAdditionalMenuLinks() {
-      global $CFG_GLPI;
-      $links = [];
-
-      //      $links['add'] = '/plugins/singlesignon/front/provider.form.php';
-      //      $links['config'] = '/plugins/singlesignon/index.php';
-      $links["<img  src='" . $CFG_GLPI["root_doc"] . "/pics/menu_showall.png' title='" . __s('Show all') . "' alt='" . __s('Show all') . "'>"] = '/plugins/singlesignon/index.php';
-      $links[__s('Test link', 'singlesignon')] = '/plugins/singlesignon/index.php';
-
-      return $links;
-   }
-
    function defineTabs($options = []) {
 
       $ong = [];
@@ -230,65 +215,123 @@ class PluginSinglesignonProvider extends CommonDBTM {
    }
 
    function getSearchOptions() {
+      // For GLPI <= 9.2
+      $options = [];
+      foreach ($this->rawSearchOptions() as $opt) {
+         if (!isset($opt['id'])) {
+            continue;
+         }
+         $optid = $opt['id'];
+         unset($opt['id']);
+         if (isset($options[$optid])) {
+            $message = "Duplicate key $optid ({$options[$optid]['name']}/{$opt['name']}) in " .
+                  get_class($this) . " searchOptions!";
+            Toolbox::logDebug($message);
+         }
+         foreach ($opt as $k => $v) {
+            $options[$optid][$k] = $v;
+         }
+      }
+      return $options;
+   }
 
+   function rawSearchOptions() {
       $tab = [];
-      $tab['common'] = __('Characteristics');
-
-      $tab[1]['table'] = $this->getTable();
-      $tab[1]['field'] = 'type';
-      $tab[1]['name'] = __('Type');
-      $tab[1]['searchtype'] = 'equals';
-      $tab[1]['datatype'] = 'specific';
-
-      $tab[2]['table'] = $this->getTable();
-      $tab[2]['field'] = 'name';
-      $tab[2]['name'] = __('Name');
-      $tab[2]['datatype'] = 'text';
-
-      $tab[3]['table'] = $this->getTable();
-      $tab[3]['field'] = 'client_id';
-      $tab[3]['name'] = __sso('Client ID');
-      $tab[3]['datatype'] = 'text';
-
-      $tab[4]['table'] = $this->getTable();
-      $tab[4]['field'] = 'client_secret';
-      $tab[4]['name'] = __sso('Client Secret');
-      $tab[4]['datatype'] = 'text';
-
-      $tab[5]['table'] = $this->getTable();
-      $tab[5]['field'] = 'scope';
-      $tab[5]['name'] = __sso('Scope');
-      $tab[5]['datatype'] = 'text';
-
-      $tab[6]['table'] = $this->getTable();
-      $tab[6]['field'] = 'extra_options';
-      $tab[6]['name'] = __sso('Extra Options');
-      $tab[6]['datatype'] = 'text';
-
-      $tab[7]['table'] = $this->getTable();
-      $tab[7]['field'] = 'url_authorize';
-      $tab[7]['name'] = __sso('Authorize URL');
-      $tab[7]['datatype'] = 'weblink';
-
-      $tab[8]['table'] = $this->getTable();
-      $tab[8]['field'] = 'url_access_token';
-      $tab[8]['name'] = __sso('Access Token URL');
-      $tab[8]['datatype'] = 'weblink';
-
-      $tab[9]['table'] = $this->getTable();
-      $tab[9]['field'] = 'url_resource_owner_details';
-      $tab[9]['name'] = __sso('Resource Owner Details URL');
-      $tab[9]['datatype'] = 'weblink';
-
-      $tab[10]['table'] = $this->getTable();
-      $tab[10]['field'] = 'is_active';
-      $tab[10]['name'] = __('Active');
-      $tab[10]['searchtype'] = 'equals';
-      $tab[10]['datatype'] = 'bool';
-
-      $tab[30]['table'] = $this->getTable();
-      $tab[30]['field'] = 'id';
-      $tab[30]['name'] = __('ID');
+
+      $tab[] = [
+         'id' => 'common',
+         'name' => __('Characteristics'),
+      ];
+
+      $tab[] = [
+         'id' => 1,
+         'table' => $this->getTable(),
+         'field' => 'name',
+         'name' => __('Name'),
+         'datatype' => 'itemlink',
+      ];
+
+      $tab[] = [
+         'id' => 2,
+         'table' => $this->getTable(),
+         'field' => 'type',
+         'name' => __('Type'),
+         'searchtype' => 'equals',
+         'datatype' => 'specific',
+      ];
+
+      $tab[] = [
+         'id' => 3,
+         'table' => $this->getTable(),
+         'field' => 'client_id',
+         'name' => __sso('Client ID'),
+         'datatype' => 'text',
+      ];
+
+      $tab[] = [
+         'id' => 4,
+         'table' => $this->getTable(),
+         'field' => 'client_secret',
+         'name' => __sso('Client Secret'),
+         'datatype' => 'text',
+      ];
+
+      $tab[] = [
+         'id' => 5,
+         'table' => $this->getTable(),
+         'field' => 'scope',
+         'name' => __sso('Scope'),
+         'datatype' => 'text',
+      ];
+
+      $tab[] = [
+         'id' => 6,
+         'table' => $this->getTable(),
+         'field' => 'extra_options',
+         'name' => __sso('Extra Options'),
+         'datatype' => 'specific',
+      ];
+
+      $tab[] = [
+         'id' => 7,
+         'table' => $this->getTable(),
+         'field' => 'url_authorize',
+         'name' => __sso('Authorize URL'),
+         'datatype' => 'weblink',
+      ];
+
+      $tab[] = [
+         'id' => 8,
+         'table' => $this->getTable(),
+         'field' => 'url_access_token',
+         'name' => __sso('Access Token URL'),
+         'datatype' => 'weblink',
+      ];
+
+      $tab[] = [
+         'id' => 9,
+         'table' => $this->getTable(),
+         'field' => 'url_resource_owner_details',
+         'name' => __sso('Resource Owner Details URL'),
+         'datatype' => 'weblink',
+      ];
+
+      $tab[] = [
+         'id' => 10,
+         'table' => $this->getTable(),
+         'field' => 'is_active',
+         'name' => __('Active'),
+         'searchtype' => 'equals',
+         'datatype' => 'bool',
+      ];
+
+      $tab[] = [
+         'id' => 30,
+         'table' => $this->getTable(),
+         'field' => 'id',
+         'name' => __('ID'),
+         'datatype' => 'itemlink',
+      ];
 
       return $tab;
    }

+ 26 - 26
locales/en_GB.po

@@ -7,8 +7,8 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2019-04-26 14:41-0300\n"
-"PO-Revision-Date: 2019-04-26 14:41-0300\n"
+"POT-Creation-Date: 2019-04-26 15:28-0300\n"
+"PO-Revision-Date: 2019-04-26 15:28-0300\n"
 "Last-Translator: Automatically generated\n"
 "Language-Team: none\n"
 "MIME-Version: 1.0\n"
@@ -55,99 +55,99 @@ msgstr "Provider not active."
 msgid "Single Sign-on Provider"
 msgstr "Single Sign-on Provider"
 
-#: inc/provider.class.php:109
+#: inc/provider.class.php:94
 msgid "SSO Type"
 msgstr "SSO Type"
 
-#: inc/provider.class.php:117 inc/provider.class.php:250
+#: inc/provider.class.php:102 inc/provider.class.php:267
 msgid "Client ID"
 msgstr "Client ID"
 
-#: inc/provider.class.php:119 inc/provider.class.php:255
+#: inc/provider.class.php:104 inc/provider.class.php:275
 msgid "Client Secret"
 msgstr "Client Secret"
 
-#: inc/provider.class.php:124 inc/provider.class.php:260
+#: inc/provider.class.php:109 inc/provider.class.php:283
 msgid "Scope"
 msgstr "Scope"
 
-#: inc/provider.class.php:126 inc/provider.class.php:265
+#: inc/provider.class.php:111 inc/provider.class.php:291
 msgid "Extra Options"
 msgstr "Extra Options"
 
-#: inc/provider.class.php:137 inc/provider.class.php:270
+#: inc/provider.class.php:122 inc/provider.class.php:299
 msgid "Authorize URL"
 msgstr "Authorize URL"
 
-#: inc/provider.class.php:142 inc/provider.class.php:275
+#: inc/provider.class.php:127 inc/provider.class.php:307
 msgid "Access Token URL"
 msgstr "Access Token URL"
 
-#: inc/provider.class.php:147 inc/provider.class.php:280
+#: inc/provider.class.php:132 inc/provider.class.php:315
 msgid "Resource Owner Details URL"
 msgstr "Resource Owner Details URL"
 
-#: inc/provider.class.php:181
+#: inc/provider.class.php:166
 msgid "A Name is required"
 msgstr "A Name is required"
 
-#: inc/provider.class.php:187
+#: inc/provider.class.php:172
 #, php-format
 msgid "The \"%s\" is a Invalid type"
 msgstr "The \"%s\" is a Invalid type"
 
-#: inc/provider.class.php:191
+#: inc/provider.class.php:176
 msgid "A Client ID is required"
 msgstr "A Client ID is required"
 
-#: inc/provider.class.php:195
+#: inc/provider.class.php:180
 msgid "A Client Secret is required"
 msgstr "A Client Secret is required"
 
-#: inc/provider.class.php:200
+#: inc/provider.class.php:185
 msgid "An Authorize URL is required"
 msgstr "An Authorize URL is required"
 
-#: inc/provider.class.php:202
+#: inc/provider.class.php:187
 msgid "The Authorize URL is invalid"
 msgstr "The Authorize URL is invalid"
 
-#: inc/provider.class.php:206
+#: inc/provider.class.php:191
 msgid "An Access Token URL is required"
 msgstr "An Access Token URL is required"
 
-#: inc/provider.class.php:208
+#: inc/provider.class.php:193
 msgid "The Access Token URL is invalid"
 msgstr "The Access Token URL is invalid"
 
-#: inc/provider.class.php:212
+#: inc/provider.class.php:197
 msgid "A Resource Owner Details URL is required"
 msgstr "A Resource Owner Details URL is required"
 
-#: inc/provider.class.php:214
+#: inc/provider.class.php:199
 msgid "The Resource Owner Details URL is invalid"
 msgstr "The Resource Owner Details URL is invalid"
 
-#: inc/provider.class.php:331
+#: inc/provider.class.php:374
 msgid "Generic"
 msgstr "Generic"
 
-#: inc/provider.class.php:332
+#: inc/provider.class.php:375
 msgid "Facebook"
 msgstr "Facebook"
 
-#: inc/provider.class.php:333
+#: inc/provider.class.php:376
 msgid "GitHub"
 msgstr "GitHub"
 
-#: inc/provider.class.php:334
+#: inc/provider.class.php:377
 msgid "Google"
 msgstr "Google"
 
-#: inc/provider.class.php:335
+#: inc/provider.class.php:378
 msgid "Instagram"
 msgstr "Instagram"
 
-#: inc/provider.class.php:336
+#: inc/provider.class.php:379
 msgid "LinkdeIn"
 msgstr "LinkdeIn"

+ 25 - 25
locales/pt_BR.po

@@ -7,7 +7,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2019-04-26 14:37-0300\n"
+"POT-Creation-Date: 2019-04-26 15:28-0300\n"
 "PO-Revision-Date: 2019-04-26 11:04-0300\n"
 "Last-Translator: Edgard Lorraine Messias <edgardmessias@gmail.com>\n"
 "Language-Team: none\n"
@@ -55,99 +55,99 @@ msgstr "Provedor não ativo."
 msgid "Single Sign-on Provider"
 msgstr "Provedor Single Sign-on"
 
-#: inc/provider.class.php:109
+#: inc/provider.class.php:94
 msgid "SSO Type"
 msgstr "Tipo SSO"
 
-#: inc/provider.class.php:117 inc/provider.class.php:250
+#: inc/provider.class.php:102 inc/provider.class.php:267
 msgid "Client ID"
 msgstr "ID de Cliente"
 
-#: inc/provider.class.php:119 inc/provider.class.php:255
+#: inc/provider.class.php:104 inc/provider.class.php:275
 msgid "Client Secret"
 msgstr "Segredo do Cliente"
 
-#: inc/provider.class.php:124 inc/provider.class.php:260
+#: inc/provider.class.php:109 inc/provider.class.php:283
 msgid "Scope"
 msgstr "Escopo"
 
-#: inc/provider.class.php:126 inc/provider.class.php:265
+#: inc/provider.class.php:111 inc/provider.class.php:291
 msgid "Extra Options"
 msgstr "Opções Extras"
 
-#: inc/provider.class.php:137 inc/provider.class.php:270
+#: inc/provider.class.php:122 inc/provider.class.php:299
 msgid "Authorize URL"
 msgstr "URL de Autorização"
 
-#: inc/provider.class.php:142 inc/provider.class.php:275
+#: inc/provider.class.php:127 inc/provider.class.php:307
 msgid "Access Token URL"
 msgstr "URL de Token de Acesso"
 
-#: inc/provider.class.php:147 inc/provider.class.php:280
+#: inc/provider.class.php:132 inc/provider.class.php:315
 msgid "Resource Owner Details URL"
 msgstr "URL de Detalhes do Proprietário do Recurso"
 
-#: inc/provider.class.php:181
+#: inc/provider.class.php:166
 msgid "A Name is required"
 msgstr "Nome é obrigatório"
 
-#: inc/provider.class.php:187
+#: inc/provider.class.php:172
 #, php-format
 msgid "The \"%s\" is a Invalid type"
 msgstr "O \"%s\" é um tipo inválido"
 
-#: inc/provider.class.php:191
+#: inc/provider.class.php:176
 msgid "A Client ID is required"
 msgstr "ID de cliente é obrigatório"
 
-#: inc/provider.class.php:195
+#: inc/provider.class.php:180
 msgid "A Client Secret is required"
 msgstr "Segredo do Cliente é obrigatório"
 
-#: inc/provider.class.php:200
+#: inc/provider.class.php:185
 msgid "An Authorize URL is required"
 msgstr "URL de Autorização é obrigatório"
 
-#: inc/provider.class.php:202
+#: inc/provider.class.php:187
 msgid "The Authorize URL is invalid"
 msgstr "A URL de Autorização é inválida"
 
-#: inc/provider.class.php:206
+#: inc/provider.class.php:191
 msgid "An Access Token URL is required"
 msgstr "URL de Token de Acesso é obrigatório"
 
-#: inc/provider.class.php:208
+#: inc/provider.class.php:193
 msgid "The Access Token URL is invalid"
 msgstr "A URL de Token de Acesso é inválida"
 
-#: inc/provider.class.php:212
+#: inc/provider.class.php:197
 msgid "A Resource Owner Details URL is required"
 msgstr "URL de Detalhes do Proprietário do Recurso é obrigatório"
 
-#: inc/provider.class.php:214
+#: inc/provider.class.php:199
 msgid "The Resource Owner Details URL is invalid"
 msgstr "A URL de Detalhes do Proprietário do Recurso é inválida"
 
-#: inc/provider.class.php:331
+#: inc/provider.class.php:374
 msgid "Generic"
 msgstr "Generic"
 
-#: inc/provider.class.php:332
+#: inc/provider.class.php:375
 msgid "Facebook"
 msgstr "Facebook"
 
-#: inc/provider.class.php:333
+#: inc/provider.class.php:376
 msgid "GitHub"
 msgstr "GitHub"
 
-#: inc/provider.class.php:334
+#: inc/provider.class.php:377
 msgid "Google"
 msgstr "Google"
 
-#: inc/provider.class.php:335
+#: inc/provider.class.php:378
 msgid "Instagram"
 msgstr "Instagram"
 
-#: inc/provider.class.php:336
+#: inc/provider.class.php:379
 msgid "LinkdeIn"
 msgstr "LinkdeIn"

+ 25 - 25
locales/singlesignon.pot

@@ -8,7 +8,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2019-04-26 14:41-0300\n"
+"POT-Creation-Date: 2019-04-26 15:28-0300\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -55,99 +55,99 @@ msgstr ""
 msgid "Single Sign-on Provider"
 msgstr ""
 
-#: inc/provider.class.php:109
+#: inc/provider.class.php:94
 msgid "SSO Type"
 msgstr ""
 
-#: inc/provider.class.php:117 inc/provider.class.php:250
+#: inc/provider.class.php:102 inc/provider.class.php:267
 msgid "Client ID"
 msgstr ""
 
-#: inc/provider.class.php:119 inc/provider.class.php:255
+#: inc/provider.class.php:104 inc/provider.class.php:275
 msgid "Client Secret"
 msgstr ""
 
-#: inc/provider.class.php:124 inc/provider.class.php:260
+#: inc/provider.class.php:109 inc/provider.class.php:283
 msgid "Scope"
 msgstr ""
 
-#: inc/provider.class.php:126 inc/provider.class.php:265
+#: inc/provider.class.php:111 inc/provider.class.php:291
 msgid "Extra Options"
 msgstr ""
 
-#: inc/provider.class.php:137 inc/provider.class.php:270
+#: inc/provider.class.php:122 inc/provider.class.php:299
 msgid "Authorize URL"
 msgstr ""
 
-#: inc/provider.class.php:142 inc/provider.class.php:275
+#: inc/provider.class.php:127 inc/provider.class.php:307
 msgid "Access Token URL"
 msgstr ""
 
-#: inc/provider.class.php:147 inc/provider.class.php:280
+#: inc/provider.class.php:132 inc/provider.class.php:315
 msgid "Resource Owner Details URL"
 msgstr ""
 
-#: inc/provider.class.php:181
+#: inc/provider.class.php:166
 msgid "A Name is required"
 msgstr ""
 
-#: inc/provider.class.php:187
+#: inc/provider.class.php:172
 #, php-format
 msgid "The \"%s\" is a Invalid type"
 msgstr ""
 
-#: inc/provider.class.php:191
+#: inc/provider.class.php:176
 msgid "A Client ID is required"
 msgstr ""
 
-#: inc/provider.class.php:195
+#: inc/provider.class.php:180
 msgid "A Client Secret is required"
 msgstr ""
 
-#: inc/provider.class.php:200
+#: inc/provider.class.php:185
 msgid "An Authorize URL is required"
 msgstr ""
 
-#: inc/provider.class.php:202
+#: inc/provider.class.php:187
 msgid "The Authorize URL is invalid"
 msgstr ""
 
-#: inc/provider.class.php:206
+#: inc/provider.class.php:191
 msgid "An Access Token URL is required"
 msgstr ""
 
-#: inc/provider.class.php:208
+#: inc/provider.class.php:193
 msgid "The Access Token URL is invalid"
 msgstr ""
 
-#: inc/provider.class.php:212
+#: inc/provider.class.php:197
 msgid "A Resource Owner Details URL is required"
 msgstr ""
 
-#: inc/provider.class.php:214
+#: inc/provider.class.php:199
 msgid "The Resource Owner Details URL is invalid"
 msgstr ""
 
-#: inc/provider.class.php:331
+#: inc/provider.class.php:374
 msgid "Generic"
 msgstr ""
 
-#: inc/provider.class.php:332
+#: inc/provider.class.php:375
 msgid "Facebook"
 msgstr ""
 
-#: inc/provider.class.php:333
+#: inc/provider.class.php:376
 msgid "GitHub"
 msgstr ""
 
-#: inc/provider.class.php:334
+#: inc/provider.class.php:377
 msgid "Google"
 msgstr ""
 
-#: inc/provider.class.php:335
+#: inc/provider.class.php:378
 msgid "Instagram"
 msgstr ""
 
-#: inc/provider.class.php:336
+#: inc/provider.class.php:379
 msgid "LinkdeIn"
 msgstr ""