Allow custom public share tokens for form links#3311
Allow custom public share tokens for form links#3311alexander-rebello wants to merge 8 commits intonextcloud:mainfrom
Conversation
Signed-off-by: Alexander Rebello <me@alexander-rebello.de>
Signed-off-by: Alexander Rebello <me@alexander-rebello.de>
Signed-off-by: Alexander Rebello <me@alexander-rebello.de>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Signed-off-by: Alexander Rebello <me@alexander-rebello.de>
Signed-off-by: Alexander Rebello <me@alexander-rebello.de>
Signed-off-by: Alexander Rebello <me@alexander-rebello.de>
Chartman123
left a comment
There was a problem hiding this comment.
Added some review comments on the PHP part
| ### Update a Public Share Token | ||
|
|
||
| - Endpoint: `/api/v3/forms/{formId}/shares/{shareId}/token` | ||
| - Method: `PATCH` | ||
| - Url-Parameters: | ||
| | Parameter | Type | Description | | ||
| |-----------|---------|-------------| | ||
| | _formId_ | Integer | ID of the form containing the share | | ||
| | _shareId_ | Integer | ID of the public link share to update | | ||
| - Parameters: | ||
| | Parameter | Type | Description | | ||
| |-----------|---------|-------------| | ||
| | _token_ | String | New token for the public share link | | ||
| - Restrictions: | ||
| - Only available when the admin setting _allowCustomPublicShareTokens_ is enabled. | ||
| - Only link shares can be updated. | ||
| - Token must be unique among link shares and only contain alphanumeric characters. | ||
| - Token length must be between 8 and 256 characters. | ||
| - Response: **Status-Code OK**, as well as the id of the updated share. | ||
|
|
||
| ``` | ||
| "data": 5 | ||
| ``` | ||
|
|
There was a problem hiding this comment.
I wouldn't add a new endpoint for that, please use the already existing update share endpoint
| #[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)] | ||
| class PageController extends Controller { | ||
| private const TEMPLATE_MAIN = 'main'; | ||
| private const PUBLIC_SHARE_HASH_REQUIREMENT = '[a-zA-Z0-9]{8,256}'; |
There was a problem hiding this comment.
Could this be moved to our central Constants.php file?
| #[NoCSRFRequired()] | ||
| #[PublicPage()] | ||
| #[FrontpageRoute(verb: 'GET', url: '/s/{hash}', requirements: ['hash' => '[a-zA-Z0-9]{24,}'])] | ||
| #[FrontpageRoute(verb: 'GET', url: '/s/{hash}', requirements: ['hash' => self::PUBLIC_SHARE_HASH_REQUIREMENT])] |
There was a problem hiding this comment.
Would probably be good if we can decide here wether custom share tokens are allowed on that instance. But IIRC it's not working with dynamically defined requirements.
There was a problem hiding this comment.
Meaning it would be good, but can't be done in this instance? Or should I try?
| #[CORS()] | ||
| #[NoAdminRequired()] | ||
| #[ApiRoute(verb: 'PATCH', url: '/api/v3/forms/{formId}/shares/{shareId}/token')] | ||
| public function updateShareToken(int $formId, int $shareId, string $token): DataResponse { |
There was a problem hiding this comment.
See other comment... Should be moved to already existing endpoint
Signed-off-by: Alexander Rebello <me@alexander-rebello.de>
Signed-off-by: Alexander Rebello <me@alexander-rebello.de>
Accidentally approved the PR instead of just adding the review comments
This adds admin-gated custom tokens for public Forms share links. By default the feature is disabled, so existing instances keep the current random-token behavior. When enabled by an admin, form owners can edit the token of an existing public link directly in the sharing sidebar, save it explicitly, and the old URL becomes invalid immediately.
It also adds the necessary backend support for token updates, keeps public-link routing compatible with custom tokens, and includes tests plus API documentation updates.