Tags search criterion returns items of other itemtypes that share the same ID

未关闭
#399 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
半天
新手友好度
62/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
php, sql
领域
backend, search

调研方向

The bug is in the search option for tags, built in plugin_tag_getAddSearchOptionsNew(). Compare its joinparams with the regular join, since the generated subquery keeps only condition and drops jointype and specific_itemtype. Reproduce with a tag on a Project and a ProjectTask that share an ID, then check that a 'Tags is' search on projects excludes the project. Done when the search returns only items of the searched itemtype and 'is not' behaves correctly.

由索引模型根据 Issue 内容生成。

描述

GLPI 11.0.11, Tag 2.14.8.

Searching projects with "Tags is ASYS" returns project 80, which only has the tag DNS. Project task 80 has the tag ASYS.

Since use_subquery is set for GLPI >= 10.0.19, the criterion is built as a subquery by Glpi\Search\Provider\SQLProvider. The subquery only keeps joinparams['condition'] of the glpi_plugin_tag_tagitems join and ignores jointype => itemtype_item / specific_itemtype, so there is no filter on itemtype:

`glpi_projects`.`id` IN (SELECT `items_id` FROM `glpi_plugin_tag_tagitems` WHERE true AND `plugin_tag_tags_id` = '111')

Any item of any type with the same ID and the tag matches. With "is not", the item is wrongly excluded. It happens on every itemtype as soon as a tag is used on more than one type (tickets, changes, computers...). The Tags column in the results is correct, the regular LEFT JOIN has the itemtype condition.

Steps to reproduce:

  1. Allow a tag on Project and ProjectTask.
  2. Put the tag on a project task whose ID is also the ID of an untagged project.
  3. Search projects with "Tags is ": the project is returned.

Adding the itemtype as a join condition in plugin_tag_getAddSearchOptionsNew() fixes it, since the subquery keeps condition:

'jointype'          => 'itemtype_item',
'specific_itemtype' => $itemtype,
'condition'         => ['NEWTABLE.itemtype' => $itemtype],

We run this patch locally. The core subquery could also handle itemtype_item itself.

主要语言
PHP
星标
30
派生
26
平均合并
1 天 2 小时
30 天内合并 PR
8

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

pluginsGLPI/tag 的其他 Issue

查看 pluginsGLPI/tag 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。