Skip to content

Commit

Permalink
Merge branch 'v5' into feat/SFT-1608-form-monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavs-gutmanis committed Dec 16, 2024
2 parents 9e5b515 + 07d0a9d commit 9c76bfa
Show file tree
Hide file tree
Showing 31 changed files with 309 additions and 66 deletions.
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
# Solspace Freeform Changelog

## 5.8.3 - 2024-12-16

### Fixed
- Fixed a bug where the initial field value wasn't used in the Calculation field.
- Fixed an issue where the resource URLs for sample formatting templates were not fully compatible with Craft Cloud sites.
- Fixed a bug where **Status** was not available in Quick Export.
- Fixed issues with the Stripe webhook.
- Fixed a bug where the form builder **Usage in Elements** tab was not always loading correctly.

## 5.8.2 - 2024-12-11

### Fixed
- Fixed a bug where a user with individual form permissions would not have access to a form they just duplicated.
- Fixed a bug where the automatic purging of old submissions queue job could fail if an empty string was passed for an asset.

## 5.8.1 - 2024-12-10

### Added
- Added Italian translation.

### Changed
- Changed the _English_ translation from `en-US` to `en`.

### Fixed
- Fixed a bug where spammy submissions were still being saved to the database when the Spam Folder was disabled.
- Fixed a bug where fresh installs between 5.7.0 and 5.8.0 were missing a new `options` column in the `freeform_email_marketing_fields` and `freeform_crm_fields` database tables. Added a migration for affected installs.
- Fixed a bug where the form name link on the CP submission details page was not linked correctly.
- Fixed a bug where translations for the Error Log notice were missing.

## 5.8.0 - 2024-12-03

### Added
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "solspace/craft-freeform",
"description": "The most reliable form builder that's ready for wherever your project takes you.",
"version": "5.8.0",
"version": "5.8.3",
"type": "craft-plugin",
"authors": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public function removeSubmissionFiles(Event $event): void

