Skip to content

Commit

Permalink
Merge pull request #1342 from shikorism/develop
Browse files Browse the repository at this point in the history
Release 2024.11.1
  • Loading branch information
shibafu528 authored Nov 23, 2024
2 parents d374a8c + f8c031c commit b0da57d
Show file tree
Hide file tree
Showing 53 changed files with 2,865 additions and 925 deletions.
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2.1
executors:
build:
docker:
- image: cimg/php:8.1-browsers
- image: cimg/php:8.2-browsers
environment:
APP_DEBUG: true
APP_ENV: testing
Expand Down Expand Up @@ -115,6 +115,7 @@ jobs:
# Run unit test
- run:
command: |
php artisan passport:install -n
mkdir -p /tmp/phpunit{,-coverage}
./vendor/bin/phpunit --log-junit /tmp/phpunit/phpunit.xml --coverage-clover=/tmp/phpunit-coverage/coverage.xml
when: always
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ a.k.a. shikorism.net

## 実行環境

- PHP 8.1
- PHP 8.2
- PostgreSQL 14

> [!WARNING]
Expand Down
64 changes: 64 additions & 0 deletions app/Http/Controllers/Admin/ReportController.php
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', 'モデレーションを実行しました。');
}
}
51 changes: 51 additions & 0 deletions app/Http/Controllers/Admin/RuleController.php
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', '通報理由を削除しました。');
}
}
5 changes: 5 additions & 0 deletions app/Http/Controllers/EjaculationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,9 @@ public function tools()
{
return view('ejaculation.tools');
}

public function report()
{

}
}
44 changes: 44 additions & 0 deletions app/Http/Controllers/EjaculationReportController.php
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', 'チェックインを報告しました。');
}
}
37 changes: 37 additions & 0 deletions app/Http/Requests/AdminRuleStoreRequest.php
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' => 'ルール',
];
}
}
54 changes: 54 additions & 0 deletions app/Http/Requests/EjaculationReportRequest.php
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' => '詳しい内容を入力してください。',
];
}
}
59 changes: 59 additions & 0 deletions app/Mail/EjaculationReported.php
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 [];
}
}
Loading

0 comments on commit b0da57d

Please sign in to comment.