-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1342 from shikorism/develop
Release 2024.11.1
- Loading branch information
Showing
53 changed files
with
2,865 additions
and
925 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ a.k.a. shikorism.net | |
|
||
## 実行環境 | ||
|
||
- PHP 8.1 | ||
- PHP 8.2 | ||
- PostgreSQL 14 | ||
|
||
> [!WARNING] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Admin; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Moderation; | ||
use App\ModerationAction; | ||
use App\Report; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Validation\Rules\Enum; | ||
|
||
class ReportController extends Controller | ||
{ | ||
public function index() | ||
{ | ||
$reports = Report::query() | ||
->with([ | ||
'violatedRule' => fn ($query) => $query->withTrashed(), | ||
'targetUser', | ||
]) | ||
->orderByDesc('id') | ||
->get(); | ||
|
||
return view('admin.reports.index')->with(compact('reports')); | ||
} | ||
|
||
public function show(Report $report) | ||
{ | ||
$report->load([ | ||
'violatedRule' => fn ($query) => $query->withTrashed(), | ||
'moderations.moderator', | ||
]); | ||
$strikes = Report::where('target_user_id', $report->target_user_id)->count(); | ||
|
||
return view('admin.reports.show')->with(compact('report', 'strikes')); | ||
} | ||
|
||
public function action(Report $report, Request $request) | ||
{ | ||
$validated = $request->validate([ | ||
'action' => ['required', new Enum(ModerationAction::class)], | ||
'comment' => 'string|max:100', | ||
'send_email' => 'boolean', | ||
]); | ||
|
||
DB::transaction(function () use ($report, $validated) { | ||
$mod = new Moderation($validated); | ||
$mod->moderator()->associate(Auth::user()); | ||
$mod->report()->associate($report); | ||
$mod->targetUser()->associate($report->targetUser); | ||
$mod->ejaculation()->associate($report->ejaculation); | ||
$mod->send_email |= false; | ||
$mod->saveOrFail(); | ||
|
||
if (!$mod->performAction()) { | ||
abort(500); | ||
} | ||
}); | ||
|
||
return redirect()->route('admin.reports.show', ['report' => $report])->with('status', 'モデレーションを実行しました。'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Admin; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Http\Requests\AdminRuleStoreRequest; | ||
use App\Rule; | ||
use Illuminate\Http\Request; | ||
|
||
class RuleController extends Controller | ||
{ | ||
public function index() | ||
{ | ||
$rules = Rule::query() | ||
->sorted() | ||
->get(); | ||
|
||
return view('admin.rule.index')->with(compact('rules')); | ||
} | ||
|
||
public function create() | ||
{ | ||
return view('admin.rule.create'); | ||
} | ||
|
||
public function store(AdminRuleStoreRequest $request) | ||
{ | ||
Rule::create($request->validated()); | ||
|
||
return redirect()->route('admin.rule')->with('status', '通報理由を作成しました。'); | ||
} | ||
|
||
public function edit(Rule $rule) | ||
{ | ||
return view('admin.rule.edit')->with(compact('rule')); | ||
} | ||
|
||
public function update(AdminRuleStoreRequest $request, Rule $rule) | ||
{ | ||
$rule->fill($request->validated())->save(); | ||
|
||
return redirect()->route('admin.rule.edit', compact('rule'))->with('status', '通報理由を更新しました。'); | ||
} | ||
|
||
public function destroy(Rule $rule) | ||
{ | ||
$rule->delete(); | ||
|
||
return redirect()->route('admin.rule')->with('status', '通報理由を削除しました。'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -240,4 +240,9 @@ public function tools() | |
{ | ||
return view('ejaculation.tools'); | ||
} | ||
|
||
public function report() | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Ejaculation; | ||
use App\Http\Requests\EjaculationReportRequest; | ||
use App\Mail\EjaculationReported; | ||
use App\Report; | ||
use App\Rule; | ||
use App\User; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Support\Facades\Mail; | ||
|
||
class EjaculationReportController extends Controller | ||
{ | ||
public function create(Ejaculation $ejaculation) | ||
{ | ||
$rules = Rule::query()->sorted()->get(); | ||
|
||
return view('ejaculation.report')->with(compact('ejaculation', 'rules')); | ||
} | ||
|
||
public function store(EjaculationReportRequest $request, Ejaculation $ejaculation) | ||
{ | ||
$validated = $request->validated(); | ||
|
||
$report = new Report(); | ||
$report->comment = $validated['comment']; | ||
$report->reporter()->associate(Auth::user()); | ||
$report->targetUser()->associate($ejaculation->user); | ||
$report->ejaculation()->associate($ejaculation); | ||
|
||
if (!empty($validated['violated_rule']) && $validated['violated_rule'] !== 'other') { | ||
$rule = Rule::findOrFail($validated['violated_rule']); | ||
$report->violatedRule()->associate($rule); | ||
} | ||
|
||
$report->save(); | ||
|
||
Mail::to(User::administrators()->get())->send(new EjaculationReported($report)); | ||
|
||
return redirect()->route('checkin.show', ['id' => $ejaculation->id])->with('status', 'チェックインを報告しました。'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
class AdminRuleStoreRequest 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<string, mixed> | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
'summary' => 'required|string|max:255', | ||
]; | ||
} | ||
|
||
public function attributes() | ||
{ | ||
return [ | ||
'summary' => 'ルール', | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
use Illuminate\Validation\Validator; | ||
|
||
class EjaculationReportRequest 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<string, mixed> | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
'violated_rule' => 'required', | ||
'comment' => 'required_if:violated_rule,other|string|max:1000', | ||
]; | ||
} | ||
|
||
public function withValidator(Validator $validator) | ||
{ | ||
$validator->sometimes('comment', 'exists:rules,id', function ($input) { | ||
return $input->violated_rule !== 'other'; | ||
}); | ||
} | ||
|
||
public function attributes() | ||
{ | ||
return [ | ||
'violated_rule' => '報告の理由', | ||
'comment' => '詳しい内容', | ||
]; | ||
} | ||
|
||
public function messages() | ||
{ | ||
return [ | ||
'comment.required_if' => '詳しい内容を入力してください。', | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace App\Mail; | ||
|
||
use App\Report; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Mail\Mailable; | ||
use Illuminate\Mail\Mailables\Content; | ||
use Illuminate\Mail\Mailables\Envelope; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class EjaculationReported extends Mailable | ||
{ | ||
use Queueable, SerializesModels; | ||
|
||
/** | ||
* Create a new message instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct(public Report $report) | ||
{ | ||
} | ||
|
||
/** | ||
* Get the message envelope. | ||
* | ||
* @return \Illuminate\Mail\Mailables\Envelope | ||
*/ | ||
public function envelope() | ||
{ | ||
return new Envelope( | ||
subject: "チェックイン #{$this->report->ejaculation_id} の報告 | " . config('app.name'), | ||
); | ||
} | ||
|
||
/** | ||
* Get the message content definition. | ||
* | ||
* @return \Illuminate\Mail\Mailables\Content | ||
*/ | ||
public function content() | ||
{ | ||
return new Content( | ||
markdown: 'emails.ejaculation_reported', | ||
); | ||
} | ||
|
||
/** | ||
* Get the attachments for the message. | ||
* | ||
* @return array | ||
*/ | ||
public function attachments() | ||
{ | ||
return []; | ||
} | ||
} |
Oops, something went wrong.