Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/Controller/IdDocsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\Attribute\PublicPage;
use OCP\AppFramework\Http\Attribute\RequestHeader;
use OCP\AppFramework\Http\DataResponse;
use OCP\IL10N;
use OCP\IRequest;
Expand Down Expand Up @@ -62,6 +63,7 @@ public function __construct(
#[AnonRateLimit(limit: 30, period: 60)]
#[NoAdminRequired]
#[NoCSRFRequired]
#[RequestHeader(name: 'libresign-sign-request-uuid', description: 'The UUID of the sign request, used to identify the request', indirect: true)]
#[RequireSignRequestUuid(skipIfAuthenticated: true)]
#[ApiRoute(verb: 'POST', url: '/api/{apiVersion}/id-docs', requirements: ['apiVersion' => '(v1)'])]
public function addFiles(array $files): DataResponse {
Expand Down Expand Up @@ -111,6 +113,7 @@ public function addFiles(array $files): DataResponse {
#[AnonRateLimit(limit: 30, period: 60)]
#[NoAdminRequired]
#[NoCSRFRequired]
#[RequestHeader(name: 'libresign-sign-request-uuid', description: 'The UUID of the sign request, used to identify the request', indirect: true)]
#[RequireSignRequestUuid(skipIfAuthenticated: true)]
#[ApiRoute(verb: 'DELETE', url: '/api/{apiVersion}/id-docs/{nodeId}', requirements: ['apiVersion' => '(v1)'])]
public function delete(int $nodeId, ?string $uuid = null): DataResponse {
Expand Down Expand Up @@ -150,6 +153,7 @@ public function delete(int $nodeId, ?string $uuid = null): DataResponse {
#[PublicPage]
#[AnonRateLimit(limit: 30, period: 60)]
#[NoCSRFRequired]
#[RequestHeader(name: 'libresign-sign-request-uuid', description: 'The UUID of the sign request, used to identify the request', indirect: true)]
#[RequireSignRequestUuid(skipIfAuthenticated: true)]
#[ApiRoute(verb: 'GET', url: '/api/{apiVersion}/id-docs', requirements: ['apiVersion' => '(v1)'])]
public function listUnauthenticatedSignerDocuments(
Expand Down
2 changes: 2 additions & 0 deletions lib/Controller/SignFileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\Attribute\OpenAPI;
use OCP\AppFramework\Http\Attribute\PublicPage;
use OCP\AppFramework\Http\Attribute\RequestHeader;
use OCP\AppFramework\Http\DataResponse;
use OCP\IL10N;
use OCP\IRequest;
Expand Down Expand Up @@ -428,6 +429,7 @@ public function requestCodeBySignerUuid(string $uuid, ?string $identifyMethod, ?
#[RequireSigner]
#[PublicPage]
#[OpenAPI(tags: ['signing'])]
#[RequestHeader(name: 'libresign-sign-request-uuid', description: 'The UUID of the sign request, used to identify the request', indirect: true)]
#[ApiRoute(verb: 'POST', url: '/api/{apiVersion}/sign/file_id/{fileId}/code', requirements: ['apiVersion' => '(v1)'])]
public function requestCodeByFileId(int $fileId, ?string $identifyMethod, ?string $signMethod, ?string $identify): DataResponse {
try {
Expand Down
3 changes: 3 additions & 0 deletions lib/Controller/SignatureElementsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public function getSignatureElements(): DataResponse {
#[NoAdminRequired]
#[PublicPage]
#[NoCSRFRequired]
#[RequestHeader(name: 'libresign-sign-request-uuid', description: 'The UUID of the sign request, used to identify the request', indirect: true)]
#[RequireSignRequestUuid(skipIfAuthenticated: true)]
#[ApiRoute(verb: 'GET', url: '/api/{apiVersion}/signature/elements/preview/{nodeId}', requirements: ['apiVersion' => '(v1)'])]
public function previewSignatureElement(int $nodeId) {
Expand Down Expand Up @@ -243,6 +244,7 @@ public function getSignatureElement(int $nodeId): DataResponse {
#[NoAdminRequired]
#[PublicPage]
#[NoCSRFRequired]
#[RequestHeader(name: 'libresign-sign-request-uuid', description: 'The UUID of the sign request, used to identify the request', indirect: true)]
#[RequireSignRequestUuid(skipIfAuthenticated: true)]
#[ApiRoute(verb: 'PATCH', url: '/api/{apiVersion}/signature/elements/{nodeId}', requirements: ['apiVersion' => '(v1)'])]
public function patchSignatureElement(int $nodeId, string $type = '', array $file = []): DataResponse {
Expand Down Expand Up @@ -300,6 +302,7 @@ public function patchSignatureElement(int $nodeId, string $type = '', array $fil
#[NoAdminRequired]
#[NoCSRFRequired]
#[PublicPage]
#[RequestHeader(name: 'libresign-sign-request-uuid', description: 'The UUID of the sign request, used to identify the request', indirect: true)]
#[RequireSignRequestUuid(skipIfAuthenticated: true)]
#[ApiRoute(verb: 'DELETE', url: '/api/{apiVersion}/signature/elements/{nodeId}', requirements: ['apiVersion' => '(v1)'])]
public function deleteSignatureElement(int $nodeId): DataResponse {
Expand Down
20 changes: 20 additions & 0 deletions src/tests/views/SignPDF/_partials/ModalVerificationCode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ describe('ModalVerificationCode requestCode route (#8365)', () => {
signStore.document = {
...signStore.document,
uuid: 'id-doc-file-uuid',
fileId: 42,
signers: [{ me: false, sign_request_uuid: 'external-signer-uuid', email: 'external@example.com' }],
settings: { isApprover: true },
} as typeof signStore.document
Expand All @@ -549,6 +550,7 @@ describe('ModalVerificationCode requestCode route (#8365)', () => {
signStore.document = {
...signStore.document,
uuid: 'file-uuid',
fileId: 42,
signers: [{ me: true, sign_request_uuid: 'my-signer-uuid' }],
settings: { isApprover: false },
} as typeof signStore.document
Expand All @@ -565,6 +567,7 @@ describe('ModalVerificationCode requestCode route (#8365)', () => {
signStore.document = {
...signStore.document,
uuid: 'file-uuid',
fileId: 42,
signers: [{ me: true, sign_request_uuid: 'my-signer-uuid' }],
settings: { isApprover: true },
} as typeof signStore.document
Expand All @@ -575,4 +578,21 @@ describe('ModalVerificationCode requestCode route (#8365)', () => {
const [url] = vi.mocked(axios.post).mock.calls[0]
expect(url).toBe('/ocs/v2.php/apps/libresign/api/v1/sign/uuid/my-signer-uuid/code')
})
it('does not request a code with fileId alone when signer UUID is unavailable', async () => {
const signStore = useSignStore()
signStore.document = {
...signStore.document,
fileId: 42,
uuid: 'file-uuid',
signers: [],
settings: { isApprover: false },
} as typeof signStore.document

const wrapper = mountToken()
await wrapper.vm.requestCode()

expect(axios.post).not.toHaveBeenCalled()
expect(wrapper.vm.tokenRequested).toBe(false)
expect(wrapper.vm.loading).toBe(false)
})
})
22 changes: 7 additions & 15 deletions src/views/SignPDF/_partials/ModalVerificationCode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ import md5 from 'blueimp-md5'
import axios from '@nextcloud/axios'
import { showError } from '@nextcloud/dialogs'
import { loadState } from '@nextcloud/initial-state'
import { generateOcsUrl } from '@nextcloud/router'

import NcButton from '@nextcloud/vue/components/NcButton'
import NcDialog from '@nextcloud/vue/components/NcDialog'
Expand Down Expand Up @@ -390,21 +389,14 @@ async function requestCode() {
signMethod: activeTokenMethod.value,
}

if (signStore.document.fileId) {
await axios.post(
generateOcsUrl('/apps/libresign/api/v1/sign/file_id/{fileId}/code', {
fileId: signStore.document.fileId,
}),
params,
)
} else {
// Same route/context decision as signing (Sign.vue).
const signRequestUuid = getSigningRouteUuid(signStore.document)
if (!signRequestUuid) {
throw new Error(t('libresign', 'Document not found'))
}
await axios.post(signStore.buildRequestCodeUrl(signRequestUuid), params)
// Resolve signer or approver context even when a fileId is available.
// Both verification code routes require a UUID in the signing middleware.
const signRequestUuid = getSigningRouteUuid(signStore.document)
if (!signRequestUuid) {
// TRANSLATORS Error when the document has no usable signing context.
throw new Error(t('libresign', 'Document not found'))
}
await axios.post(signStore.buildRequestCodeUrl(signRequestUuid), params)

if (props.mode === 'email') {
signMethodsStore.setHasEmailConfirmCode(true)
Expand Down
Loading