Skip to content

Commit

Permalink
Feature/page feedback user details (#164)
Browse files Browse the repository at this point in the history
* updated API docs

* added migration

* implemented name, email and phone fields to page feedback

* added CONTACT_DETAILS_PROVIDED key to notification
  • Loading branch information
matthew-inamdar committed Dec 10, 2018
1 parent 64ec601 commit 09f31f9
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/Http/Controllers/Core/V1/PageFeedbackController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
3 changes: 3 additions & 0 deletions app/Http/Requests/PageFeedback/StoreRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
];
}
}
4 changes: 4 additions & 0 deletions app/Http/Resources/PageFeedbackResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
];
Expand Down
1 change: 1 addition & 0 deletions app/Listeners/Notifications/PageFeedbackReceived.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
])
);
}
Expand Down
19 changes: 19 additions & 0 deletions app/Models/PageFeedback.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddUserDetailsToPageFeedbacksTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('page_feedbacks', function (Blueprint $table) {
$table->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');
});
}
}
15 changes: 15 additions & 0 deletions resources/views/docs/core/requests/page-feedback.blade.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,28 @@ store:
required:
- url
- feedback
- name
- email
- phone
properties:
url:
type: string
example: {{ url('/path/to/page') }}
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:
Expand Down
16 changes: 16 additions & 0 deletions resources/views/docs/core/resources/page-feedback.blade.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions tests/Feature/PageFeedbacksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
Expand All @@ -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),
]
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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,
]);
Expand All @@ -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),
]
Expand All @@ -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,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
Expand Down

0 comments on commit 09f31f9

Please sign in to comment.