Skip to content

Save the filters of the part lists under a name - #1673

Open
killecaptron wants to merge 2 commits into
Part-DB:masterfrom
killecaptron:saved-filters
Open

killecaptron wants to merge 2 commits into
Part-DB:masterfrom
killecaptron:saved-filters

Conversation

@killecaptron

Copy link
Copy Markdown
Contributor

In #1087 you mentioned that you are planning to store custom filter combinations as user-definable "views". We needed this for recurring evaluations (e.g. "parts with a lead time of more than 52 weeks"), so I implemented a first version: named filters, listed under "Show" in the sidebar as suggested in #1087. It has been running on our test instance for a few days. As with #1672, this is meant as a proposal: if you have a different concept for the views in mind, I'm happy to rework it to your liking.

What it does

  • Once a filter is applied, it can be saved under a name at the bottom of the filter panel. The panel also lists the saved filters as buttons.
  • Saved filters appear in the tools tree under Show → Saved filters, which also leads to a page where they can be renamed, shared and deleted.
  • A saved filter stores the part list page (all parts, search, category, footprint, manufacturer, storage location, supplier or tag), its route parameters and the query parameters of the applied filter. Opening it redirects to that page with the filter applied. The filter is evaluated anew each time, so the result is always up to date, and the page opens in the language of whoever opens it. Only these part list routes are accepted, and internal parameters like _locale are dropped.
  • New table saved_filters (migration Version20261125120000 for MySQL, SQLite and PostgreSQL), with the owner as a foreign key (ON DELETE CASCADE).

What it doesn't do (yet): it only stores the filter, not the column selection or sorting of the table, and there is no API endpoint for it. If your idea of "views" includes those, the entity could be extended with them.

Permissions – the part I'm least sure about

New permission saved_filters with two operations:

  • create: save, rename and delete your own filters.
  • share: share filters with all users, and edit or delete the shared filters of all users. Setting it also sets create.

Reading follows from parts.read: everybody who can see parts can open the shared filters and their own. The anonymous user can open shared filters but cannot save any; that is enforced in the voter.

The permission schema update (version 5) grants create to everybody who has parts.read, and share to everybody who has config.change_system_settings. The reasoning was that shared filters are visible to all users, like the system settings (e.g. the banner). The presets do the same: read-only users get create, administrators get share.

Open questions where I'd follow your preference:

  1. Is a separate permission worthwhile at all, or should saving simply require parts.read and sharing an existing permission?
  2. Should share be derived from a different permission than config.change_system_settings?
  3. The operations don't have an apiTokenRole, as there is no API for saved filters so far.

Other

  • Permission schema: Store the tags of parts as entities of their own #1672 also bumps the schema to version 5. Whichever of the two is merged second needs to renumber its update method to 6. I'll gladly do that, of course.
  • Only the English translations are included; German and the other languages go through Crowdin.
  • Docs: a short section in docs/usage/tips_tricks.md.
  • Tests: controller tests (save, open, edit, delete, sharing and permissions), entity tests and a test for the permission schema update. The full test suite and PHPStan pass locally.

🤖 Generated with Claude Code

@greptile-apps

greptile-apps Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5 · Preserve saved date cutoffs across timezones before merging; owner deletion also needs sidebar cache cleanup.RetriggerView in GreptileConfidence Score: 4/5 Tier: apex

[Medium impact] Saved filters affect part-list workflows and visibility across users.

Preserve saved date cutoffs across timezones before merging; owner deletion also needs sidebar cache cleanup.

FindingsFix All in Claude CodeFindings

  1. P1 Shared date cutoffs change ▶
  2. P2 Deleted filters stay visible ▶
Fix with agent prompt
### Issue 1
src/Controller/SavedFilterController.php:93
Shared date filters can return different parts for users in different timezones. `save()` stores the raw date text, but `DateTimeConstraintType` reads it using the opener's timezone. For example, a cutoff saved as noon in UTC becomes noon in Berlin, which is 11:00 UTC in winter.

Store date cutoffs with their timezone, or normalize them to UTC and convert them when reopening.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

### Issue 2
src/Services/Trees/ToolsTreeBuilder.php:318-320
Deleting a shared filter's owner leaves broken links in other users' cached sidebars. The database deletes that owner's filters through `ON DELETE CASCADE`, but user deletion does not clear `tree_tools` for other users. Those links survive page reloads and return 404 until another change clears the cache.

Clear both `tree_tools` and `sidebar_tree_update` when an owner is deleted.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Adds named private and shared filters for part lists, with management pages and sidebar links.

  • Part lists can reopen filters saved under a name.
  • Saved-filter permissions separate personal saves from sharing.
  • The tools sidebar lists filters people can open.

Acknowledged scope from killecaptron:

