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
60 changes: 45 additions & 15 deletions lib/Service/FormsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use OCP\Search\ISearchQuery;
use OCP\Security\ISecureRandom;
use OCP\Share\IShare;
use Psr\Log\LoggerInterface;

/**
* Trait for getting forms information in a service
Expand Down Expand Up @@ -62,6 +63,7 @@
private IRootFolder $rootFolder,
private IL10N $l10n,
private IEventDispatcher $eventDispatcher,
private LoggerInterface $logger,
) {
$this->currentUser = $userSession->getUser();
}
Expand Down Expand Up @@ -562,19 +564,30 @@
* @param Share $share The new Share
*/
public function notifyNewShares(Form $form, Share $share): void {
switch ($share->getShareType()) {
case IShare::TYPE_USER:
$this->activityManager->publishNewShare($form, $share->getShareWith());
break;
case IShare::TYPE_GROUP:
$this->activityManager->publishNewGroupShare($form, $share->getShareWith());
break;
case IShare::TYPE_CIRCLE:
$this->activityManager->publishNewCircleShare($form, $share->getShareWith());
break;
default:
// Do nothing.
try {
switch ($share->getShareType()) {
case IShare::TYPE_USER:
$this->activityManager->publishNewShare($form, $share->getShareWith());
break;
case IShare::TYPE_GROUP:
$this->activityManager->publishNewGroupShare($form, $share->getShareWith());
break;
case IShare::TYPE_CIRCLE:
$this->activityManager->publishNewCircleShare($form, $share->getShareWith());
break;
default:
// Do nothing.
}
} catch (\Exception $e) {

Check warning on line 581 in lib/Service/FormsService.php

View check run for this annotation

Codecov / codecov/patch

lib/Service/FormsService.php#L581

Added line #L581 was not covered by tests
// Handle exceptions silently, as this is not critical.
// We don't want to break the share creation process just because of an activity error.
$this->logger->error(
'Error while publishing new share activity',
[$e]
);

Check warning on line 587 in lib/Service/FormsService.php

View check run for this annotation

Codecov / codecov/patch

lib/Service/FormsService.php#L584-L587

Added lines #L584 - L587 were not covered by tests

}

}

/**
Expand All @@ -585,14 +598,31 @@
*/
public function notifyNewSubmission(Form $form, Submission $submission): void {
$shares = $this->getShares($form->getId());
$this->activityManager->publishNewSubmission($form, $submission->getUserId());
try {
$this->activityManager->publishNewSubmission($form, $submission->getUserId());
} catch (\Exception $e) {

Check warning on line 603 in lib/Service/FormsService.php

View check run for this annotation

Codecov / codecov/patch

lib/Service/FormsService.php#L603

Added line #L603 was not covered by tests
// Handle exceptions silently, as this is not critical.
// We don't want to break the submission process just because of an activity error.
$this->logger->error(
'Error while publishing new submission activity',
[$e]
);

Check warning on line 609 in lib/Service/FormsService.php

View check run for this annotation

Codecov / codecov/patch

lib/Service/FormsService.php#L606-L609

Added lines #L606 - L609 were not covered by tests
}

foreach ($shares as $share) {
if (!in_array(Constants::PERMISSION_RESULTS, $share['permissions'])) {
continue;
}

$this->activityManager->publishNewSharedSubmission($form, $share['shareType'], $share['shareWith'], $submission->getUserId());
try {
$this->activityManager->publishNewSharedSubmission($form, $share['shareType'], $share['shareWith'], $submission->getUserId());
} catch (\Exception $e) {

Check warning on line 618 in lib/Service/FormsService.php

View check run for this annotation

Codecov / codecov/patch

lib/Service/FormsService.php#L618

Added line #L618 was not covered by tests
// Handle exceptions silently, as this is not critical.
// We don't want to break the submission process just because of an activity error.
$this->logger->error(
'Error while publishing new shared submission activity',
[$e]
);

Check warning on line 624 in lib/Service/FormsService.php

View check run for this annotation

Codecov / codecov/patch

lib/Service/FormsService.php#L621-L624

Added lines #L621 - L624 were not covered by tests
}
}

$this->eventDispatcher->dispatchTyped(new FormSubmittedEvent($form, $submission));
Expand Down
19 changes: 14 additions & 5 deletions src/views/Submit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -818,12 +818,21 @@ export default {
this.deleteFormFieldFromLocalStorage()
emit('forms:last-updated:set', this.form.id)
} catch (error) {
const errorMessage = error.response?.data?.ocs?.meta?.message
logger.error('Error while submitting the form', { error })
showError(
t('forms', 'There was an error submitting the form: {message}', {
message: error.response.data.ocs.meta.message,
}),
)
if (errorMessage) {
showError(
t(
'forms',
'There was an error submitting the form: {message}',
{
message: errorMessage,
},
),
)
} else {
showError(t('forms', 'There was an error submitting the form'))
}
} finally {
this.loading = false
if (!this.publicView) {
Expand Down
11 changes: 10 additions & 1 deletion tests/Unit/Service/FormsServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ function microtime(bool|float $asFloat = false) {
use OCP\IUserSession;
use OCP\Security\ISecureRandom;
use OCP\Share\IShare;

use PHPUnit\Framework\MockObject\MockObject;

use Psr\Log\LoggerInterface;
use Test\TestCase;

class FormsServiceTest extends TestCase {
Expand Down Expand Up @@ -105,6 +106,8 @@ class FormsServiceTest extends TestCase {

/** @var IL10N|MockObject */
private $l10n;
/** @var LoggerInterface|MockObject */
private $logger;

public function setUp(): void {
parent::setUp();
Expand All @@ -120,6 +123,7 @@ public function setUp(): void {
$this->userManager = $this->createMock(IUserManager::class);
$this->secureRandom = $this->createMock(ISecureRandom::class);
$this->circlesService = $this->createMock(CirclesService::class);
$this->logger = $this->createMock(LoggerInterface::class);
$userSession = $this->createMock(IUserSession::class);

$user = $this->createMock(IUser::class);
Expand Down Expand Up @@ -155,6 +159,7 @@ public function setUp(): void {
$this->storage,
$this->l10n,
\OCP\Server::get(IEventDispatcher::class),
$this->logger,
);
}

Expand Down Expand Up @@ -632,6 +637,7 @@ public function testGetPermissions_NotLoggedIn() {
$this->storage,
$this->l10n,
\OCP\Server::get(IEventDispatcher::class),
$this->logger,
);

$form = new Form();
Expand Down Expand Up @@ -871,6 +877,7 @@ public function testPublicCanSubmit() {
$this->storage,
$this->l10n,
\OCP\Server::get(IEventDispatcher::class),
$this->logger,
);

$this->assertEquals(true, $formsService->canSubmit($form));
Expand Down Expand Up @@ -982,6 +989,7 @@ public function testHasUserAccess_NotLoggedIn() {
$this->storage,
$this->l10n,
\OCP\Server::get(IEventDispatcher::class),
$this->logger,
);

$form = new Form();
Expand Down Expand Up @@ -1213,6 +1221,7 @@ public function testNotifyNewSubmission($shares, $shareNotifications) {
$this->storage,
$this->l10n,
$eventDispatcher,
$this->logger,
])
->getMock();

Expand Down
Loading