fix resolving report with non-existing reporter
This commit is contained in:
parent
b7af1ebf19
commit
c4e292c877
|
|
@ -150,7 +150,11 @@ class ReportController extends Controller
|
||||||
|
|
||||||
public static function returnScore($report)
|
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->score -= $score;
|
||||||
$report->informer->save();
|
$report->informer->save();
|
||||||
}
|
}
|
||||||
|
|
@ -158,7 +162,7 @@ class ReportController extends Controller
|
||||||
|
|
||||||
public static function giveAward($report)
|
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->score += option('reporter_reward_score', 0);
|
||||||
$report->informer->save();
|
$report->informer->save();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -300,6 +300,26 @@ class ReportControllerTest extends TestCase
|
||||||
|
|
||||||
return true;
|
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()
|
public function testReviewDeleteNonExistentTexture()
|
||||||
|
|
@ -426,5 +446,25 @@ class ReportControllerTest extends TestCase
|
||||||
'code' => 1,
|
'code' => 1,
|
||||||
'message' => trans('admin.users.operations.non-existent'),
|
'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],
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user