Application tests and visual checks were not run; PHP and installed dependencies are absent.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["Part list with an applied filter"] --> B["POST /saved_filters/save"]
    B --> C["Check permissions and CSRF token"]
    C --> D[("saved_filters")]
    D --> E["Filter buttons and sidebar"]
    E --> F["GET /saved_filters/{id}"]
    F --> G["Check read access"]
    G --> H["Redirect to the saved list"]
    H --> I["Evaluate the filter again"]
Loading

Reviews (1) · Last reviewed commit: "Save the filters of the part lists under..." · Reviewed by Greptile

->setOwner($user)
->setName(trim((string) $request->request->get('name', '')))
->setShared($request->request->getBoolean('shared') && $this->isGranted('share', SavedFilter::class))
->setTarget($route, $routeParams, $query);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Shared date cutoffs change

Shared date filters can return different parts for users in different timezones. save() stores the raw date text, but DateTimeConstraintType reads it using the opener's timezone. For example, a cutoff saved as noon in UTC becomes noon in Berlin, which is 11:00 UTC in winter.

Store date cutoffs with their timezone, or normalize them to UTC and convert them when reopening.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Controller/SavedFilterController.php
Line: 93

Comment:
**Shared date cutoffs change**

Shared date filters can return different parts for users in different timezones. `save()` stores the raw date text, but `DateTimeConstraintType` reads it using the opener's timezone. For example, a cutoff saved as noon in UTC becomes noon in Berlin, which is 11:00 UTC in winter.

Store date cutoffs with their timezone, or normalize them to UTC and convert them when reopening.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid, thanks. A saved filter now stores the date-times of its date-time constraints in UTC: save() converts them from the timezone of the user who saves the filter, and opening a filter converts them to the timezone of the user who opens it (SavedFilter::setTarget() / getQuery()). Dates without a time (e.g. the lot expiration date) are kept as they are, as they denote a calendar day. A test saves a filter as a user in Berlin and opens it as a user in New York.

Comment on lines +318 to +320
$user = $this->security->getUser();
$filters = $this->entityManager->getRepository(SavedFilter::class)
->findVisibleFor($user instanceof User ? $user : null);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Deleted filters stay visible

Deleting a shared filter's owner leaves broken links in other users' cached sidebars. The database deletes that owner's filters through ON DELETE CASCADE, but user deletion does not clear tree_tools for other users. Those links survive page reloads and return 404 until another change clears the cache.

Clear both tree_tools and sidebar_tree_update when an owner is deleted.

Knowledge Base Used: Web application experience

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Services/Trees/ToolsTreeBuilder.php
Line: 318-320

Comment:
**Deleted filters stay visible**

Deleting a shared filter's owner leaves broken links in other users' cached sidebars. The database deletes that owner's filters through `ON DELETE CASCADE`, but user deletion does not clear `tree_tools` for other users. Those links survive page reloads and return 404 until another change clears the cache.

Clear both `tree_tools` and `sidebar_tree_update` when an owner is deleted.

**Knowledge Base Used:** [Web application experience](https://app.greptile.com/-/switch-tenant?tenant=part-db&next=%2Fcustom-context%2Fknowledge-base%2Fpart-db%2Fpart-db-server%2F-%2Fdocs%2Fweb-application-experience.md)

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid, thanks. The TreeCacheInvalidationListener now invalidates tree_tools and sidebar_tree_update when a user is deleted, as the database deletes their (possibly shared) filters without any listener of the filters being called. There is a test for this as well.

killecaptron and others added 2 commits November 30, 2026 08:18
A filter of a part list could only be kept as a bookmark of its URL. Now an
applied filter can be saved under a name at the bottom of the filter panel:

* A saved filter stores the part list page (all parts, search, category,
  footprint, manufacturer, storage location, supplier or tag) with its route
  parameters and the query parameters of the applied filter. Opening it
  redirects to that page with the filter applied, in the language of whoever
  opens it, so the result is always up to date.
* Saved filters are listed in the filter panel of all part lists and in the
  tools tree of the sidebar under Show -> Saved filters, which also leads to a
  page to rename and delete them.
* Filters are private to the user who saved them, unless they are shared with
  all users. A new "saved_filters" permission controls this: "create" allows
  saving own filters, "share" allows sharing filters and changing or deleting
  the shared filters of all users. The permission schema update grants
  "create" to everybody who can read parts and "share" to everybody who can
  change the system settings; the presets do the same for read-only users and
  administrators. The anonymous user can open shared filters, but not save
  any.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Saved filters store the date-times of their constraints in UTC and convert
them to the timezone of the user who opens them, so a shared filter covers
the same points in time for all users.

Deleting a user invalidates the cached tools trees, as the database deletes
the (possibly shared) filters of the user without calling any listener.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@killecaptron

Copy link
Copy Markdown
Contributor Author

I've pushed fixes for both review comments:

  • Saved filters store their date-times in UTC and convert them to the timezone of whoever opens them, so a shared filter covers the same points in time for all users.
  • Deleting a user invalidates the cached tools trees, which list the shared filters of that user.

Both come with tests. I've also rebased the branch onto the current master.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant