Skip to content

Fix error when creating mail shares if custom tokens are enabled#60378

Draft
danxuliu wants to merge 1 commit into
masterfrom
fix-error-when-creating-mail-shares-if-custom-tokens-are-enabled
Draft

Fix error when creating mail shares if custom tokens are enabled#60378
danxuliu wants to merge 1 commit into
masterfrom
fix-error-when-creating-mail-shares-if-custom-tokens-are-enabled

Conversation

@danxuliu
Copy link
Copy Markdown
Member

Fixes #56168

When a new share is saved it is first created in the backend and then updated with some additional attributes set in the frontend. If custom tokens are enabled the attributes to update also include the token. However, for new shares the token is set by the backend when it is created, it is not defined by the frontend, so the token returned by the backend needs to be copied to the share data in the frontend. Otherwise the update would fail because an empty token is sent.

Note that this is unrelated to #53442, which is about not being able to modify the token of a mail share because the backend does not store the new one.

How to test

  • Log in as an admin
  • Open Sharing section in Administration settings
  • Enable Allow users to set custom share link tokens
  • Open the Files app
  • Open the Sharing tab for a file
  • Create a new share with an e-mail address

Result with this pull request

The share is created without errors; modifying it (for example, to change the permissions) also works without errors

Result without this pull request

The share is created, but Tokens must contain at least 1 character and may only contain letters, numbers, or a hyphen is shown in an error toast; trying to modify the share will also cause the same error to appear, although it does not appear once the page is reloaded and the share is modified again (as in that case the token was already loaded from the backend when opening the share details).

@danxuliu danxuliu added this to the Nextcloud 34 milestone May 14, 2026
@danxuliu
Copy link
Copy Markdown
Member Author

/backport to stable33 please

@danxuliu
Copy link
Copy Markdown
Member Author

/backport to stable32 please

When a new share is saved it is first created in the backend and then
updated with some additional attributes set in the frontend. If custom
tokens are enabled the attributes to update also include the token.
However, for new shares the token is set by the backend when it is
created, it is not defined by the frontend, so the token returned by the
backend needs to be copied to the share data in the frontend. Otherwise
the update would fail because an empty token is sent.

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
@danxuliu danxuliu force-pushed the fix-error-when-creating-mail-shares-if-custom-tokens-are-enabled branch from 148ddb0 to 77a8bc7 Compare May 14, 2026 21:30
@danxuliu
Copy link
Copy Markdown
Member Author

@nfebe @susnux @skjnldsv I do not know what would be the proper fix for the lint issues. Could you take a look? Thanks!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Share-by-email fails with HTTP 400 "Tokens must contain at least 1 character" error

1 participant