diff --git a/app/Http/Controllers/Core/V1/PageFeedbackController.php b/app/Http/Controllers/Core/V1/PageFeedbackController.php index 0c132508..29be2e1f 100644 --- a/app/Http/Controllers/Core/V1/PageFeedbackController.php +++ b/app/Http/Controllers/Core/V1/PageFeedbackController.php @@ -58,6 +58,10 @@ public function store(StoreRequest $request) $pageFeedback = PageFeedback::create([ 'url' => $request->url, 'feedback' => $request->feedback, + 'name' => $request->name, + 'email' => $request->email, + 'phone' => $request->phone, + 'consented_at' => now(), ]); event(EndpointHit::onCreate($request, "Created page feedback [{$pageFeedback->id}]", $pageFeedback)); diff --git a/app/Http/Requests/PageFeedback/StoreRequest.php b/app/Http/Requests/PageFeedback/StoreRequest.php index 8cf7f56c..57f766d9 100644 --- a/app/Http/Requests/PageFeedback/StoreRequest.php +++ b/app/Http/Requests/PageFeedback/StoreRequest.php @@ -26,6 +26,9 @@ public function rules() return [ 'url' => ['required', 'url', 'max:255'], 'feedback' => ['required', 'string', 'min:1', 'max:10000'], + 'name' => ['present', 'nullable', 'string', 'max:255'], + 'email' => ['present', 'nullable', 'email', 'max:255'], + 'phone' => ['present', 'nullable', 'string', 'max:255'], ]; } } diff --git a/app/Http/Resources/PageFeedbackResource.php b/app/Http/Resources/PageFeedbackResource.php index 606381d1..feaa2f1a 100644 --- a/app/Http/Resources/PageFeedbackResource.php +++ b/app/Http/Resources/PageFeedbackResource.php @@ -19,6 +19,10 @@ public function toArray($request) 'id' => $this->id, 'url' => $this->url, 'feedback' => $this->feedback, + 'name' => $this->name, + 'email' => $this->email, + 'phone' => $this->phone, + 'consented_at' => $this->consented_at->format(Carbon::ISO8601), 'created_at' => $this->created_at->format(Carbon::ISO8601), 'updated_at' => $this->updated_at->format(Carbon::ISO8601), ]; diff --git a/app/Listeners/Notifications/PageFeedbackReceived.php b/app/Listeners/Notifications/PageFeedbackReceived.php index 98c650ba..5fad5eff 100644 --- a/app/Listeners/Notifications/PageFeedbackReceived.php +++ b/app/Listeners/Notifications/PageFeedbackReceived.php @@ -35,6 +35,7 @@ protected function notifyGlobalAdmins(PageFeedback $pageFeedback) new NotifyGlobalAdminEmail(config('ck.global_admin.email'), [ 'FEEDBACK_URL' => $pageFeedback->url, 'FEEDBACK_CONTENT' => $pageFeedback->feedback, + 'CONTACT_DETAILS_PROVIDED' => $pageFeedback->userDetailsProvided(), ]) ); } diff --git a/app/Models/PageFeedback.php b/app/Models/PageFeedback.php index 00f644d7..628f97cf 100644 --- a/app/Models/PageFeedback.php +++ b/app/Models/PageFeedback.php @@ -11,4 +11,23 @@ class PageFeedback extends Model use PageFeedbackMutators; use PageFeedbackRelationships; use PageFeedbackScopes; + + /** + * The attributes that should be cast to native types. + * + * @var array + */ + protected $casts = [ + 'consented_at' => 'datetime', + 'created_at' => 'datetime', + 'updated_at' => 'datetime', + ]; + + /** + * @return bool + */ + public function userDetailsProvided(): bool + { + return ($this->name !== null) || ($this->email !== null) || ($this->phone !== null); + } } diff --git a/database/migrations/2018_12_07_164219_add_user_details_to_page_feedbacks_table.php b/database/migrations/2018_12_07_164219_add_user_details_to_page_feedbacks_table.php new file mode 100644 index 00000000..1322f9fc --- /dev/null +++ b/database/migrations/2018_12_07_164219_add_user_details_to_page_feedbacks_table.php @@ -0,0 +1,35 @@ +string('name')->nullable()->after('feedback'); + $table->string('email')->nullable()->after('name'); + $table->string('phone')->nullable()->after('email'); + $table->timestamp('consented_at')->nullable()->after('phone'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('page_feedbacks', function (Blueprint $table) { + $table->dropColumn('name', 'email', 'phone', 'consented_at'); + }); + } +} diff --git a/resources/views/docs/core/requests/page-feedback.blade.yaml b/resources/views/docs/core/requests/page-feedback.blade.yaml index fb6c92ce..b0608f0f 100644 --- a/resources/views/docs/core/requests/page-feedback.blade.yaml +++ b/resources/views/docs/core/requests/page-feedback.blade.yaml @@ -3,6 +3,9 @@ store: required: - url - feedback + - name + - email + - phone properties: url: type: string @@ -10,6 +13,18 @@ store: feedback: type: string example: This does not work on my browser + name: + type: string + nullable: true + example: John Doe + email: + type: string + nullable: true + example: john.doe@example.com + phone: + type: string + nullable: true + example: "07700000000" update: allOf: diff --git a/resources/views/docs/core/resources/page-feedback.blade.yaml b/resources/views/docs/core/resources/page-feedback.blade.yaml index 59d6644d..09fddbdd 100644 --- a/resources/views/docs/core/resources/page-feedback.blade.yaml +++ b/resources/views/docs/core/resources/page-feedback.blade.yaml @@ -10,6 +10,22 @@ properties: feedback: type: string example: This does not work on my browser + name: + type: string + nullable: true + example: John Doe + email: + type: string + nullable: true + example: john.doe@example.com + phone: + type: string + nullable: true + example: "07700000000" + consented_at: + type: string + format: date-time + nullable: true created_at: type: string format: date-time diff --git a/tests/Feature/PageFeedbacksTest.php b/tests/Feature/PageFeedbacksTest.php index 6b872f9a..5c873281 100644 --- a/tests/Feature/PageFeedbacksTest.php +++ b/tests/Feature/PageFeedbacksTest.php @@ -88,6 +88,7 @@ public function test_global_admin_can_list_them() $pageFeedback = PageFeedback::create([ 'url' => url('/test'), 'feedback' => 'This page does not work', + 'consented_at' => $this->now, 'created_at' => $this->now, 'updated_at' => $this->now, ]); @@ -102,6 +103,10 @@ public function test_global_admin_can_list_them() 'id' => $pageFeedback->id, 'url' => url('/test'), 'feedback' => 'This page does not work', + 'name' => null, + 'email' => null, + 'phone' => null, + 'consented_at' => $pageFeedback->consented_at->format(Carbon::ISO8601), 'created_at' => $pageFeedback->created_at->format(Carbon::ISO8601), 'updated_at' => $pageFeedback->updated_at->format(Carbon::ISO8601), ] @@ -137,6 +142,9 @@ public function test_guest_can_create_one() $payload = [ 'url' => url('test-page'), 'feedback' => 'This page does not work', + 'name' => null, + 'email' => null, + 'phone' => null, ]; $response = $this->json('POST', '/core/v1/page-feedbacks', $payload); @@ -152,6 +160,9 @@ public function test_audit_created_when_created() $response = $this->json('POST', '/core/v1/page-feedbacks', [ 'url' => url('test-page'), 'feedback' => 'This page does not work', + 'name' => null, + 'email' => null, + 'phone' => null, ]); Event::assertDispatched(EndpointHit::class, function (EndpointHit $event) use ($response) { @@ -257,6 +268,7 @@ public function test_global_admin_can_view_one() $pageFeedback = PageFeedback::create([ 'url' => url('/test'), 'feedback' => 'This page does not work', + 'consented_at' => $this->now, 'created_at' => $this->now, 'updated_at' => $this->now, ]); @@ -271,6 +283,10 @@ public function test_global_admin_can_view_one() 'id' => $pageFeedback->id, 'url' => url('/test'), 'feedback' => 'This page does not work', + 'name' => null, + 'email' => null, + 'phone' => null, + 'consented_at' => $pageFeedback->consented_at->format(Carbon::ISO8601), 'created_at' => $pageFeedback->created_at->format(Carbon::ISO8601), 'updated_at' => $pageFeedback->updated_at->format(Carbon::ISO8601), ] @@ -289,6 +305,7 @@ public function test_audit_created_when_viewed() $pageFeedback = PageFeedback::create([ 'url' => url('/test'), 'feedback' => 'This page does not work', + 'consented_at' => $this->now, 'created_at' => $this->now, 'updated_at' => $this->now, ]); diff --git a/tests/Unit/Listeners/Notifications/PageFeedbackReceivedTest.php b/tests/Unit/Listeners/Notifications/PageFeedbackReceivedTest.php index fb64761b..c1afa541 100644 --- a/tests/Unit/Listeners/Notifications/PageFeedbackReceivedTest.php +++ b/tests/Unit/Listeners/Notifications/PageFeedbackReceivedTest.php @@ -35,6 +35,7 @@ public function test_email_sent_to_global_admin_email() $this->assertEquals(config('ck.notifications_template_ids.page_feedback_received.notify_global_admin.email'), $email->templateId); $this->assertArrayHasKey('FEEDBACK_URL', $email->values); $this->assertArrayHasKey('FEEDBACK_CONTENT', $email->values); + $this->assertArrayHasKey('CONTACT_DETAILS_PROVIDED', $email->values); return true; }); }