diff --git a/app/Http/Controllers/Forms/PublicFormController.php b/app/Http/Controllers/Forms/PublicFormController.php index 1cbc092..5b4fab1 100644 --- a/app/Http/Controllers/Forms/PublicFormController.php +++ b/app/Http/Controllers/Forms/PublicFormController.php @@ -21,7 +21,7 @@ class PublicFormController extends Controller public function show(Request $request, string $slug) { - $form = Form::whereSlug($slug)->firstOrFail(); + $form = Form::whereSlug($slug)->whereVisibility('public')->firstOrFail(); if ($form->workspace == null) { // Workspace deleted return $this->error([ diff --git a/app/Http/Requests/AnswerFormRequest.php b/app/Http/Requests/AnswerFormRequest.php index 379d28a..7cd1f3b 100644 --- a/app/Http/Requests/AnswerFormRequest.php +++ b/app/Http/Requests/AnswerFormRequest.php @@ -40,7 +40,7 @@ class AnswerFormRequest extends FormRequest */ public function authorize() { - return !$this->form->is_closed && !$this->form->max_number_of_submissions_reached; + return !$this->form->is_closed && !$this->form->max_number_of_submissions_reached && $this->form->visibility === 'public'; } /** diff --git a/app/Http/Requests/UserFormRequest.php b/app/Http/Requests/UserFormRequest.php index ecfb073..8b3da44 100644 --- a/app/Http/Requests/UserFormRequest.php +++ b/app/Http/Requests/UserFormRequest.php @@ -29,6 +29,7 @@ abstract class UserFormRequest extends \Illuminate\Foundation\Http\FormRequest 'title' => 'required|string|max:60', 'description' => 'nullable|string|max:2000', 'tags' => 'nullable|array', + 'visibility' => ['required',Rule::in(Form::VISIBILITY)], // Notifications 'notifies' => 'boolean', diff --git a/app/Http/Resources/FormResource.php b/app/Http/Resources/FormResource.php index 71dee8c..dbb850e 100644 --- a/app/Http/Resources/FormResource.php +++ b/app/Http/Resources/FormResource.php @@ -42,6 +42,7 @@ class FormResource extends JsonResource 'can_be_indexed' => $this->can_be_indexed, 'password' => $this->password, 'tags' => $this->tags, + 'visibility' => $this->visibility, 'notification_emails' => $this->notification_emails, 'slack_webhook_url' => $this->slack_webhook_url, ] : []; diff --git a/app/Models/Forms/Form.php b/app/Models/Forms/Form.php index b12cdbe..c2f2405 100644 --- a/app/Models/Forms/Form.php +++ b/app/Models/Forms/Form.php @@ -20,6 +20,7 @@ class Form extends Model const DARK_MODE_VALUES = ['auto', 'light', 'dark']; const THEMES = ['default', 'simple', 'notion']; const WIDTHS = ['centered', 'full']; + const VISIBILITY = ['public', 'draft']; use HasFactory, HasSlug, SoftDeletes; @@ -45,6 +46,7 @@ class Form extends Model 'title', 'description', 'tags', + 'visibility', // Customization 'theme', diff --git a/database/factories/FormFactory.php b/database/factories/FormFactory.php index 40d4850..b5e5809 100644 --- a/database/factories/FormFactory.php +++ b/database/factories/FormFactory.php @@ -58,6 +58,7 @@ class FormFactory extends Factory return [ 'title' => $this->faker->text(30), 'description' => $this->faker->randomHtml(1), + 'visibility' => 'public', 'notifies' => false, 'send_submission_confirmation' => false, 'webhook_url' => null, diff --git a/database/migrations/2022_10_07_122038_add_visibility_to_forms.php b/database/migrations/2022_10_07_122038_add_visibility_to_forms.php new file mode 100644 index 0000000..acea5b7 --- /dev/null +++ b/database/migrations/2022_10_07_122038_add_visibility_to_forms.php @@ -0,0 +1,32 @@ +string('visibility')->default('public'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('forms', function (Blueprint $table) { + $table->dropColumn('visibility'); + }); + } +}; diff --git a/resources/js/components/open/forms/components/form-components/FormInformation.vue b/resources/js/components/open/forms/components/form-components/FormInformation.vue index 62631d4..f94bd12 100644 --- a/resources/js/components/open/forms/components/form-components/FormInformation.vue +++ b/resources/js/components/open/forms/components/form-components/FormInformation.vue @@ -27,6 +27,11 @@ placeholder="Select Tag(s)" :multiple="true" :allowCreation="true" :options="allTagsOptions" /> +