Webhook作成数を制限

This commit is contained in:
shibafu
2020-07-23 22:36:08 +09:00
parent 08e12cd218
commit 059c6d69cf
3 changed files with 23 additions and 10 deletions

View File

@@ -7,6 +7,9 @@ use Illuminate\Support\Str;
class CheckinWebhook extends Model
{
/** @var int ユーザーごとの作成数制限 */
const PER_USER_LIMIT = 10;
public $incrementing = false;
protected $keyType = 'string';

View File

@@ -79,8 +79,9 @@ class SettingController extends Controller
public function webhooks()
{
$webhooks = Auth::user()->checkinWebhooks;
$webhooksLimit = CheckinWebhook::PER_USER_LIMIT;
return view('setting.webhooks')->with(compact('webhooks'));
return view('setting.webhooks')->with(compact('webhooks', 'webhooksLimit'));
}
public function storeWebhooks(Request $request)
@@ -89,6 +90,11 @@ class SettingController extends Controller
'name' => 'required|string|max:255'
]);
if (Auth::user()->checkinWebhooks()->count() >= CheckinWebhook::PER_USER_LIMIT) {
return redirect()->route('setting.webhooks')
->with('status', CheckinWebhook::PER_USER_LIMIT . '件以上のWebhookを作成することはできません。');
}
Auth::user()->checkinWebhooks()->create($validated);
return redirect()->route('setting.webhooks')->with('status', '作成しました。');