Commit graph

164 commits

Author SHA1 Message Date
Dan Stillman
4f825ad50c Don't throw getting the filename of a stored file with a corrupt path
A stored file's path is normally 'storage:<filename>', which is parsed
as a string, but some ancient libraries apparently have relative paths
('../.../foo.pdf') that fell through to PathUtils.filename() and threw
NS_ERROR_FILE_UNRECOGNIZED_PATH, breaking syncing.

Resolve stored-file leaves as strings regardless of prefix and reserve
PathUtils.filename() for linked files, whose paths are genuine absolute
paths.

https://forums.zotero.org/discussion/132861/zotero-sync-issue-id-1987012678
2026-07-23 11:12:12 -04:00
Dan Stillman
cddb19bf36 Only reject and strip actual directory paths in stored-file filenames
Some checks are pending
CI / Test (shard 1) (push) Waiting to run
CI / Test (shard 2) (push) Waiting to run
CI / Test (shard 3) (push) Waiting to run
CI / Test (shard 4) (push) Waiting to run
CI / Utilities Tests (push) Waiting to run
CI / Build, Upload (push) Waiting to run
ee68452b treated any backslash as a directory separator, in both the
attachmentPath setter and the userdata 128 migration. But backslashes
are technically valid on Linux/macOS and appear in real filenames (due
to LaTeX in titles, etc.), so that would wrongly throw on or truncate
them. Only a forward slash (never valid in a filename) or a Windows
absolute path (drive-letter or UNC prefix) reliably indicates a leaked
directory path, so treat just those as paths and leave bare backslashes
alone. We should make sure we're running getValidFileName() everywhere
to avoid saving those.
2026-07-21 16:02:40 -04:00
Dan Stillman
ee68452b05 Disallow slashes in stored-file attachment paths
Someone ended up (via a plugin, presumably) with stored-file attachments
with a full path after 'storage:', which broke file syncing. Throw when
setting a stored-file path containing a slash, and strip paths from
existing filenames in a schema update step. No particular reason to
think that the file with that basename will exist in the storage dir,
but at least it will be looking for the right file and not be totally
broken.

Separately, the dataserver will clean up filenames with full paths and
block going forward.

