Form visibility closed (#91)

This commit is contained in:
Chirag Chhatrala 2023-02-19 17:41:50 +05:30 committed by GitHub
parent 9137282eba
commit d6930d0dc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 22 additions and 5 deletions

View File

@ -23,7 +23,7 @@ class PublicFormController extends Controller
public function show(Request $request, string $slug) public function show(Request $request, string $slug)
{ {
$form = Form::whereSlug($slug)->whereVisibility('public')->firstOrFail(); $form = Form::whereSlug($slug)->whereIn('visibility', ['public', 'closed'])->firstOrFail();
if ($form->workspace == null) { if ($form->workspace == null) {
// Workspace deleted // Workspace deleted
return $this->error([ return $this->error([

View File

@ -20,7 +20,7 @@ class Form extends Model
const DARK_MODE_VALUES = ['auto', 'light', 'dark']; const DARK_MODE_VALUES = ['auto', 'light', 'dark'];
const THEMES = ['default', 'simple', 'notion']; const THEMES = ['default', 'simple', 'notion'];
const WIDTHS = ['centered', 'full']; const WIDTHS = ['centered', 'full'];
const VISIBILITY = ['public', 'draft']; const VISIBILITY = ['public', 'draft', 'closed'];
use HasFactory, HasSlug, SoftDeletes; use HasFactory, HasSlug, SoftDeletes;

View File

@ -33,7 +33,7 @@
</div> </div>
</v-transition> </v-transition>
<div v-if="isPublicFormPage && form.is_closed" <div v-if="isPublicFormPage && (form.is_closed || form.visibility=='closed')"
class="border shadow-sm p-2 my-4 flex items-center rounded-md bg-yellow-100 border-yellow-500" class="border shadow-sm p-2 my-4 flex items-center rounded-md bg-yellow-100 border-yellow-500"
> >
<div class="flex-grow"> <div class="flex-grow">
@ -68,7 +68,7 @@
</div> </div>
<transition <transition
v-if="!form.is_password_protected && (!isPublicFormPage || (!form.is_closed && !form.max_number_of_submissions_reached))" v-if="!form.is_password_protected && (!isPublicFormPage || (!form.is_closed && !form.max_number_of_submissions_reached && form.visibility!='closed'))"
enter-active-class="duration-500 ease-out" enter-active-class="duration-500 ease-out"
enter-class="translate-x-full opacity-0" enter-class="translate-x-full opacity-0"
enter-to-class="translate-x-0 opacity-100" enter-to-class="translate-x-0 opacity-100"

View File

@ -126,7 +126,7 @@
help="If filled, then the form won't accept submissions after the given date" help="If filled, then the form won't accept submissions after the given date"
:required="false" :required="false"
/> />
<rich-text-area-input v-if="form.closes_at" name="closed_text" <rich-text-area-input v-if="form.closes_at || form.visibility=='closed'" name="closed_text"
:form="form" :form="form"
label="Closed form text" label="Closed form text"
help="This message will be shown when the form will be closed" help="This message will be shown when the form will be closed"

View File

@ -90,6 +90,10 @@ export default {
{ {
name: "Draft (form won't be accessible)", name: "Draft (form won't be accessible)",
value: "draft" value: "draft"
},
{
name: "Closed",
value: "closed"
} }
], ],
isCollapseOpen: true isCollapseOpen: true

View File

@ -50,6 +50,7 @@
submission{{ form.submissions_count > 0 ? 's' : '' }} submission{{ form.submissions_count > 0 ? 's' : '' }}
</li> </li>
<li class="list-disc ml-6 pr-1 text-blue-500" v-if="form.visibility=='draft'">Draft (not public)</li> <li class="list-disc ml-6 pr-1 text-blue-500" v-if="form.visibility=='draft'">Draft (not public)</li>
<li class="list-disc ml-6 pr-1 text-blue-500" v-if="form.visibility=='closed'">Closed</li>
<li class="list-disc ml-6">Edited {{ form.last_edited_human }}</li> <li class="list-disc ml-6">Edited {{ form.last_edited_human }}</li>
</ul> </ul>

View File

@ -85,6 +85,18 @@ it('can not submit draft form', function () {
->assertStatus(403); ->assertStatus(403);
}); });
it('can not submit visibility closed form', function () {
$user = $this->actingAsUser();
$workspace = $this->createUserWorkspace($user);
$form = $this->createForm($user, $workspace, [
'visibility' => 'closed'
]);
$formData = FormSubmissionDataFactory::generateSubmissionData($form);
$this->postJson(route('forms.answer', $form->slug), $formData)
->assertStatus(403);
});
it('can not submit form with past dates', function () { it('can not submit form with past dates', function () {
$user = $this->actingAsUser(); $user = $this->actingAsUser();
$workspace = $this->createUserWorkspace($user); $workspace = $this->createUserWorkspace($user);