diff --git a/app/Policies/ThreadPolicy.php b/app/Policies/ThreadPolicy.php index 2685aca..4279057 100644 --- a/app/Policies/ThreadPolicy.php +++ b/app/Policies/ThreadPolicy.php @@ -19,6 +19,10 @@ class ThreadPolicy */ public function update(User $user, Thread $thread) { + if ($user->isAdmin()) { + return true; + } + return $thread->user_id == $user->id; } } diff --git a/tests/Feature/UpdateThreadsTest.php b/tests/Feature/UpdateThreadsTest.php index 5dd3e29..44fb98a 100644 --- a/tests/Feature/UpdateThreadsTest.php +++ b/tests/Feature/UpdateThreadsTest.php @@ -55,4 +55,22 @@ function a_thread_can_be_updated_by_its_creator() $this->assertEquals('Changed body.', $thread->body); }); } + + /** @test */ + function administrators_can_update_threads() + { + $thread = create(\App\Thread::class, ['user_id' => auth()->id()]); + + $this->signInAdmin(); + + $this->patch($thread->path(), [ + 'title' => 'Changed', + 'body' => 'Changed body.' + ]); + + tap($thread->fresh(), function ($thread) { + $this->assertEquals('Changed', $thread->title); + $this->assertEquals('Changed body.', $thread->body); + }); + } }