| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentForm\App\Http\Controllers; |
| 4 |
|
| 5 |
use Exception; |
| 6 |
use FluentForm\App\Modules\Acl\Acl; |
| 7 |
use FluentForm\App\Services\Settings\Customizer; |
| 8 |
use FluentForm\App\Services\Settings\SettingsService; |
| 9 |
use FluentForm\Framework\Validator\ValidationException; |
| 10 |
use FluentForm\App\Services\Submission\SubmissionService; |
| 11 |
|
| 12 |
class FormSettingsController extends Controller |
| 13 |
{ |
| 14 |
public function index(SettingsService $settingsService, $formId) |
| 15 |
{ |
| 16 |
$formId = (int) $formId; |
| 17 |
|
| 18 |
// SECURITY (FINDING-09): this endpoint returns arbitrary form_meta by meta_key — |
| 19 |
// including integration feeds that hold webhook Authorization headers/credentials. |
| 20 |
// Because the method name collides with the forms-list controller, it resolved to |
| 21 |
// FormPolicy@index (fluentform_dashboard_access, the lowest tier). Require the |
| 22 |
// forms-manager capability, scoped to this form, to read its settings/meta. |
| 23 |
if (!Acl::hasPermission('fluentform_forms_manager', $formId)) { |
| 24 |
return $this->sendError([ |
| 25 |
'message' => __('You do not have permission to view these settings.', 'fluentform'), |
| 26 |
], 403); |
| 27 |
} |
| 28 |
|
| 29 |
$attributes = $this->request->all(); |
| 30 |
$attributes['form_id'] = $formId; |
| 31 |
|
| 32 |
$result = $settingsService->get($attributes); |
| 33 |
|
| 34 |
return $this->sendSuccess($result); |
| 35 |
} |
| 36 |
|
| 37 |
public function general(SettingsService $settingsService, $formId) |
| 38 |
{ |
| 39 |
$result = $settingsService->general($formId); |
| 40 |
|
| 41 |
return $this->sendSuccess($result); |
| 42 |
} |
| 43 |
|
| 44 |
public function saveGeneral(SettingsService $settingsService, $formId) |
| 45 |
{ |
| 46 |
try { |
| 47 |
$attributes = $this->request->all(); |
| 48 |
$attributes['form_id'] = (int) $formId; |
| 49 |
|
| 50 |
$settingsService->saveGeneral($attributes); |
| 51 |
|
| 52 |
return $this->sendSuccess([ |
| 53 |
'message' => __('Settings has been saved.', 'fluentform'), |
| 54 |
]); |
| 55 |
} catch (ValidationException $exception) { |
| 56 |
return $this->sendError($exception->errors(), 422); |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
public function store(SettingsService $settingsService, $formId) |
| 61 |
{ |
| 62 |
try { |
| 63 |
$attributes = $this->request->all(); |
| 64 |
$attributes['form_id'] = (int) $formId; |
| 65 |
|
| 66 |
[$settingsId, $settings] = $settingsService->store($attributes); |
| 67 |
|
| 68 |
return $this->sendSuccess([ |
| 69 |
'message' => __('Settings has been saved.', 'fluentform'), |
| 70 |
'id' => $settingsId, |
| 71 |
'settings' => $settings, |
| 72 |
]); |
| 73 |
} catch (ValidationException $exception) { |
| 74 |
return $this->sendError($exception->errors(), 422); |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
public function remove(SettingsService $settingsService, $formId) |
| 79 |
{ |
| 80 |
$attributes = $this->request->all(); |
| 81 |
$attributes['form_id'] = (int) $formId; |
| 82 |
|
| 83 |
$settingsService->remove($attributes); |
| 84 |
|
| 85 |
return $this->sendSuccess([]); |
| 86 |
} |
| 87 |
|
| 88 |
public function customizer(Customizer $customizer, $id) |
| 89 |
{ |
| 90 |
$metaKeys = [ |
| 91 |
'_custom_form_css', |
| 92 |
'_custom_form_js', |
| 93 |
'_ff_selected_style', |
| 94 |
'_ff_form_styles' |
| 95 |
]; |
| 96 |
|
| 97 |
return $this->sendSuccess($customizer->get($id, $metaKeys)); |
| 98 |
} |
| 99 |
|
| 100 |
public function storeCustomizer(Customizer $customizer, $id) |
| 101 |
{ |
| 102 |
try { |
| 103 |
$attributes = $this->request->all(); |
| 104 |
$attributes['form_id'] = (int) $id; |
| 105 |
|
| 106 |
$customizer->store($attributes); |
| 107 |
|
| 108 |
return $this->sendSuccess([ |
| 109 |
'message' => __('Custom CSS & JS successfully saved.', 'fluentform'), |
| 110 |
]); |
| 111 |
} catch (Exception $e) { |
| 112 |
return $this->sendError([ |
| 113 |
'message' => $e->getMessage(), |
| 114 |
], 423); |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
public function storeEntryColumns(SubmissionService $submissionService, $id) |
| 119 |
{ |
| 120 |
try { |
| 121 |
$attributes = $this->request->all(); |
| 122 |
$attributes['form_id'] = (int) $id; |
| 123 |
|
| 124 |
$submissionService->storeColumnSettings($attributes); |
| 125 |
|
| 126 |
return $this->sendSuccess([ |
| 127 |
'message' => __('The column display order has been saved.', 'fluentform'), |
| 128 |
]); |
| 129 |
} catch (Exception $e) { |
| 130 |
return $this->sendError([ |
| 131 |
'message' => $e->getMessage(), |
| 132 |
], 423); |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
public function conversationalDesign(SettingsService $settingsService, $formId) |
| 137 |
{ |
| 138 |
try { |
| 139 |
return $this->sendSuccess($settingsService->conversationalDesign($formId)); |
| 140 |
} catch (Exception $e) { |
| 141 |
return $this->sendError([ |
| 142 |
'message' => $e->getMessage(), |
| 143 |
], 423); |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
public function storeConversationalDesign(SettingsService $settingsService, $formId) |
| 148 |
{ |
| 149 |
try { |
| 150 |
return $this->sendSuccess($settingsService->storeConversationalDesign($this->request->all(), $formId)); |
| 151 |
} catch (Exception $e) { |
| 152 |
return $this->sendError([ |
| 153 |
'message' => $e->getMessage(), |
| 154 |
], 423); |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
public function getPreset(SettingsService $settingsService, $formId) |
| 159 |
{ |
| 160 |
try { |
| 161 |
return $this->sendSuccess($settingsService->getPreset($formId)); |
| 162 |
} catch (Exception $e) { |
| 163 |
return $this->sendError([ |
| 164 |
'message' => $e->getMessage(), |
| 165 |
], 423); |
| 166 |
} |
| 167 |
} |
| 168 |
|
| 169 |
public function savePreset(SettingsService $settingsService, $formId) |
| 170 |
{ |
| 171 |
try { |
| 172 |
$attributes = $this->request->all(); |
| 173 |
$attributes['form_id'] = (int) $formId; |
| 174 |
|
| 175 |
return $this->sendSuccess($settingsService->savePreset($attributes)); |
| 176 |
} catch (Exception $e) { |
| 177 |
return $this->sendError([ |
| 178 |
'message' => $e->getMessage(), |
| 179 |
], 423); |
| 180 |
} |
| 181 |
} |
| 182 |
} |
| 183 |
|