Repository navigation
Save the filters of the part lists under a name - #1673
killecaptron wants to merge 2 commits into
Conversation
[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.
|
| ->setOwner($user) | ||
| ->setName(trim((string) $request->request->get('name', ''))) | ||
| ->setShared($request->request->getBoolean('shared') && $this->isGranted('share', SavedFilter::class)) | ||
| ->setTarget($route, $routeParams, $query); |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
| $user = $this->security->getUser(); | ||
| $filters = $this->entityManager->getRepository(SavedFilter::class) | ||
| ->findVisibleFor($user instanceof User ? $user : null); |
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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.
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>
155d136 to
4a53140
Compare
|
I've pushed fixes for both review comments:
Both come with tests. I've also rebased the branch onto the current master. |
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
_localeare dropped.saved_filters(migrationVersion20261125120000for 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_filterswith 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 setscreate.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
createto everybody who hasparts.read, andshareto everybody who hasconfig.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 getcreate, administrators getshare.Open questions where I'd follow your preference:
parts.readand sharing an existing permission?sharebe derived from a different permission thanconfig.change_system_settings?apiTokenRole, as there is no API for saved filters so far.Other
docs/usage/tips_tricks.md.🤖 Generated with Claude Code