-
Notifications
You must be signed in to change notification settings - Fork 118
feat: add support for comments in forms #3329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\Forms\Listener; | ||
|
|
||
| use OCA\Forms\Db\FormMapper; | ||
| use OCP\AppFramework\Db\DoesNotExistException; | ||
| use OCP\Comments\CommentsEntityEvent; | ||
| use OCP\EventDispatcher\Event; | ||
| use OCP\EventDispatcher\IEventListener; | ||
|
|
||
| /** | ||
| * @template-implements IEventListener<Event> | ||
| */ | ||
| class CommentsEntityListener implements IEventListener { | ||
| public function __construct( | ||
| protected FormMapper $formMapper, | ||
| ) { | ||
| } | ||
|
|
||
| #[\Override] | ||
| public function handle(Event $event): void { | ||
| if (!$event instanceof CommentsEntityEvent) { | ||
| return; | ||
| } | ||
|
|
||
| // Register the 'forms' entity collection so the Comments app can | ||
| // check whether a given form id allows comments. | ||
| $event->addEntityCollection('forms', function ($formId) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I can tell this callback is the only thing the comments layer checks before letting someone read or write. Checking just
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes this makes sense, we should check here if the current user:
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't limit comments to the owner or shared admins but to all logged in users with access to the form. The use case of the feature request was for allowing communication between respondents.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes that what I meant we still would need the check:
Because otherwise some user could read comments of a form where he does not have access to
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes that's right. I first thought that you meant only shared edit permissions |
||
| try { | ||
| $form = $this->formMapper->findById((int)$formId); | ||
| } catch (DoesNotExistException $e) { | ||
| return false; | ||
| } | ||
| return (bool)$form->getAllowComments(); | ||
| }); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\Forms\Migration; | ||
|
|
||
| use Closure; | ||
| use OCP\DB\ISchemaWrapper; | ||
| use OCP\DB\Types; | ||
| use OCP\Migration\IOutput; | ||
| use OCP\Migration\SimpleMigrationStep; | ||
| use Override; | ||
|
|
||
| class Version050300Date20260511121033 extends SimpleMigrationStep { | ||
|
|
||
| /** | ||
| * @param IOutput $output | ||
| * @param Closure(): ISchemaWrapper $schemaClosure | ||
| * @param array $options | ||
| * @return null|ISchemaWrapper | ||
| */ | ||
| #[Override] | ||
| public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { | ||
| /** @var ISchemaWrapper $schema */ | ||
| $schema = $schemaClosure(); | ||
| $table = $schema->getTable('forms_v2_forms'); | ||
| $changed = false; | ||
|
|
||
| if (!$table->hasColumn('allow_comments')) { | ||
| $table->addColumn('allow_comments', Types::BOOLEAN, [ | ||
| 'notnull' => false, | ||
| 'default' => 0, | ||
| ]); | ||
| $changed = true; | ||
| } | ||
|
|
||
| return $changed ? $schema : null; | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.