glpi icon indicating copy to clipboard operation
glpi copied to clipboard

Feature : targeted private saved searches

Open ArthurMinfotel opened this issue 1 year ago • 5 comments

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets

Add option to choose targets for private saved searches. Modify CommonDBVisible to make it possible to restrict the types of target available, and to choose the right used to determine the availability of user type targets. For a saved search, a target can either be a user or a group. User and group dropdown take into account entity of the item when loading available targets.

The class used for the user target might need to be changed (SavedSearch_User is already used so I couldn't follow the naming convention set by the other CommonDBVisible items, so I created SavedSearch_UserTarget for now). Also the new method getVisibilityRight could be used to dynamically get the right for the itemtype associated with the saved search (to only be able to targets users with the read right on the itemtype).

Example : Target tab for SavedSearch : image Corresponding record in DB : image Available saved searches for the itemtype for users 2 without any target set : image User 2 added as a target : image Available saved searches on the itemtype for user 2 after being added added as a target : image

Type of targets available set through the static variable $types : image

Restrictions on groups available as targets based on the item's entity (for the example entity set as 1 instead of root) : List of entities : image List of groups with entity restrictions : image Visibility for groups : image Subvisibility : image

ArthurMinfotel avatar Jul 24 '24 08:07 ArthurMinfotel

@ArthurMinfotel

Could you add some screenshots to your PR description?

cedric-anne avatar Jul 24 '24 08:07 cedric-anne

@ArthurMinfotel

Could you add some screenshots to your PR description?

I've edited it to add several screenshoots, showing an example and the added functionnalities.

ArthurMinfotel avatar Jul 24 '24 15:07 ArthurMinfotel

We discussed about it with @orthagh and we think that the is_private flag should be removed from the database. Indeed, having both a public/private management + a entity/groups/users visibility management is redundant and can be a bit complex to handle for the end user.

At creation, if the saved search is created as public, then it a visibility on the root entity + recursive should be automatically created. If it is created as private, the lack of visibility filters should be sufficient to make it private.

It would require to add a migration to add a new visibility filter to all existing public searches.

The current behavior of the public searches is to have them available for all users within it's entity (and child entities if it is recursive), so shouldn't I rather make it so that it automaticaly create a link with the active entity rather than the root entity if it is meant to be a public search ?

ArthurMinfotel avatar Aug 01 '24 15:08 ArthurMinfotel

We discussed about it with @orthagh and we think that the is_private flag should be removed from the database. Indeed, having both a public/private management + a entity/groups/users visibility management is redundant and can be a bit complex to handle for the end user. At creation, if the saved search is created as public, then it a visibility on the root entity + recursive should be automatically created. If it is created as private, the lack of visibility filters should be sufficient to make it private. It would require to add a migration to add a new visibility filter to all existing public searches.

The current behavior of the public searches is to have them available for all users within it's entity (and child entities if it is recursive), so shouldn't I rather make it so that it automaticaly create a link with the active entity rather than the root entity if it is meant to be a public search ?

As we add visibility specs to saved searches, the idea was to consider that a saved search with no visibility is private. In this case, the is_private flag is no more useful.

cedric-anne avatar Aug 01 '24 16:08 cedric-anne

@cedric-anne Could you tell me if what I've added for the creation of public search matches what you talked about ? Same for the migration. Thanks in advance.

ArthurMinfotel avatar Aug 02 '24 14:08 ArthurMinfotel

@cedric-anne Could you tell me if what I've added for the creation of public search matches what you talked about ? Same for the migration. Thanks in advance.

It seems to match our functional request, but I do not have time right now to do a complete review.

cedric-anne avatar Sep 05 '24 06:09 cedric-anne

Made some changes to take the deletion of savedsearch.form.php into account (what was causing issue when I last requested a review, didn't notice the deletion when I merged from main and didn't do any functionnal tests for the minor changes I did after).

I created a new controller to include the action needed for items extending CommonDBVisible : it extends GenericFormController and deal with the 'addvisibility' action.

There are some right issues when loading a saved search with a profile which doesn't have the read right on bookmark_public, which I temporarely fixed by overriding the canView method in SavedSearch to always return true. But I also add to override getMenuContent because of that (which only stop the link from appearing in the menu, the list can still be accessed). I left it with this temporary solution because I think the rights might get reworked with the deletion of the private property, but if the rights are left unchanged I thought of maybe reworking front/savedsearch.php this way : image

ArthurMinfotel avatar Nov 14 '24 10:11 ArthurMinfotel

If everything is OK from a pratical point of view, I will start working on updating the current test functions and adding a new one for the targets.

ArthurMinfotel avatar Jan 30 '25 14:01 ArthurMinfotel

Tests are updated. Things that are tested are :

  1. Automatically adding the saved search's entity as target if input contains is_private with a falsy value.
  2. For each type of target, visibility of a saved search to a user other than the creator when using SavedSearch::getMine().

ArthurMinfotel avatar Feb 05 '25 13:02 ArthurMinfotel

It seems like there are still some small lint issues.

For the sonar cloud report, it does not like that you are created an item using a class supplied by the browser:

image

This has created security issues in the past as malicious users can supply some unwanted class names. You can fix it by calling getItemForItemtype instead, which will make sure the class is at least a CommonGLPI item which should be safe.

AdrienClairembault avatar Feb 10 '25 09:02 AdrienClairembault

I've updated the controller to fix the issue with the class instance.

For the lint, I believe those are not fixable : image The first and second are called in getTabNameForItem and displayTabContentForItem, and so lint doesn't recognise the methods from the class CommonDBVisible, which are called when $item is an instance of SavedSearch , since its parameter $item is typed as CommonGLPI. As the third one, it's a right check, so I don't even know what the cause might be.

ArthurMinfotel avatar Feb 10 '25 11:02 ArthurMinfotel

I've added suggestions that should fix the typing issues.

For the "always true" issue, this is because the condition exist twice:

image

So when you reach the second condition, it will always be true because if the first one was false then the function would have returned a value already.

I'll let you review to see which one you need to keep.

AdrienClairembault avatar Feb 11 '25 08:02 AdrienClairembault

I added the suggested fix. I will remember those for future developments.

ArthurMinfotel avatar Feb 11 '25 09:02 ArthurMinfotel

I rebased the branch to fix conflicts and revert some whitespace changes to reduce the diff. If @orthagh approves the feature, I will do a last technical review and merge it.

cedric-anne avatar Apr 15 '25 14:04 cedric-anne

I tested the feature:

  • with the "glpi" user, I created a savedsearch on the Tickets
  • shared it to a "normal" target user
  • logged in with the "normal" user
  • attempting to access the savedsearch from the Tickets results in a fatal error

By the way, the left menu points to the "Tools" section, instead of remaining in the Tickets section.

Note that if I add the "READ" (Saved Searches) permission for the "normal" user profile (Observer by default), it doesn't change anything.

image

User can not access the SavedSearch 1
In ./front/savedsearch.php(53)
#0 ./src/Glpi/Controller/LegacyFileLoadController.php(59): require()
#1 ./vendor/symfony/http-kernel/HttpKernel.php(101): Glpi\Controller\LegacyFileLoadController->Glpi\Controller\{closure}()
#2 ./vendor/symfony/http-foundation/StreamedResponse.php(106): Symfony\Component\HttpKernel\HttpKernel::Symfony\Component\HttpKernel\{closure}()
#3 ./vendor/symfony/http-foundation/Response.php(423): Symfony\Component\HttpFoundation\StreamedResponse->sendContent()
#4 ./src/Glpi/Kernel/Kernel.php(266): Symfony\Component\HttpFoundation\Response->send()
#5 ./public/index.php(58): Glpi\Kernel\Kernel->sendResponse()
#6 {main}

flegastelois avatar Apr 23 '25 15:04 flegastelois

Replaced by #20247

cedric-anne avatar Jul 09 '25 12:07 cedric-anne