Skip to content

Commit 2bd60f0

Browse files
committed
v2.0.0-beta.4
1 parent b7935aa commit 2bd60f0

File tree

15 files changed

+125
-423
lines changed

15 files changed

+125
-423
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Solspace Freeform Changelog
22

3+
## 2.0.0-beta.4 - 2018-01-30
4+
### Fixed
5+
- Fixed a bug where Freeform would trigger permission related errors when trying to edit users or user groups.
6+
- Fixed a bug where Freeform would not hide pages from navigation that a user did not have permission access to.
7+
- Fixed various permission issues throughout Freeform.
8+
39
## 2.0.0-beta.3 - 2018-01-29
410
### Added
511
- Added Freeform 1.x to 2.x (Craft 2.x to 3.x) migration path.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "solspace/craft3-freeform",
33
"description": "The most intuitive and powerful form builder for Craft.",
4-
"version": "2.0.0-beta.3",
4+
"version": "2.0.0-beta.4",
55
"type": "craft-plugin",
66
"minimum-stability": "dev",
77
"authors": [

src/Controllers/SettingsController.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Solspace\Freeform\Library\Exceptions\FreeformException;
2020
use Solspace\Freeform\Models\Settings;
2121
use Solspace\Freeform\Resources\Bundles\CodepackBundle;
22+
use Solspace\FreeformPro\FreeformPro;
2223
use yii\web\Response;
2324

2425
class SettingsController extends BaseController
@@ -51,23 +52,27 @@ public function actionDefaultView(): Response
5152

5253
if (($isFormView && !$canAccessForms) || ($isSubmissionView && !$canAccessSubmissions)) {
5354
if ($canAccessForms) {
54-
$this->redirect(UrlHelper::cpUrl('freeform/' . Freeform::VIEW_FORMS));
55+
return $this->redirect(UrlHelper::cpUrl('freeform/' . Freeform::VIEW_FORMS));
5556
}
5657

5758
if ($canAccessSubmissions) {
58-
$this->redirect(UrlHelper::cpUrl('freeform/' . Freeform::VIEW_SUBMISSIONS));
59+
return $this->redirect(UrlHelper::cpUrl('freeform/' . Freeform::VIEW_SUBMISSIONS));
5960
}
6061

6162
if ($canAccessFields) {
62-
$this->redirect(UrlHelper::cpUrl('freeform/' . Freeform::VIEW_FIELDS));
63+
return $this->redirect(UrlHelper::cpUrl('freeform/' . Freeform::VIEW_FIELDS));
6364
}
6465

6566
if ($canAccessNotifications) {
66-
$this->redirect(UrlHelper::cpUrl('freeform/' . Freeform::VIEW_NOTIFICATIONS));
67+
return $this->redirect(UrlHelper::cpUrl('freeform/' . Freeform::VIEW_NOTIFICATIONS));
6768
}
6869

6970
if ($canAccessSettings) {
70-
$this->redirect(UrlHelper::cpUrl('freeform/' . Freeform::VIEW_SETTINGS));
71+
return $this->redirect(UrlHelper::cpUrl('freeform/' . Freeform::VIEW_SETTINGS));
72+
}
73+
74+
if (Freeform::getInstance()->isPro() && PermissionHelper::checkPermission(FreeformPro::PERMISSION_EXPORT_PROFILES_ACCESS)) {
75+
return $this->redirect(UrlHelper::cpUrl('freeform/' . FreeformPro::VIEW_EXPORT_PROFILES));
7176
}
7277
}
7378

src/Controllers/SubmissionsController.php

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,6 @@ public function actionEdit(int $id): Response
192192
*/
193193
public function actionSave()
194194
{
195-
PermissionHelper::requirePermission(Freeform::PERMISSION_SUBMISSIONS_MANAGE);
196-
197195
$post = \Craft::$app->request->post();
198196

199197
$submissionId = $post['submissionId'] ?? null;
@@ -203,6 +201,13 @@ public function actionSave()
203201
throw new FreeformException(Freeform::t('Submission not found'));
204202
}
205203

204+
PermissionHelper::requirePermission(
205+
PermissionHelper::prepareNestedPermission(
206+
Freeform::PERMISSION_SUBMISSIONS_MANAGE,
207+
$model->formId
208+
)
209+
);
210+
206211
$model->title = \Craft::$app->request->post('title', $model->title);
207212
$model->statusId = $post['statusId'];
208213
$model->setFormFieldValues($post);
@@ -234,27 +239,4 @@ public function actionSave()
234239
]
235240
);
236241
}
237-
238-
/**
239-
* Deletes a field
240-
*
241-
* @return Response
242-
* @throws \Exception
243-
* @throws BadRequestHttpException
244-
* @throws ForbiddenHttpException
245-
*/
246-
public function actionDelete(): Response
247-
{
248-
$this->requirePostRequest();
249-
PermissionHelper::requirePermission(Freeform::PERMISSION_SUBMISSIONS_MANAGE);
250-
251-
$submissionId = \Craft::$app->request->post('id');
252-
$submission = $this->getSubmissionsService()->getSubmissionById($submissionId);
253-
254-
if ($submission && !$this->getSubmissionsService()->delete($submission)) {
255-
return $this->asErrorJson(implode('; ', $submission->getErrors()));
256-
}
257-
258-
return $this->asJson(['success' => true]);
259-
}
260242
}

