2023-08-30 12:37:08 +02:00
|
|
|
<?php
|
|
|
|
|
|
2024-06-05 15:35:46 +02:00
|
|
|
namespace App\Integrations\Handlers;
|
2023-08-30 12:37:08 +02:00
|
|
|
|
Email spam security (#641)
* Add hCaptcha on register page
* register page captcha test cases
* Refactor integration validation rules to include form context
- Updated the `getValidationRules` method in various integration handlers (Discord, Email, Google Sheets, Slack, Webhook, Zapier) to accept an optional `Form` parameter, allowing for context-aware validation.
- Enhanced the `EmailIntegration` handler to enforce restrictions based on user plans, ensuring free users can only create one email integration per form and can only send to a single email address.
- Added a new test suite for `EmailIntegration` to validate the new restrictions and ensure proper functionality for both free and pro users.
- Introduced loading state management in the `IntegrationModal` component to improve user experience during save operations.
These changes improve the flexibility and user experience of form integrations, particularly for email handling.
* for self-hosted ignore emil validation for spam
* fix pint
* ignore register throttle for testing env
* support new migration for mysql also
* Register page captcha enable if captcha key set
* fix test case
* fix test case
* fix test case
* fix pint
* Refactor RegisterController middleware and update TestCase setup
- Removed environment check for throttling middleware in RegisterController, ensuring consistent rate limiting for the registration endpoint.
- Updated TestCase to disable throttle middleware during tests, allowing for more flexible testing scenarios without rate limiting interference.
* Enhance hCaptcha integration in tests and configuration
- Added hCaptcha site and secret keys to phpunit.xml for testing purposes.
- Updated RegisterTest to configure hCaptcha secret key dynamically, ensuring proper token validation in production environment.
These changes improve the testing setup for hCaptcha, facilitating more accurate simulation of production conditions.
---------
Co-authored-by: Julien Nahum <julien@nahum.net>
2024-12-18 13:16:27 +01:00
|
|
|
use App\Models\Forms\Form;
|
2024-10-22 10:34:29 +02:00
|
|
|
use App\Open\MentionParser;
|
2023-08-30 12:37:08 +02:00
|
|
|
use App\Service\Forms\FormSubmissionFormatter;
|
2023-08-30 14:20:14 +02:00
|
|
|
use Illuminate\Support\Arr;
|
2024-02-23 11:54:12 +01:00
|
|
|
use Vinkla\Hashids\Facades\Hashids;
|
2023-08-30 12:37:08 +02:00
|
|
|
|
2024-03-28 18:14:30 +01:00
|
|
|
class SlackIntegration extends AbstractIntegrationHandler
|
2023-08-30 12:37:08 +02:00
|
|
|
{
|
Email spam security (#641)
* Add hCaptcha on register page
* register page captcha test cases
* Refactor integration validation rules to include form context
- Updated the `getValidationRules` method in various integration handlers (Discord, Email, Google Sheets, Slack, Webhook, Zapier) to accept an optional `Form` parameter, allowing for context-aware validation.
- Enhanced the `EmailIntegration` handler to enforce restrictions based on user plans, ensuring free users can only create one email integration per form and can only send to a single email address.
- Added a new test suite for `EmailIntegration` to validate the new restrictions and ensure proper functionality for both free and pro users.
- Introduced loading state management in the `IntegrationModal` component to improve user experience during save operations.
These changes improve the flexibility and user experience of form integrations, particularly for email handling.
* for self-hosted ignore emil validation for spam
* fix pint
* ignore register throttle for testing env
* support new migration for mysql also
* Register page captcha enable if captcha key set
* fix test case
* fix test case
* fix test case
* fix pint
* Refactor RegisterController middleware and update TestCase setup
- Removed environment check for throttling middleware in RegisterController, ensuring consistent rate limiting for the registration endpoint.
- Updated TestCase to disable throttle middleware during tests, allowing for more flexible testing scenarios without rate limiting interference.
* Enhance hCaptcha integration in tests and configuration
- Added hCaptcha site and secret keys to phpunit.xml for testing purposes.
- Updated RegisterTest to configure hCaptcha secret key dynamically, ensuring proper token validation in production environment.
These changes improve the testing setup for hCaptcha, facilitating more accurate simulation of production conditions.
---------
Co-authored-by: Julien Nahum <julien@nahum.net>
2024-12-18 13:16:27 +01:00
|
|
|
public static function getValidationRules(?Form $form): array
|
2023-08-30 12:37:08 +02:00
|
|
|
{
|
2024-03-28 18:14:30 +01:00
|
|
|
return [
|
|
|
|
|
'slack_webhook_url' => 'required|url|starts_with:https://hooks.slack.com/',
|
|
|
|
|
'include_submission_data' => 'boolean',
|
2024-12-30 11:11:17 +01:00
|
|
|
'include_hidden_fields_submission_data' => ['nullable', 'boolean'],
|
2024-03-28 18:14:30 +01:00
|
|
|
'link_open_form' => 'boolean',
|
|
|
|
|
'link_edit_form' => 'boolean',
|
|
|
|
|
'views_submissions_count' => 'boolean',
|
|
|
|
|
'link_edit_submission' => 'boolean'
|
|
|
|
|
];
|
2023-08-30 12:37:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getWebhookUrl(): ?string
|
|
|
|
|
{
|
2024-03-28 18:14:30 +01:00
|
|
|
return $this->integrationData->slack_webhook_url;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function shouldRun(): bool
|
|
|
|
|
{
|
|
|
|
|
return !is_null($this->getWebhookUrl()) && $this->form->is_pro && parent::shouldRun();
|
2023-08-30 12:37:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getWebhookData(): array
|
|
|
|
|
{
|
2024-12-30 11:11:17 +01:00
|
|
|
$settings = (array) $this->integrationData ?? [];
|
|
|
|
|
|
2023-08-30 14:20:14 +02:00
|
|
|
$externalLinks = [];
|
2024-02-23 11:54:12 +01:00
|
|
|
if (Arr::get($settings, 'link_open_form', true)) {
|
2024-03-28 18:14:30 +01:00
|
|
|
$externalLinks[] = '*<' . $this->form->share_url . '|🔗 Open Form>*';
|
2023-08-30 14:20:14 +02:00
|
|
|
}
|
2024-02-23 11:54:12 +01:00
|
|
|
if (Arr::get($settings, 'link_edit_form', true)) {
|
2024-03-28 18:14:30 +01:00
|
|
|
$editFormURL = front_url('forms/' . $this->form->slug . '/show');
|
|
|
|
|
$externalLinks[] = '*<' . $editFormURL . '|✍️ Edit Form>*';
|
2023-08-30 14:20:14 +02:00
|
|
|
}
|
|
|
|
|
if (Arr::get($settings, 'link_edit_submission', true) && $this->form->editable_submissions) {
|
2024-03-28 18:14:30 +01:00
|
|
|
$submissionId = Hashids::encode($this->submissionData['submission_id']);
|
|
|
|
|
$externalLinks[] = '*<' . $this->form->share_url . '?submission_id=' . $submissionId . '|✍️ ' . $this->form->editable_submissions_button_text . '>*';
|
2023-08-30 12:37:08 +02:00
|
|
|
}
|
|
|
|
|
|
2025-04-02 11:10:35 +02:00
|
|
|
$formattedData = (new FormSubmissionFormatter($this->form, $this->submissionData))->outputStringsOnly()->showHiddenFields()->getFieldsWithValue();
|
2024-10-22 10:34:29 +02:00
|
|
|
$message = Arr::get($settings, 'message', 'New form submission');
|
2023-08-30 14:20:14 +02:00
|
|
|
$blocks = [
|
|
|
|
|
[
|
|
|
|
|
'type' => 'section',
|
|
|
|
|
'text' => [
|
|
|
|
|
'type' => 'mrkdwn',
|
2024-10-22 10:34:29 +02:00
|
|
|
'text' => (new MentionParser($message, $formattedData))->parse(),
|
2024-02-23 11:54:12 +01:00
|
|
|
],
|
|
|
|
|
],
|
2023-08-30 12:37:08 +02:00
|
|
|
];
|
2023-08-30 14:20:14 +02:00
|
|
|
|
2024-02-23 11:54:12 +01:00
|
|
|
if (Arr::get($settings, 'include_submission_data', true)) {
|
2025-04-02 11:10:35 +02:00
|
|
|
$formatter = (new FormSubmissionFormatter($this->form, $this->submissionData))->outputStringsOnly();
|
|
|
|
|
if (Arr::get($settings, 'include_hidden_fields_submission_data', false)) {
|
|
|
|
|
$formatter->showHiddenFields();
|
|
|
|
|
}
|
|
|
|
|
$formattedData = $formatter->getFieldsWithValue();
|
|
|
|
|
|
2023-08-30 14:20:14 +02:00
|
|
|
$submissionString = '';
|
2024-10-22 10:34:29 +02:00
|
|
|
foreach ($formattedData as $field) {
|
2023-08-30 14:20:14 +02:00
|
|
|
$tmpVal = is_array($field['value']) ? implode(',', $field['value']) : $field['value'];
|
2024-03-28 18:14:30 +01:00
|
|
|
$submissionString .= '>*' . ucfirst($field['name']) . '*: ' . $tmpVal . " \n";
|
2023-08-30 14:20:14 +02:00
|
|
|
}
|
|
|
|
|
$blocks[] = [
|
|
|
|
|
'type' => 'section',
|
|
|
|
|
'text' => [
|
|
|
|
|
'type' => 'mrkdwn',
|
|
|
|
|
'text' => $submissionString,
|
2024-02-23 11:54:12 +01:00
|
|
|
],
|
2023-08-30 14:20:14 +02:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-23 11:54:12 +01:00
|
|
|
if (Arr::get($settings, 'views_submissions_count', true)) {
|
2024-03-28 18:14:30 +01:00
|
|
|
$countString = '*👀 Views*: ' . (string) $this->form->views_count . " \n";
|
|
|
|
|
$countString .= '*🖊️ Submissions*: ' . (string) $this->form->submissions_count;
|
2023-08-30 14:20:14 +02:00
|
|
|
$blocks[] = [
|
|
|
|
|
'type' => 'section',
|
|
|
|
|
'text' => [
|
|
|
|
|
'type' => 'mrkdwn',
|
|
|
|
|
'text' => $countString,
|
2024-02-23 11:54:12 +01:00
|
|
|
],
|
2023-08-30 14:20:14 +02:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-23 11:54:12 +01:00
|
|
|
if (count($externalLinks) > 0) {
|
2023-08-30 14:20:14 +02:00
|
|
|
$blocks[] = [
|
|
|
|
|
'type' => 'section',
|
|
|
|
|
'text' => [
|
|
|
|
|
'type' => 'mrkdwn',
|
|
|
|
|
'text' => implode(' ', $externalLinks),
|
2024-02-23 11:54:12 +01:00
|
|
|
],
|
2023-08-30 14:20:14 +02:00
|
|
|
];
|
2023-08-30 12:37:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return [
|
2024-02-23 11:54:12 +01:00
|
|
|
'blocks' => $blocks,
|
2023-08-30 12:37:08 +02:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|