https://forums.zotero.org/discussion/132822/reference-sychronization-error
2026-07-21 10:40:59 -04:00
Tom Najdek
40cb1cfa84
Fix stale itemType in _previousData (#5964)
Some checks failed
CI / Build, Upload, Test (push) Has been cancelled
This fixes a problem where, on subsequent item type changes, a stale itemType is reported and the filename is not updated.
2026-06-19 16:34:23 -04:00
Dan Stillman
99228a6c76 Disallow changing item type to/from attachment, note, or annotation
The UI doesn't allow this, but plugins could do it, leading to sync
errors. (Can't do much for direct DB access.)

https://forums.zotero.org/discussion/131286/67734299-error-happens-in-my-zotero-plz-help-me
2026-05-04 15:30:27 -04:00
Abe Jellinek
fb8389d654
Read Aloud: Persist last-read position in synced setting (#5860) 2026-03-27 15:22:02 -04:00
Dan Stillman
a3909af5ab Clear lastRead in Item#fromJSON() when absent from API response
When the server returns an attachment without lastRead (because it was
cleared), fromJSON was not clearing the local value since it only
processes fields present in the JSON. Add explicit check after field
processing to clear lastRead when absent.
2026-03-24 11:36:43 -04:00
Dan Stillman
aaed7ddfc0 Add Added By and Modified By columns for group libraries
- Add columns as options in item tree, visible only in group libraries
- Fall back to createdByUserID for Modified By when lastModifiedByUserID
  is not set
- Update lastModifiedByUserID on local saves when dateModified changes
- Fix backfill in _updateGroupItemUsers() to process all batches
- Update formatColumnName() to support Fluent string keys

Closes #233
2026-03-18 23:19:11 -04:00
Abe Jellinek
34039991f8
Track attachment last-read time, add Recently Read virtual collection (#2854)
Track when attachments are last opened or read, storing a `lastRead` Unix timestamp on the attachment. For user library items, `lastRead` syncs as an attachment property in item JSON. For group library items, it syncs via a per-user synced setting (like `lastPageIndex`).

- Add `lastRead` column to `itemAttachments`
- Add `AttachmentReadObserver` to update `lastRead` on file open and page change (throttled to 5 min for page changes)
- Add "Recently Read" virtual collection (items read in last 14 days, sorted by `lastRead` descending)
- Add `lastRead` search condition with date operators
- Add `lastRead` item tree column with new `dependsOnChildren` property for parent item aggregation
- Add `getItemLastRead()` to return max `lastRead` across child attachments

Also:

- Generalize collection tree SCSS to support universal (context-fill) icons alongside themed icons

---------

Co-authored-by: Dan Stillman <dstillman@zotero.org>
2026-03-17 13:52:00 -04:00
Dan Stillman
2f6825027a Add Director fallback to firstCreator for Video Recording items
The firstCreator/sortCreator SQL now falls back through primary →
editor → director → contributor. This ensures Video Recording items
with only a Director creator show that creator in the items list.

Also refactors the repetitive SQL-building in _getFirstCreatorSQL()
and _getSortCreatorSQL() into helper functions.

Closes #5720
2026-03-09 10:28:06 -04:00
Dan Stillman
7487595e6a Fix test error after adding type to document 2025-12-25 22:13:34 -05:00
abaevbog
11223451d2
set libraryID on annotations in tests (#5644)
Fix tests breakage post 84764570f4
2025-12-04 08:27:57 -05:00
Abe Jellinek
84764570f4
Enforce annotationSortIndex format by type (#5641) 2025-11-25 12:59:09 -05:00
Tom Najdek
e896fd0137
Add continuous-renaming functionality for attachment files (#3860)
Resolves #1685
2025-09-11 04:54:03 -04:00
Dan Stillman
33bd1327a0 Remove unnecessary file stat in Item#attachmentModificationTime 2025-08-28 03:06:52 -04:00
Dan Stillman
f81763b173 Remove Chai as Promised
A test using `assert.eventually` was failing after the Bluebird removal
but worked with just `await`, and since there hasn't really been much
point to Chai as Promised since the introduction of `async`/`await` ages
ago, just remove the library instead of figuring out why.
2025-07-30 22:31:08 -04:00
Abe Jellinek
67d2e1cead fx140: Asyncify/ESMify tests
They seem to be succeeding when run individually, but failing when
run as a whole. Not sure why yet.
2025-07-30 22:30:53 -04:00
Tom Najdek
ee35361608 Test for subsequent updates providing stale changed object data
From #5297
2025-05-31 02:20:32 -04:00
Dan Stillman
2bc0c4861c Fix changed object data not being passed in notifier extraData
Which I apparently broke a decade ago in afe0412c5

And add support for 'deleted' and 'tags', which now use a different
mechanism
2025-05-12 23:36:58 -04:00
Abe Jellinek
6cdae37e5b
Local API: Fix 500 error when attachment has unparseable path (#5010) 2025-01-28 00:54:29 -05:00
Dan Stillman
ed045e640a Tests for Item#fromJSON() changes (#3422) 2025-01-22 03:23:06 -05:00
Martynas Bagdonas
d16ea8fe15
Enable type change between highlight and underline (#4411) 2024-07-20 02:27:11 -04:00
abaevbog
26f7c707ba
display emojis from color-less tag in itemTreeRow (#3330)
- display the first continuous span of emojis in the primary cell of
the itemTree for non-colored tags.
- the emojis appear after the colored tags' circles (if any)
- to keep things consistent with itemTree, sort tags in the tagsBox in
the following order: colored tags first sorted by their position,
emoji tags after sorted alphabetically, followed by remaining tags sorted
alphabetically.
2024-07-15 00:28:01 -04:00
abaevbog
2d3375e9f6
Revised logic of trashed collections in item cache (#4358)
- revert change from 2401a34031
that only loads un-trashed collections in _loadCollections.
If an item only belongs to deleted collections, item._loaded.collections = true
from _loadCollections will never run, so an exception
will be thrown in item.toJSON() when syncing happens.
Instead, to address the problem of item.getCollections()
having stale data #4307, add 'includeTrashed' parameter to
item.getCollections() based on which item._collections
will be filtered. Fixes: #4346
- revert earlier, no more necessary, changes from a532cfb475
to not alter item._collections cache when collections are being trashed or restored.
Collection is removed from item._collections only when it is permanently
erased.
- removed unnecessary test checking for consistent item._collections
value before and after reload, since item._collections is no longer
modified
- fix encountered bug where a trashed child collection is not
unloaded if a parent collection is erased without being trashed first.
- tweaked Zotero.Search sql construction to count items
that only belong to trashed collections into 'unfiled'. Fixes: #4347

---------

Co-authored-by: Dan Stillman
2024-07-09 03:34:12 -04:00
Dan Stillman
81ed1f6ebb Strip line and paragraph separators in filenames
And don't fail on existing filenames with these characters in
`Item::attachmentFilename`

https://forums.zotero.org/discussion/114025/pdf-files-renaming-casuing-syncing-issue
2024-04-28 07:51:25 -04:00
Abe Jellinek
a5393ca0e5 Merge: Keep external annotations on master, don't erase on other
PDFWorker only re-imports external annotations when the file changes on
disk. Keep annotation items corresponding to external annotations so
that they don't disappear after the merge (and then come back when the
file is edited).

Tweaks behavior introduced in 2aa34a6.

https://forums.zotero.org/discussion/113943/zotero-7-beta-merging-pdf-files-leaves-ghost-external-annotations
2024-04-25 16:35:09 -04:00
Tom Najdek
16fa1ac893
Fix attachment icon remains after deleting attachment. Fix #3779 2024-03-08 15:22:15 +01:00
Tom Najdek
cffb5cdd4b
Fix best attachment type sometimes missing. Fix #3740 2024-02-26 13:14:27 +01:00
Tom Najdek
b1333d0e9d
More attachment type icons in the item tree (#3645) 2024-02-23 06:11:40 -05:00
Abe Jellinek
676f820f87
Strip bidi control characters in filenames and elsewhere (#3208)
Passing unformatted = true to Item#getField() now returns a bidi control
character-less result, and we use that in Reader#updateTitle() and
getFileBaseNameFromItem() to prevent bidi control characters from showing up in
filenames and window titles (the former everywhere, the latter on Windows only).

We also strip bidi control characters in getValidFileName() to be extra safe.
2023-07-22 03:30:28 -04:00
Dan Stillman
cadfca7475 Set a default annotation color if not assigned
https://forums.zotero.org/discussion/104249/sync-issue-on-ipados
2023-04-12 22:23:13 -04:00
Dan Stillman
497d6376c8 Add Zotero.Item::topLevelItem and Zotero.Items.getTopLevel(items) 2022-09-12 15:54:03 -04:00
Abe Jellinek
22b00c33de Empty Trash: Visually remove deleted items, refresh icon (#2606)
There were a few problems causing the incorrect behavior:
1. Rows were being removed only if they had no non-deleted children, which
   wasn't the right check. We want to remove all rows with no *deleted*
   children.
2. Children of the removed rows weren't being removed with them.
3. We weren't invalidating the tree (which _removeRows() doesn't do).

Also:

* Erase trashed annotation after getAnnotations() test

Because ItemTree#notify() doesn't yet correctly handle refresh events on
parent items that are themselves children (three-level nesting: item ->
attachment -> annotation), this test was causing a failure in
itemTreeTest.js.
2022-08-19 09:14:24 -04:00
Abe Jellinek
1f9e518581 Duplicates Merge: Preserve embedded annotations (#2728) 2022-08-11 03:52:40 -04:00
Abe Jellinek
3481def4f6 Fix sorting by attachment (#2586) 2022-08-11 02:33:03 -04:00
Dan Stillman
03242e8984 fx-compat: DB.executeTransaction() no longer takes generator functions 2022-05-12 02:38:59 -04:00
Dan Stillman
08d3880d88 Don't remove relations in annotation item JSON
This was causing UUIDs for annotations from Mendeley imports to be
removed after a sync, resulting in annotations being duplicated on a
reimport.
2022-04-14 06:37:30 -04:00
Dan Stillman
174f1aadde Fix error adding group item before syncing in Zotero 6
Fixes #2440
2022-03-21 22:50:43 -04:00
Dan Stillman
c7ece79f79 Fix missing creators not being removed in item.fromJSON()
Apparently there's been a bug for years where removing a creator
remotely hasn't caused it to be removed locally via sync...

https://forums.zotero.org/discussion/94910/desktop-app-not-correctly-syncing
2022-03-09 02:43:22 -05:00
Dan Stillman
df64a16b55 Disallow unowned group annotation edits, but allow deletions
Update `DataObject::isEditable()` to take an optional `op` argument to
test individual operations as opposed to general library editing.
Erasing objects now tests `erase`, and `Item::isEditable()` allows
`erase` for unowned group annotations while disallowing the default
`edit`.

It's still up to the reader to handle this appropriately in the UI and
not allow operations it shouldn't, but this enforces it in the data
layer.
2022-01-31 06:48:05 -05:00
Dan Stillman
1e1969a089 Fix getBestAttachmentState() tests after b0ba7e464 2021-12-22 05:23:16 -05:00
Dan Stillman
76d8818bed Don't count missing annotation values as changed if empty string passed
Similar to 0d377a1c4a, this fixes an unnecessary annotation reload and
loss of unsaved typing on auto-sync immediately after an annotation is
created.
2021-04-26 03:49:59 -04:00
Dan Stillman
0d377a1c4a Clear changed state of annotation after saving color change
This was resulting in an extra 'modify' event after each sync upload.
2021-04-24 19:49:08 -04:00
Dan Stillman
749e28dc1f Fix alphabetical sorting of child attachments in new databases
Broken after global schema introduction
2021-04-18 01:44:39 -04:00
Dan Stillman
26bf507fe2 Throw invalid-data error on unknown annotation type 2021-04-01 05:52:14 -04:00
Dan Stillman
8c341f2e26 Add field name to assertion in annotation clone test 2021-03-23 03:20:33 -04:00
Dan Stillman
b566c06f93 Add getImageBlob() support function for tests 2021-03-21 14:36:43 -04:00
Dan Stillman
7889cd5d39 Fix item.clone() on annotation items 2021-03-21 14:36:42 -04:00
Dan Stillman
651aabc4dc Prevent setting parent item to non-regular item
Except for embedded-image attachments under notes and annotations under
attachments
2021-03-02 18:10:44 -05:00
Dan Stillman
eb865e2625 setAttachmentPageIndex() → setAttachmentLastPageIndex() 2021-03-02 18:10:44 -05:00