src/Elements/Actions/SetSubmissionStatusAction.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use craft\base\ElementAction;
66
use craft\elements\db\ElementQueryInterface;
7+
use Solspace\Commons\Helpers\PermissionHelper;
78
use Solspace\Freeform\Elements\Submission;
89
use Solspace\Freeform\Freeform;
910

@@ -68,12 +69,22 @@ public function performAction(ElementQueryInterface $query): bool
6869
$submissions = $query->all();
6970
$failCount = 0;
7071

72+
static $allowedFormIds;
73+
74+
if (null === $allowedFormIds) {
75+
$allowedFormIds = PermissionHelper::getNestedPermissionIds(Freeform::PERMISSION_SUBMISSIONS_MANAGE);
76+
}
77+
7178
foreach ($submissions as $submission) {
7279
// Skip if there's nothing to change
7380
if ((int) $submission->statusId === (int) $this->statusId) {
7481
continue;
7582
}
7683

84+
if (!\in_array($submission->formId, $allowedFormIds, false)) {
85+
continue;
86+
}
87+
7788
$submission->statusId = $this->statusId;
7889

7990
if ($elementsService->saveElement($submission) === false) {

src/Elements/Submission.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use craft\elements\db\ElementQueryInterface;
99
use craft\helpers\Html;
1010
use craft\helpers\UrlHelper;
11+
use Solspace\Commons\Helpers\PermissionHelper;
1112
use Solspace\Freeform\Elements\Actions\DeleteSubmissionAction;
1213
use Solspace\Freeform\Elements\Actions\ExportCSVAction;
1314
use Solspace\Freeform\Elements\Actions\SetSubmissionStatusAction;
@@ -492,6 +493,16 @@ public function getIsEditable(): bool
492493
*/
493494
public function getCpEditUrl()
494495
{
496+
static $allowedFormIds;
497+
498+
if (null === $allowedFormIds) {
499+
$allowedFormIds = PermissionHelper::getNestedPermissionIds(Freeform::PERMISSION_SUBMISSIONS_MANAGE);
500+
}
501+
502+
if (!\in_array($this->formId, $allowedFormIds, false)) {
503+
return false;
504+
}
505+
495506
return UrlHelper::cpUrl('freeform/submissions/' . $this->id);
496507
}
497508

@@ -617,4 +628,17 @@ private function getFieldByIdentifier($identifier): AbstractField
617628

618629
return self::$fieldIdMap[$this->formId][$id];
619630
}
631+
632+
/**
633+
* @inheritDoc
634+
*/
635+
public function beforeDelete(): bool
636+
{
637+
return PermissionHelper::checkPermission(
638+
PermissionHelper::prepareNestedPermission(
639+
Freeform::PERMISSION_SUBMISSIONS_MANAGE,
640+
$this->formId
641+
)
642+
);
643+
}
620644
}

src/Freeform.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ function (RegisterUserPermissionsEvent $event) {
227227
self::PERMISSION_FORMS_ACCESS => [
228228
'label' => self::t('Access Forms'),
229229
'nested' => [
230-
PermissionHelper::PERMISSION_FORMS_MANAGE => ['label' => self::t('Manage Forms')],
230+
self::PERMISSION_FORMS_MANAGE => ['label' => self::t('Manage Forms')],
231231
],
232232
],
233233
self::PERMISSION_FIELDS_ACCESS => [

src/Library/Helpers/ColorHelper.php

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/Library/Helpers/PermissionsHelper.php

Lines changed: 0 additions & 153 deletions
This file was deleted.

0 commit comments

Comments
 (0)