Repository navigation
feat: define a files metadata API - #66355
leftybournes wants to merge 3 commits into
Conversation
Signed-off-by: Kent Delante <kent@delante.me> Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Kent Delante <kent@delante.me> Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Kent Delante <kent@delante.me> Assisted-by: ClaudeCode:claude-opus-5-5
| * | ||
| * @since 36.0.0 | ||
| */ | ||
| #[Throwable(since: '36.0.0')] |
There was a problem hiding this comment.
I initially considered it but, after thinking about it, I think it shouldn't be as only core currently throws it. I'll remove the attribute.
| public function canRead(string $key, Node $node, ?IUser $user): bool; | ||
|
|
||
| /** | ||
| * Whether the user may change the value of the field on the node, as decided by the app owning the field. | ||
| * Returns false for unknown fields. | ||
| * When injected into an app, the app is detected and passed on to the owning app. | ||
| * | ||
| * @param string $key the key of the metadata field | ||
| * @param Node $node the node to which the metadata key applies | ||
| * @param IUser|null $user null for unauthenticated access, e.g. public shares | ||
| * @since 36.0.0 | ||
| */ | ||
| public function canEdit(string $key, Node $node, ?IUser $user): bool; |
There was a problem hiding this comment.
Both should ideally directly use the Actor API
artonge
left a comment
There was a problem hiding this comment.
Can you clarify what the changes are adding compared to the current files metadata API?
I think those changes might contain some logic duplication.
There was a problem hiding this comment.
Maybe a duplicate of:
server/lib/public/FilesMetadata/Model/IMetadataValueWrapper.php
Lines 24 to 46 in 7bd62eb
| private function checkAccess(string $key, Node $node, ?IUser $user, bool $edit): bool { | ||
| $field = $this->registry->getFields()[$key] ?? null; | ||
| $provider = $this->registry->getProvider($key); | ||
| if ($field === null || $provider === null) { | ||
| return false; | ||
| } | ||
|
|
||
| try { | ||
| return $edit | ||
| ? $provider->canEdit($field, $node, $user, $this->appId) | ||
| : $provider->canRead($field, $node, $user, $this->appId); | ||
| } catch (Throwable $e) { | ||
| $this->logger->error('Failed to check access to metadata field "' . $key . '"', [ | ||
| 'app' => $field->getApp(), | ||
| 'exception' => $e, | ||
| ]); | ||
| return false; | ||
| } | ||
| } |
There was a problem hiding this comment.
server/apps/dav/lib/Connector/Sabre/FilesPlugin.php
Lines 735 to 746 in 7bd62eb
| #[\Override] | ||
| public function canEdit(string $key, Node $node, ?IUser $user): bool { | ||
| return $this->checkAccess($key, $node, $user, true); | ||
| } |
There was a problem hiding this comment.
server/apps/dav/lib/Connector/Sabre/FilesPlugin.php
Lines 665 to 667 in 7bd62eb
|
Thanks for this, it is close to something we need. Context: with Dutch municipalities and VNG (Common Ground) we are working on records-management support in Nextcloud, so files can be kept in line with archival law on storage that enforces retention. One piece is metadata that comes from the storage backend or a records register: classification, retention status, disposal date, legal hold and provenance. Users must be able to see and search it in Files, but not change it. Displayed, not owned. The schema and provider pattern here looks like the right place for that. Three things would make it fit, ideally as room in the API rather than extra work in this PR:
On @artonge's question: if Two related proposals cover the storage side: #66498 (a backend that can refuse a deletion, with a reason the user sees) and #66499 (a durable object id, so metadata and links keep pointing at the same record after a rescan or migration). We would like to help rather than only ask. We are happy to build follow-up PRs on top of this one (WebDAV wiring and enforcement, source per value, showing the fields in the Files sidebar), with tests, and to maintain them. Would you prefer follow-ups once this lands, or PRs against your branch? |
The existing is quite bare metal, what we need is a way to have proper defined metadata:
Yes that can be done with the actor, but I do not think this belongs into the metadata itself but into the audit logging.
Not sure what you mean, files metadata should always be stored with the API. In general there are 3 things:
An app stores their metadata with this API for a file, that metadata then is imprinted into documents where needed using the imprinting API.
If there is a real use case we can add this. For this API we agreed to add a base set of types and only add new ones if there is a use case because adding types is easy, removing types means breaking API. |
|
Thanks @susnux, that clarifies the scope, and it fits what we need better than I first read.
|
Summary
This defines a metadata API that apps will be able to use to register custom metadata fields to files.
Currently, metadata fields that can be registered with the following types:
These are checked and validated. For example, int/float metadata can be in the form of a string. It will be validated and normalized into an actual int/float or throw an error if the input is invalid.
Checklist
3. to review, feature component)stable32)AI (if applicable)