From 5e06626ba1828920ed03698746dce0bb2ae8c75d Mon Sep 17 00:00:00 2001 From: global-prog Date: Wed, 9 Sep 2026 04:12:45 +0300 Subject: [PATCH 1/8] feat: image and video blocks Adds two display-only blocks so a form can show a picture or point at a video between its questions, rather than only text. They are modelled as ordinary question types that happen to carry no answer, which keeps them in the existing ordering and drag-and-drop with no new concepts. A shared ANSWER_TYPES_DISPLAY_ONLY list marks them so they are skipped when validating a submission and filtered out of exports - without that, each block would add an empty column to every CSV. Video is deliberately NOT embedded in an iframe. Embedding makes every respondent's browser contact the video host on page load, disclosing their IP address and usually setting cookies, which would quietly undermine a form marked as anonymous. It renders as a link the respondent chooses to follow. Images do render inline, since that is the point of an image block, but with referrerpolicy="no-referrer" so the form's address is not passed on, and the editor warns when the address is not on this instance. No schema change: the address and description live in the existing extraSettings. FormsQuestionType is left alone, matching how linearscale, ranking and color are already handled, so openapi.json is unaffected. Signed-off-by: global-prog --- lib/Constants.php | 21 +++ lib/Service/FormsService.php | 2 + lib/Service/SubmissionService.php | 16 ++ src/components/Questions/QuestionMedia.vue | 168 +++++++++++++++++++++ src/models/AnswerTypes.ts | 27 ++++ 5 files changed, 234 insertions(+) create mode 100644 src/components/Questions/QuestionMedia.vue diff --git a/lib/Constants.php b/lib/Constants.php index 5debb548b..1ea51e6e4 100644 --- a/lib/Constants.php +++ b/lib/Constants.php @@ -110,9 +110,11 @@ class Constants { public const ANSWER_TYPE_LONG = 'long'; public const ANSWER_TYPE_MULTIPLE = 'multiple'; public const ANSWER_TYPE_MULTIPLEUNIQUE = 'multiple_unique'; + public const ANSWER_TYPE_IMAGE = 'image'; public const ANSWER_TYPE_RANKING = 'ranking'; public const ANSWER_TYPE_SHORT = 'short'; public const ANSWER_TYPE_TIME = 'time'; + public const ANSWER_TYPE_VIDEO = 'video'; public const ANSWER_GRID_TYPE_CHECKBOX = 'checkbox'; public const ANSWER_GRID_TYPE_NUMBER = 'number'; @@ -149,9 +151,11 @@ class Constants { self::ANSWER_TYPE_LONG, self::ANSWER_TYPE_MULTIPLE, self::ANSWER_TYPE_MULTIPLEUNIQUE, + self::ANSWER_TYPE_IMAGE, self::ANSWER_TYPE_RANKING, self::ANSWER_TYPE_SHORT, self::ANSWER_TYPE_TIME, + self::ANSWER_TYPE_VIDEO, ]; // AnswerTypes, that need/have predefined Options @@ -276,6 +280,23 @@ class Constants { 'next' => ['integer', 'string'], ]; + /** + * Display-only blocks carry no answer; they only reference something to show. + */ + public const EXTRA_SETTINGS_MEDIA = [ + 'url' => ['string', 'NULL'], + 'alt' => ['string', 'NULL'], + ]; + + /** + * Question types that are shown but never answered, so they are skipped when + * validating a submission and left out of exports. + */ + public const ANSWER_TYPES_DISPLAY_ONLY = [ + self::ANSWER_TYPE_IMAGE, + self::ANSWER_TYPE_VIDEO, + ]; + public const EXTRA_SETTINGS_RANKING = [ 'shuffleOptions' => ['boolean'], 'next' => ['integer', 'string'], diff --git a/lib/Service/FormsService.php b/lib/Service/FormsService.php index 086d2582b..3925d1031 100644 --- a/lib/Service/FormsService.php +++ b/lib/Service/FormsService.php @@ -905,6 +905,8 @@ public static function getAllowedExtraSettings(string $questionType): array { Constants::ANSWER_TYPE_FILE => Constants::EXTRA_SETTINGS_FILE, Constants::ANSWER_TYPE_DATE => Constants::EXTRA_SETTINGS_DATE, Constants::ANSWER_TYPE_GRID => Constants::EXTRA_SETTINGS_GRID, + Constants::ANSWER_TYPE_IMAGE => Constants::EXTRA_SETTINGS_MEDIA, + Constants::ANSWER_TYPE_VIDEO => Constants::EXTRA_SETTINGS_MEDIA, Constants::ANSWER_TYPE_RANKING => Constants::EXTRA_SETTINGS_RANKING, Constants::ANSWER_TYPE_COLOR => Constants::EXTRA_SETTINGS_COLOR, Constants::ANSWER_TYPE_TIME => Constants::EXTRA_SETTINGS_TIME, diff --git a/lib/Service/SubmissionService.php b/lib/Service/SubmissionService.php index 850e964f2..f0834b53b 100644 --- a/lib/Service/SubmissionService.php +++ b/lib/Service/SubmissionService.php @@ -265,6 +265,16 @@ public function getSubmissionsData(Form $form, string $fileFormat, ?File $file = $submissionEntities = array_reverse($submissionEntities); $questions = $this->questionMapper->findByForm($form->getId()); + // Display-only blocks hold no answers; leaving them in would add an empty column + // per block to every export. + $questions = array_values(array_filter( + $questions, + static fn ($question): bool => !in_array( + $question->getType(), + Constants::ANSWER_TYPES_DISPLAY_ONLY, + true, + ), + )); $activeQuestionIds = $this->getActiveQuestionIds($questions); @@ -691,6 +701,12 @@ public function validateSubmission(array $questions, array $answers, string $for throw new \InvalidArgumentException(sprintf('Invalid answer for question "%s".', $question['text'])); } + // Display-only blocks are never answered, so they must not be treated as an + // unanswered mandatory question. + if (in_array($question['type'], Constants::ANSWER_TYPES_DISPLAY_ONLY, true)) { + continue; + } + // Check if all required questions have an answer if (!empty($question['isRequired']) && self::isShownToRespondents($question) diff --git a/src/components/Questions/QuestionMedia.vue b/src/components/Questions/QuestionMedia.vue new file mode 100644 index 000000000..f5d04c8b8 --- /dev/null +++ b/src/components/Questions/QuestionMedia.vue @@ -0,0 +1,168 @@ + + + + + + + diff --git a/src/models/AnswerTypes.ts b/src/models/AnswerTypes.ts index d0cebc0eb..225ce63b0 100644 --- a/src/models/AnswerTypes.ts +++ b/src/models/AnswerTypes.ts @@ -12,12 +12,14 @@ import IconCalendar from '@material-symbols/svg-400/outlined/calendar_today.svg? import IconCheckboxOutline from '@material-symbols/svg-400/outlined/check_box.svg?raw' import IconFile from '@material-symbols/svg-400/outlined/draft.svg?raw' import IconGrid from '@material-symbols/svg-400/outlined/grid_view.svg?raw' +import IconImage from '@material-symbols/svg-400/outlined/image.svg?raw' import IconLinearScale from '@material-symbols/svg-400/outlined/linear_scale.svg?raw' import IconPalette from '@material-symbols/svg-400/outlined/palette.svg?raw' import IconRadioboxMarked from '@material-symbols/svg-400/outlined/radio_button_checked.svg?raw' import IconRecommend from '@material-symbols/svg-400/outlined/recommend.svg?raw' import IconClockOutline from '@material-symbols/svg-400/outlined/schedule.svg?raw' import IconTextShort from '@material-symbols/svg-400/outlined/short_text.svg?raw' +import IconVideo from '@material-symbols/svg-400/outlined/smart_display.svg?raw' import IconStar from '@material-symbols/svg-400/outlined/star.svg?raw' import IconTextLong from '@material-symbols/svg-400/outlined/subject.svg?raw' import IconSwapVertical from '@material-symbols/svg-400/outlined/swap_vert.svg?raw' @@ -30,6 +32,7 @@ import QuestionFile from '../components/Questions/QuestionFile.vue' import QuestionGrid from '../components/Questions/QuestionGrid.vue' import QuestionLinearScale from '../components/Questions/QuestionLinearScale.vue' import QuestionLong from '../components/Questions/QuestionLong.vue' +import QuestionMedia from '../components/Questions/QuestionMedia.vue' import QuestionMultiple from '../components/Questions/QuestionMultiple.vue' import QuestionRanking from '../components/Questions/QuestionRanking.vue' import QuestionShort from '../components/Questions/QuestionShort.vue' @@ -57,6 +60,8 @@ export interface AnswerTypeConfig { warningInvalid: string unique?: boolean subtypes?: Record + /** Which media a display-only block shows. */ + mediaKind?: 'image' | 'video' pickerType?: string storageFormat?: string momentFormat?: string @@ -292,6 +297,28 @@ const answerTypes: Record = { warningInvalid: t('forms', 'This question needs a title!'), }, + image: { + component: markRaw(QuestionMedia), + icon: IconImage, + label: t('forms', 'Image'), + predefined: false, + mediaKind: 'image', + + titlePlaceholder: t('forms', 'Image caption'), + warningInvalid: t('forms', 'This block needs a caption!'), + }, + + video: { + component: markRaw(QuestionMedia), + icon: IconVideo, + label: t('forms', 'Video'), + predefined: false, + mediaKind: 'video', + + titlePlaceholder: t('forms', 'Video caption'), + warningInvalid: t('forms', 'This block needs a caption!'), + }, + color: { component: markRaw(QuestionColor), icon: IconPalette, From 15cb8383b76c11bdebbb83585074e3d3c4f68a8b Mon Sep 17 00:00:00 2001 From: global-prog Date: Fri, 11 Sep 2026 17:27:35 +0300 Subject: [PATCH 2/8] fix: refuse an answer submitted to an image or video block A display-only block was skipped during validation whether or not an answer came with it, so a hand-made request could store an answer against a block that has nowhere to show it. An absent answer is still expected -- and still must not count as a missing required one -- but a present answer is now refused. The submit view never sends one for these blocks, since they emit no value, so this changes nothing for a form filled in normally. Adds tests for both halves, and for the image and video settings accepted by areExtraSettingsValid, which were not exercised before. Signed-off-by: global-prog --- lib/Service/SubmissionService.php | 9 +++- tests/Unit/Service/FormsServiceTest.php | 31 +++++++++++++ tests/Unit/Service/SubmissionServiceTest.php | 48 ++++++++++++++++++++ 3 files changed, 86 insertions(+), 2 deletions(-) diff --git a/lib/Service/SubmissionService.php b/lib/Service/SubmissionService.php index f0834b53b..f7ac81f9c 100644 --- a/lib/Service/SubmissionService.php +++ b/lib/Service/SubmissionService.php @@ -701,9 +701,14 @@ public function validateSubmission(array $questions, array $answers, string $for throw new \InvalidArgumentException(sprintf('Invalid answer for question "%s".', $question['text'])); } - // Display-only blocks are never answered, so they must not be treated as an - // unanswered mandatory question. + // Display-only blocks take no answer. An absent answer is therefore expected and + // must not count as an unanswered mandatory question -- but a present one is + // refused outright rather than skipped, since nothing else would stop it being + // stored against a block that has nowhere to show it. if (in_array($question['type'], Constants::ANSWER_TYPES_DISPLAY_ONLY, true)) { + if ($questionAnswered) { + throw new \InvalidArgumentException(sprintf('Question "%s" does not take an answer.', $question['text'])); + } continue; } diff --git a/tests/Unit/Service/FormsServiceTest.php b/tests/Unit/Service/FormsServiceTest.php index 67747a10a..64ba4c1c4 100644 --- a/tests/Unit/Service/FormsServiceTest.php +++ b/tests/Unit/Service/FormsServiceTest.php @@ -1827,6 +1827,37 @@ public static function dataAreExtraSettingsValid() { 'questionType' => Constants::ANSWER_TYPE_SHORT, 'expected' => false, ], + 'valid-image-settings' => [ + 'extraSettings' => [ + 'url' => 'https://example.com/picture.png', + 'alt' => 'A picture', + ], + 'questionType' => Constants::ANSWER_TYPE_IMAGE, + 'expected' => true + ], + 'valid-video-settings' => [ + 'extraSettings' => [ + 'url' => 'https://example.com/clip', + ], + 'questionType' => Constants::ANSWER_TYPE_VIDEO, + 'expected' => true + ], + 'invalid-image-key' => [ + // A block has no answer, so the answer-shaping settings of other types + // must not be accepted on it. + 'extraSettings' => [ + 'shuffleOptions' => true, + ], + 'questionType' => Constants::ANSWER_TYPE_IMAGE, + 'expected' => false + ], + 'invalid-video-type' => [ + 'extraSettings' => [ + 'url' => ['not', 'a', 'string'], + ], + 'questionType' => Constants::ANSWER_TYPE_VIDEO, + 'expected' => false + ], 'empty-extra-settings' => [ 'extraSettings' => [], 'questionType' => Constants::ANSWER_TYPE_LONG, diff --git a/tests/Unit/Service/SubmissionServiceTest.php b/tests/Unit/Service/SubmissionServiceTest.php index 29780a9ad..e16e6a7b1 100644 --- a/tests/Unit/Service/SubmissionServiceTest.php +++ b/tests/Unit/Service/SubmissionServiceTest.php @@ -1136,6 +1136,54 @@ public static function dataValidateSubmission() { // Expected Result null, ], + 'display-only-block-not-answered' => [ + // Questions + [ + ['id' => 1, 'type' => 'image', 'text' => 'picture', 'isRequired' => false], + ['id' => 2, 'type' => 'short', 'text' => 'q2', 'isRequired' => true], + ], + // Answers + [ + '2' => ['answer'], + ], + // Expected Result + null, + ], + 'display-only-block-marked-required' => [ + // Questions -- a block can never be answered, so a stray required flag must + // not make the whole form impossible to submit. + [ + ['id' => 1, 'type' => 'video', 'text' => 'clip', 'isRequired' => true], + ], + // Answers + [], + // Expected Result + null, + ], + 'display-only-image-answered' => [ + // Questions + [ + ['id' => 1, 'type' => 'image', 'text' => 'picture', 'isRequired' => false], + ], + // Answers + [ + '1' => ['anything'], + ], + // Expected Result + 'Question "picture" does not take an answer.', + ], + 'display-only-video-answered' => [ + // Questions + [ + ['id' => 1, 'type' => 'video', 'text' => 'clip', 'isRequired' => false], + ], + // Answers + [ + '1' => ['anything'], + ], + // Expected Result + 'Question "clip" does not take an answer.', + ], 'required-not-answered' => [ // Questions [ From 425259d68c39405b5338ece83292e20ee4697035 Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Fri, 27 Nov 2026 14:59:06 +0100 Subject: [PATCH 3/8] feat(media): play YouTube and Vimeo videos after consent A video block was only a link. For YouTube and Vimeo addresses it now shows a placeholder that names the provider and explains that playing the video discloses the viewer's IP address and may set cookies. The player loads only after the viewer clicks "Play video", from youtube-nocookie.com or with Vimeo's do-not-track flag. The link stays below it, and other addresses keep the plain link. The pages showing a form allow these two player origins as frames. Images on another site never loaded, because the content security policy only allows images from the instance. The editor now says that only images stored on this Nextcloud can be shown, and neither view renders a broken image any more. The warning about external addresses is gone, as nothing is loaded from them. The block's fields now line up with the title field in the editor, and the image and link align to the start like the other question content. The link is underlined so it reads as a link. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Andy Scherzinger --- lib/Constants.php | 8 + lib/Controller/PageController.php | 24 ++- src/components/Questions/QuestionMedia.vue | 147 ++++++++++++++++--- tests/Unit/Controller/PageControllerTest.php | 27 ++++ 4 files changed, 186 insertions(+), 20 deletions(-) diff --git a/lib/Constants.php b/lib/Constants.php index 1ea51e6e4..95808cd5b 100644 --- a/lib/Constants.php +++ b/lib/Constants.php @@ -288,6 +288,14 @@ class Constants { 'alt' => ['string', 'NULL'], ]; + /** + * Origins of the video players a video block may load after the respondent agrees. + */ + public const VIDEO_PLAYER_ORIGINS = [ + 'https://www.youtube-nocookie.com', + 'https://player.vimeo.com', + ]; + /** * Question types that are shown but never answered, so they are skipped when * validating a submission and left out of exports. diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index ef0b54e5b..4aa105fa4 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -85,10 +85,13 @@ public function index(?string $hash = null): TemplateResponse { } } - return new TemplateResponse($this->appName, self::TEMPLATE_MAIN, [ + $response = new TemplateResponse($this->appName, self::TEMPLATE_MAIN, [ 'id-app-content' => '#app-content-vue', 'id-app-navigation' => '#app-navigation-vue', ]); + $response->setContentSecurityPolicy($this->createPolicy()); + + return $response; } /** @@ -219,7 +222,10 @@ protected function createPublicSubmitView(Form $form, string $hash): TemplateRes $this->initialState->provideInitialState('isLoggedIn', $this->userSession->isLoggedIn()); $this->initialState->provideInitialState('shareHash', $hash); $this->initialState->provideInitialState('maxStringLengths', Constants::MAX_STRING_LENGTHS); - return $this->provideTemplate(self::TEMPLATE_MAIN, $form, ['id-app-navigation' => null]); + $response = $this->provideTemplate(self::TEMPLATE_MAIN, $form, ['id-app-navigation' => null]); + $response->setContentSecurityPolicy($this->createPolicy()); + + return $response; } /** @@ -293,13 +299,25 @@ protected function insertHeaderOnIos(): void { } } + /** + * Create the CSP for pages showing a form, allowing the players of video blocks as frames + */ + protected function createPolicy(): ContentSecurityPolicy { + $policy = new ContentSecurityPolicy(); + foreach (Constants::VIDEO_PLAYER_ORIGINS as $origin) { + $policy->addAllowedFrameDomain($origin); + } + + return $policy; + } + /** * Set CSP options to allow the page be embedded using