diff --git a/CHANGELOG.md b/CHANGELOG.md index cdcf090..177d77c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed - Avoid a per-tag database lookup when rendering the tag column in item lists +- Fix tag associate item ## [2.14.6] - 2026-08-04 diff --git a/ajax/add_item_to_tag.php b/ajax/add_item_to_tag.php new file mode 100644 index 0000000..1ab6624 --- /dev/null +++ b/ajax/add_item_to_tag.php @@ -0,0 +1,70 @@ +. + * ------------------------------------------------------------------------- + * @copyright Copyright (C) 2014-2026 by Teclib'. + * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html + * @link https://github.com/pluginsGLPI/tag + * ------------------------------------------------------------------------- + */ + +use Glpi\Exception\Http\BadRequestHttpException; +use Glpi\Exception\Http\AccessDeniedHttpException; + +Session::checkLoginUser(); + +if (!isset($_POST['plugin_tag_tags_id'], $_POST['itemtype'], $_POST['items_id'])) { + throw new BadRequestHttpException(__s('Missing parameters', 'tag')); +} + +$tag = new PluginTagTag(); +if (!$tag->getFromDB($_POST['plugin_tag_tags_id']) || !$tag->can($tag->getID(), UPDATE)) { + throw new AccessDeniedHttpException(__s('You do not have permission to update this tag', 'tag')); +} + +$itemtype = $_POST['itemtype']; +if (!is_a($itemtype, CommonDBTM::class, true) || !PluginTagTag::canItemtype($itemtype)) { + throw new BadRequestHttpException(__s('Invalid item type', 'tag')); +} + +$item = new $itemtype(); +if (!$item->getFromDB($_POST['items_id']) || !$item->canUpdateItem()) { + throw new AccessDeniedHttpException(__s('You do not have permission to update this item', 'tag')); +} + +$tag_item = new PluginTagTagItem(); +$found = $tag_item->find([ + 'plugin_tag_tags_id' => $tag->getID(), + 'items_id' => $item->getID(), + 'itemtype' => $itemtype, +]); + +if (count($found) === 0) { + $tag_item->add([ + 'plugin_tag_tags_id' => $tag->getID(), + 'items_id' => $item->getID(), + 'itemtype' => $itemtype, + ]); +} + +Html::back(); diff --git a/inc/tagitem.class.php b/inc/tagitem.class.php index f06709c..56ae802 100644 --- a/inc/tagitem.class.php +++ b/inc/tagitem.class.php @@ -197,7 +197,7 @@ public static function showForTag(PluginTagTag $tag) if ($canedit) { echo "