This commit is contained in:
yushijinhun 2019-05-19 17:04:17 +08:00
parent baef165dbc
commit a9affdced9
No known key found for this signature in database
GPG Key ID: 5BC167F73EA558E4
2 changed files with 59 additions and 9 deletions

View File

@ -106,7 +106,16 @@ class ReportController extends Controller
switch ($data['action']) {
case 'delete':
$report->texture->delete();
if ($report->texture) {
$report->texture->delete();
} else {
// The texture has been deleted by its uploader
// We will return the score, but will not give the informer any reward
self::returnScore($report);
$report->status = Report::RESOLVED;
$report->save();
return json(trans('general.texture-deleted'), 0, ['status' => Report::RESOLVED]);
}
break;
case 'ban':
$uploader = User::find($report->uploader);
@ -121,17 +130,24 @@ class ReportController extends Controller
break;
}
if ($report->status == Report::PENDING) {
if (($score = option('reporter_score_modification', 0)) < 0) {
$report->informer->score -= $score;
}
$report->informer->score += option('reporter_reward_score', 0);
$report->informer->save();
}
self::returnScore($report);
self::giveAward($report);
$report->status = Report::RESOLVED;
$report->save();
return json(trans('general.op-success'), 0, ['status' => Report::RESOLVED]);
}
static function returnScore($report) {
if ($report->status == Report::PENDING && ($score = option('reporter_score_modification', 0)) < 0) {
$report->informer->score -= $score;
$report->informer->save();
}
}
static function giveAward($report) {
if ($report->status == Report::PENDING) {
$report->informer->score += option('reporter_reward_score', 0);
$report->informer->save();
}
}
}

View File

@ -218,6 +218,40 @@ class ReportControllerTest extends TestCase
$this->assertEquals($score + 7, $reporter->score);
}
public function testReviewDeleteNonExistentTexture()
{
$uploader = factory(User::class)->create();
$reporter = factory(User::class)->create();
$admin = factory(User::class, 'admin')->create();
$texture = factory(Texture::class)->create(['uploader' => $uploader->uid]);
$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();
option([
'reporter_reward_score' => 6,
'reporter_score_modification' => -7,
]);
$score = $reporter->score;
$texture->delete();
$this->actingAs($admin)
->postJson('/admin/reports', ['id' => $report->id, 'action' => 'delete'])
->assertJson([
'code' => 0,
'message' => trans('general.texture-deleted'),
'data' => ['status' => Report::RESOLVED],
]);
$report->refresh();
$this->assertEquals(Report::RESOLVED, $report->status);
$this->assertEquals($score, $reporter->score);
}
public function testReviewBan()
{
$uploader = factory(User::class)->create();