if (\is_array($value)) {
foreach ($value as $id) {
\Craft::$app->elements->deleteElementById($id);
if (\is_int($id)) {
\Craft::$app->elements->deleteElementById($id);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ function (GenerateLinksEvent $event) {
$form = $event->getForm();
$data = $event->getFormData();

static $isSpamEnabled;
if (null === $isSpamEnabled) {
$isSpamEnabled = Freeform::getInstance()->settings->isSpamFolderEnabled();
}

$canManageForm = PermissionHelper::checkPermission(Freeform::PERMISSION_FORMS_MANAGE);
if (!$canManageForm) {
$canManageForm = PermissionHelper::checkPermission(
Expand Down Expand Up @@ -77,7 +82,7 @@ function (GenerateLinksEvent $event) {
$event->add(
$spam,
'spam',
$canManageSubmissions ? UrlHelper::cpUrl('freeform/spam?source=form:'.$form->getId()) : null,
$isSpamEnabled && $canManageSubmissions ? UrlHelper::cpUrl('freeform/spam?source=form:'.$form->getId()) : null,
'linkList',
$spamCount,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@

namespace Solspace\Freeform\Bundles\Persistence\Duplication;

use craft\db\Query;
use craft\db\Table;
use craft\helpers\StringHelper;
use craft\records\UserPermission;
use craft\records\UserPermission_User;
use craft\records\UserPermission_UserGroup;
use Solspace\Freeform\Attributes\Property\Input\Field;
use Solspace\Freeform\Attributes\Property\Input\Special\Properties\FieldMapping;
use Solspace\Freeform\Bundles\Attributes\Property\PropertyProvider;
use Solspace\Freeform\Fields\Implementations\Pro\GroupField;
use Solspace\Freeform\Form\Managers\ContentManager;
use Solspace\Freeform\Freeform;
use Solspace\Freeform\Library\Helpers\JsonHelper;
use Solspace\Freeform\Library\Helpers\StringHelper as FreeformStringHelper;
use Solspace\Freeform\Notifications\Types\Conditional\Conditional;
Expand Down Expand Up @@ -83,6 +89,7 @@ public function clone(int $id): bool
$this->cloneNotifications($id, $form);
$this->cloneRules($id, $form);
$this->cloneIntegrations($id, $form);
$this->updatePermissions($id, $form);

$form = $this->formsService->getFormById($form->id);

Expand Down Expand Up @@ -402,6 +409,66 @@ private function cloneIntegrations(int $originalId, FormRecord $form): void
}
}

private function updatePermissions(int $id, FormRecord $form): void
{
$userId = \Craft::$app->user->getIdentity()->id;
$permissions = [
Freeform::PERMISSION_SUBMISSIONS_READ,
Freeform::PERMISSION_SUBMISSIONS_MANAGE,
Freeform::PERMISSION_FORMS_MANAGE,
];

foreach ($permissions as $permissionName) {
$name = strtolower($permissionName.':'.$id);
$newName = strtolower($permissionName.':'.$form->id);

$permissionId = (int) (new Query())
->select('id')
->from(Table::USERPERMISSIONS)
->where(['name' => $name])
->scalar()
;

$groupIds = (new Query())
->select('groupId')
->from(Table::USERPERMISSIONS_USERGROUPS)
->where(['permissionId' => $permissionId])
->column()
;

$userPermissionId = (new Query())
->select('id')
->from(Table::USERPERMISSIONS_USERS)
->where([
'permissionId' => $permissionId,
'userId' => $userId,
])
->scalar()
;

$permission = UserPermission::find()->where(['name' => $newName])->one();
if (!$permission) {
$permission = new UserPermission();
$permission->name = $newName;
$permission->save();
}

if ($userPermissionId) {
$userPermission = new UserPermission_User();
$userPermission->userId = $userId;
$userPermission->permissionId = $permission->id;
$userPermission->save();
} else {
foreach ($groupIds as $groupId) {
$groupPermission = new UserPermission_UserGroup();
$groupPermission->groupId = $groupId;
$groupPermission->permissionId = $permission->id;
$groupPermission->save();
}
}
}
}

private function warmUpLayout(int $formId): void
{
$this->layouts = $this->fetchRecords(FormLayoutRecord::class, $formId);
Expand Down
23 changes: 23 additions & 0 deletions packages/plugin/src/Bundles/Spam/SpamBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@

use Solspace\Freeform\Elements\SpamSubmission;
use Solspace\Freeform\Elements\Submission;
use Solspace\Freeform\Events\Forms\SubmitEvent;
use Solspace\Freeform\Events\Submissions\ProcessSubmissionEvent;
use Solspace\Freeform\Form\Form;
use Solspace\Freeform\Library\Bundles\FeatureBundle;
use yii\base\Event;

class SpamBundle extends FeatureBundle
{
public function __construct()
{
Event::on(
Form::class,
Form::EVENT_SUBMIT,
[$this, 'onFormSubmit']
);

Event::on(
Submission::class,
Submission::EVENT_PROCESS_SUBMISSION,
Expand All @@ -24,6 +32,21 @@ public static function getPriority(): int
return 800;
}

public function onFormSubmit(SubmitEvent $event): void
{
$form = $event->getForm();
if (!$form->isMarkedAsSpam()) {
return;
}

$isSpamFolderEnabled = $this->plugin()->settings->isSpamFolderEnabled();
if ($isSpamFolderEnabled) {
return;
}

$event->isValid = false;
}

public function processSpamSubmission(ProcessSubmissionEvent $event): void
{
// TODO: refactor due to mailing list field changes
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/src/Integrations/Elements/User/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Setup Guide
This integration allows you to map Freeform submission data to [Craft User](https://craftcms.com/docs/4.x/users.html), essentially creating a powerful [User Registration form](https://docs.solspace.com/craft/freeform/v5/guides/user-registration-forms/).
This integration allows you to map Freeform submission data to [Craft User](https://craftcms.com/docs/4.x/users.html), essentially creating a powerful [User Registration form](https://docs.solspace.com/craft/freeform/v5/guides/speciality-forms/user-registration/).

<span class="note warning"><b>Important:</b> This feature requires a <b>Craft Pro</b> license in order to work, as Users are a Craft Pro feature.</span>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public function actionWebhooks(): Response
$json = json_decode($payload, false);
$header = $_SERVER['HTTP_STRIPE_SIGNATURE'] ?? null;

$hash = $json->data->object->metadata->hash;
$hash = $json->data->object->subscription_details->metadata->hash ?? $json->data->object->metadata->hash;

[, $integration] = $this->getRequestItems($hash);
$secret = $integration->getWebhookSecret();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class BasicDarkBundle extends AssetBundle
{
public function init(): void
{
$this->sourcePath = '@freeform-formatting-templates/basic-dark';
$this->sourcePath = '@Solspace/Freeform/templates/_templates/formatting/basic-dark';

$this->js = ['_main.js'];
$this->css = ['_main.css'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class BasicFloatingLabelsBundle extends AssetBundle
{
public function init(): void
{
$this->sourcePath = '@freeform-formatting-templates/basic-floating-labels';
$this->sourcePath = '@Solspace/Freeform/templates/_templates/formatting/basic-floating-labels';

$this->js = ['_main.js'];
$this->css = ['_main.css'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class BasicLightBundle extends AssetBundle
{
public function init(): void
{
$this->sourcePath = '@freeform-formatting-templates/basic-light';
$this->sourcePath = '@Solspace/Freeform/templates/_templates/formatting/basic-light';

$this->js = ['_main.js'];
$this->css = ['_main.css'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Bootstrap5Bundle extends AssetBundle
{
public function init(): void
{
$this->sourcePath = '@freeform-formatting-templates/bootstrap-5';
$this->sourcePath = '@Solspace/Freeform/templates/_templates/formatting/bootstrap-5';

$this->js = ['_main.js'];
$this->css = ['_main.css'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Bootstrap5DarkBundle extends AssetBundle
{
public function init(): void
{
$this->sourcePath = '@freeform-formatting-templates/bootstrap-5-dark';
$this->sourcePath = '@Solspace/Freeform/templates/_templates/formatting/bootstrap-5-dark';

$this->js = ['_main.js'];
$this->css = ['_main.css'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Bootstrap5FloatingLabelsBundle extends AssetBundle
{
public function init(): void
{
$this->sourcePath = '@freeform-formatting-templates/bootstrap-5-floating-labels';
$this->sourcePath = '@Solspace/Freeform/templates/_templates/formatting/bootstrap-5-floating-labels';

$this->js = ['_main.js'];
$this->css = ['_main.css'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ConversationalBundle extends AssetBundle
{
public function init(): void
{
$this->sourcePath = '@freeform-formatting-templates/conversational';
$this->sourcePath = '@Solspace/Freeform/templates/_templates/formatting/conversational';

$this->js = ['_main.js'];
$this->css = ['_main.css'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class FlexboxBundle extends AssetBundle
{
public function init(): void
{
$this->sourcePath = '@freeform-formatting-templates/flexbox';
$this->sourcePath = '@Solspace/Freeform/templates/_templates/formatting/flexbox';

$this->js = ['_main.js'];
$this->css = ['_main.css'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Foundation6Bundle extends AssetBundle
{
public function init(): void
{
$this->sourcePath = '@freeform-formatting-templates/foundation-6';
$this->sourcePath = '@Solspace/Freeform/templates/_templates/formatting/foundation-6';

$this->js = ['_main.js'];
$this->css = ['_main.css'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class GridBundle extends AssetBundle
{
public function init(): void
{
$this->sourcePath = '@freeform-formatting-templates/grid';
$this->sourcePath = '@Solspace/Freeform/templates/_templates/formatting/grid';

$this->js = ['_main.js'];
$this->css = ['_main.css'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class MultipageAllFieldsBundle extends AssetBundle
{
public function init(): void
{
$this->sourcePath = '@freeform-formatting-templates/multipage-all-fields';
$this->sourcePath = '@Solspace/Freeform/templates/_templates/formatting/multipage-all-fields';

$this->js = ['_main.js'];
$this->css = ['_main.css'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Tailwind3Bundle extends AssetBundle
{
public function init(): void
{
$this->sourcePath = '@freeform-formatting-templates/tailwind-3';
$this->sourcePath = '@Solspace/Freeform/templates/_templates/formatting/tailwind-3';

$this->js = ['_main.js'];
$this->css = ['_main.css'];
Expand Down

Large diffs are not rendered by default.

23 changes: 18 additions & 5 deletions packages/plugin/src/Services/SubmissionsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use Solspace\Freeform\Freeform;
use Solspace\Freeform\Library\Database\SubmissionHandlerInterface;
use Solspace\Freeform\Library\Helpers\PermissionHelper;
use Solspace\Freeform\Records\FormRecord;
use Twig\Markup;
use yii\base\Event;

Expand Down Expand Up @@ -117,6 +118,16 @@ public function getSubmissionCount(?array $formIds = null, ?array $statusIds = n
*/
public function getSubmissionCountByForm(bool $isSpam = false, ?Carbon $rangeStart = null, ?Carbon $rangeEnd = null): array
{
$isSpamFolderEnabled = $this->getSettingsService()->isSpamFolderEnabled();
if ($isSpam && !$isSpamFolderEnabled) {
return (new Query())
->select('spamBlockCount')
->from(FormRecord::TABLE)
->indexBy('id')
->column()
;
}

$submissions = Submission::TABLE;
$query = (new Query())
->select(["COUNT({$submissions}.[[id]]) as [[submissionCount]]"])
Expand Down Expand Up @@ -398,11 +409,13 @@ public function purgeSubmissions(?int $age = null): array

$assetIds = array_unique($assetIds);
foreach ($assetIds as $assetId) {
\Craft::$app->elements->deleteElementById(
$assetId,
hardDelete: true,
);
++$deletedAssets;
if (\is_int($assetId)) {
\Craft::$app->elements->deleteElementById(
$assetId,
hardDelete: true,
);
++$deletedAssets;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public function testReverseTransform()
$output = (new TableTransformer())->reverseTransform($value);

$expected = [
['label' => 'Col 1', 'value' => 'one', 'type' => 'string'],
['label' => 'Col 2', 'value' => 'two', 'type' => 'checkbox'],
['label' => 'Col 3', 'value' => 'three;four;five', 'type' => 'select'],
['label' => 'Col 1', 'value' => 'one', 'type' => 'string', 'placeholder' => '', 'options' => [], 'checked' => false],
['label' => 'Col 2', 'value' => 'two', 'type' => 'checkbox', 'placeholder' => '', 'options' => [], 'checked' => false],
['label' => 'Col 3', 'value' => 'three;four;five', 'type' => 'select', 'placeholder' => '', 'options' => [], 'checked' => false],
];

$this->assertEquals($expected, $output);
Expand Down
Loading

0 comments on commit 9c76bfa

Please sign in to comment.