Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Commit

Permalink
Reportable content 42 (#106)
Browse files Browse the repository at this point in the history
* ragnaranks-29 Server language support database + vue

* ragnaranks-29 Server language support database + vue

* ragnaranks-29 Server language support database + vue

* Apply fixes from StyleCI (#101)

[ci skip] [skip ci]

* account design improv

* merge master

* Apply fixes from StyleCI (#104)

[ci skip] [skip ci]

* #29, flags now seed correctly, flag images added, flags now show on homepage.

* #29, tests

* #42 Installation and quick test

* Apply fixes from StyleCI (#105)

[ci skip] [skip ci]

* #42 Review reported controller, test and request

* #42 Reports controller with view, required design for reported content

* Apply fixes from StyleCI (#107)

[ci skip] [skip ci]

* #42 Design and modal actions

* #42 Moderator tool actions are now tested and notifications are sent too the reporter.

* Renamed reports controller to report controller

* Apply fixes from StyleCI (#108)

[ci skip] [skip ci]

* Corrected Url

* Reports can now be concluded, Concluded reports are not shown on moderation tools.

* Update production files.

* Apply fixes from StyleCI (#109)

[ci skip] [skip ci]
  • Loading branch information
marky291 committed Jun 4, 2019
1 parent 9fd4a87 commit 869496a
Show file tree
Hide file tree
Showing 30 changed files with 587 additions and 124,169 deletions.
37 changes: 37 additions & 0 deletions app/Http/Controllers/ReportController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace App\Http\Controllers;

use App\Report;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use App\Notifications\ReportedReviewAllowed;
use App\Notifications\ReportedReviewRemoved;

class ReportController extends Controller
{
public function index()
{
return view('account.moderation', ['reports' => Report::unjudged()->latest()->with(['reporter', 'reportable'])->get()]);
}

public function update(Request $request, Report $report) : JsonResponse
{
$report->reporter->notify(new ReportedReviewAllowed($report));

$report->conclude(['conclusion' => 'The report content was kept.', 'action_taken' => 'updated'], auth()->user());

return response()->json([], 200);
}

public function destroy(Report $report)
{
$report->reportable->delete();

$report->conclude(['conclusion' => 'The reported content was removed.', 'action_taken' => 'deleted'], auth()->user());

$report->reporter->notify(new ReportedReviewRemoved($report));

return response()->json([], 200);
}
}
27 changes: 27 additions & 0 deletions app/Http/Controllers/ReviewReportController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App\Http\Controllers;

use App\Interactions\Review;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use App\Http\Requests\ReviewReportRequest;

class ReviewReportController extends Controller
{
/**
* Store a newly created resource in storage.
*
* @param Review $review
* @param Request $request
* @return JsonResponse
*/
public function store(Review $review, ReviewReportRequest $request): JsonResponse
{
$review = $review->report($request->validated(), auth()->user());

$status = $review->save();

return response()->json(['status' => $status], 200);
}
}
2 changes: 1 addition & 1 deletion app/Http/Middleware/CheckForMaintenanceMode.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CheckForMaintenanceMode extends Middleware
* @var array
*/
protected $exemptIP = [
'213.202.145.165',
'80.233.36.207',
'45.56.25.157',
];

Expand Down
31 changes: 31 additions & 0 deletions app/Http/Requests/ReviewReportRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class ReviewReportRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'reason' => 'required', 'string', 'max:255',
'meta' => 'sometimes', 'array',
];
}
}
17 changes: 12 additions & 5 deletions app/Interactions/Review.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
use App\ReviewComment;
use App\Listings\Listing;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\Validator;
use BrianFaust\Reportable\Traits\HasReports;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Relations\MorphToMany;

/**
* Class Review.
Expand All @@ -35,18 +36,24 @@
*/
class Review extends Interaction
{
/*
* @link https://github.com/artisanry/reportable/blob/master/src/Traits/HasReports.php
*/
use HasReports;

/**
* The attributes that aren't mass assignable.
*
* @var array
*/
protected $guarded = [];

public function validator(array $data)
/**
* @return MorphToMany
*/
public function listing()
{
return Validator::make($data, [
// validation for data.
]);
return $this->morphedByMany(Listing::class, 'interaction');
}

/**
Expand Down
52 changes: 52 additions & 0 deletions app/Notifications/ReportedReviewAllowed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace App\Notifications;

use App\Report;
use App\Interactions\Review;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;

class ReportedReviewAllowed extends Notification
{
use Queueable;

/**
* @var Review
*/
private $report;

/**
* Create a new notification instance.
* @param Report $report
*/
public function __construct(Report $report)
{
$this->report = $report;
}

/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['database'];
}

/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
'title' => 'Action taken on a review you reported!',
'message' => "The review you reported {$this->report->created_at->diffForHumans()} was deemed acceptable by the moderation team",
];
}
}
53 changes: 53 additions & 0 deletions app/Notifications/ReportedReviewRemoved.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace App\Notifications;

use App\Report;
use App\Interactions\Review;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;

class ReportedReviewRemoved extends Notification
{
use Queueable;

/**
* @var Report
*/
private $report;

/**
* Create a new notification instance.
*
* @param Report $report
*/
public function __construct(Report $report)
{
$this->report = $report;
}

/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['database'];
}

/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
'title' => 'Action taken on a review you reported!',
'message' => "The review you reported {$this->report->created_at->diffForHumans()} broke our rules and was removed.",
];
}
}
7 changes: 6 additions & 1 deletion app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Providers;

use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;

class AuthServiceProvider extends ServiceProvider
Expand All @@ -24,6 +25,10 @@ public function boot()
{
$this->registerPolicies();

//
// Implicitly grant "Super Admin" role all permissions
// This works in the app by using gate-related functions like auth()->user->can() and @can()
Gate::before(function ($user, $ability) {
return $user->hasRole('admin') ? true : null;
});
}
}
29 changes: 29 additions & 0 deletions app/Report.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\MorphOne;

/**
* @property User reporter
* @property MorphOne reportable
*/
class Report extends \BrianFaust\Reportable\Models\Report
{
public function scopeUnjudged(Builder $query) : Builder
{
return $query->doesntHave('conclusion');
}

/**
* A report has a reporter.
*
* @return HasOne
*/
public function reporter(): HasOne
{
return $this->hasOne(User::class, 'id', 'reporter_id');
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"license": "MIT",
"require": {
"php": "^7.1.3",
"faustbrian/laravel-reportable": "^2.3",
"fideloper/proxy": "^4.0",
"gstt/laravel-achievements": "^1.0",
"laravel/framework": "5.7.*",
Expand Down
64 changes: 63 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion database/factories/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
'email_verified_at' => now(),
'password' => '$2y$10$TKh8H1.PfQx37YgCzwiKb.KjNyWgaHb9cbcoQgdIVFlYg7B77UdFm', // secret
'remember_token' => str_random(10),
'avatarUrl' => 'https://forums.xilero.net/uploads/monthly_2019_03/Ragnarok.Chronicle_full.1603769.thumb.jpg.9228c6e958031d09fa6cf9613cacc219.jpg',
'avatarUrl' => $faker->imageUrl(640, 480),
];
});

Expand Down
Loading

0 comments on commit 869496a

Please sign in to comment.