fix resolving report with non-existing reporter

This commit is contained in:
Pig Fang 2021-05-04 18:32:35 +08:00
parent b7af1ebf19
commit c4e292c877
No known key found for this signature in database
GPG Key ID: A8198F548DADA9E2
2 changed files with 46 additions and 2 deletions

View File

@ -150,7 +150,11 @@ class ReportController extends Controller
public static function returnScore($report)
{
if ($report->status == Report::PENDING && ($score = option('reporter_score_modification', 0)) < 0) {
if (
$report->status == Report::PENDING &&
($score = option('reporter_score_modification', 0)) < 0 &&
$report->informer
) {
$report->informer->score -= $score;
$report->informer->save();
}
@ -158,7 +162,7 @@ class ReportController extends Controller
public static function giveAward($report)
{
if ($report->status == Report::PENDING) {
if ($report->status == Report::PENDING && $report->informer) {
$report->informer->score += option('reporter_reward_score', 0);
$report->informer->save();
}

View File

@ -300,6 +300,26 @@ class ReportControllerTest extends TestCase
return true;
});
$texture = Texture::factory()->create();
// no errors should be occurred even reporter doesn't exist
$report = new Report();
$report->tid = $texture->tid;
$report->uploader = $uploader->uid;
$report->reporter = 0;
$report->reason = 'test';
$report->status = Report::PENDING;
$report->save();
$report->refresh();
$id = $report->id;
$tid = $texture->tid;
$this->actingAs($admin)
->putJson('/admin/reports/'.$report->id, ['action' => 'delete'])
->assertJson([
'code' => 0,
'message' => trans('general.op-success'),
'data' => ['status' => Report::RESOLVED],
]);
}
public function testReviewDeleteNonExistentTexture()
@ -426,5 +446,25 @@ class ReportControllerTest extends TestCase
'code' => 1,
'message' => trans('admin.users.operations.non-existent'),
]);
$uploader->permission = User::NORMAL;
$uploader->save();
// no errors should be occurred even reporter doesn't exist
$report = new Report();
$report->tid = $texture->tid;
$report->uploader = $uploader->uid;
$report->reporter = $reporter->uid;
$report->reason = 'test';
$report->status = Report::PENDING;
$report->save();
$report->refresh();
$id = $report->id;
$this->actingAs($admin)
->putJson('/admin/reports/'.$report->id, ['action' => 'ban'])
->assertJson([
'code' => 0,
'message' => trans('general.op-success'),
'data' => ['status' => Report::RESOLVED],
]);
}
}