Webhook作成数を制限
This commit is contained in:
		| @@ -7,6 +7,9 @@ use Illuminate\Support\Str; | |||||||
|  |  | ||||||
| class CheckinWebhook extends Model | class CheckinWebhook extends Model | ||||||
| { | { | ||||||
|  |     /** @var int ユーザーごとの作成数制限 */ | ||||||
|  |     const PER_USER_LIMIT = 10; | ||||||
|  |  | ||||||
|     public $incrementing = false; |     public $incrementing = false; | ||||||
|     protected $keyType = 'string'; |     protected $keyType = 'string'; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -79,8 +79,9 @@ class SettingController extends Controller | |||||||
|     public function webhooks() |     public function webhooks() | ||||||
|     { |     { | ||||||
|         $webhooks = Auth::user()->checkinWebhooks; |         $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) |     public function storeWebhooks(Request $request) | ||||||
| @@ -89,6 +90,11 @@ class SettingController extends Controller | |||||||
|             'name' => 'required|string|max:255' |             '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); |         Auth::user()->checkinWebhooks()->create($validated); | ||||||
|  |  | ||||||
|         return redirect()->route('setting.webhooks')->with('status', '作成しました。'); |         return redirect()->route('setting.webhooks')->with('status', '作成しました。'); | ||||||
|   | |||||||
| @@ -13,6 +13,9 @@ | |||||||
|             <p>Webhook APIは予告なく仕様変更を行う場合がございます。また、サーバに対する過剰なリクエストや、不審な公開チェックインを繰り返している場合には管理者の裁量によって予告なく無効化(削除)する場合があります。</p> |             <p>Webhook APIは予告なく仕様変更を行う場合がございます。また、サーバに対する過剰なリクエストや、不審な公開チェックインを繰り返している場合には管理者の裁量によって予告なく無効化(削除)する場合があります。</p> | ||||||
|             <p>通常利用と同様、1分以内のチェックインは禁止されていることを考慮してください。また、テスト目的であれば非公開チェックインをご活用ください。</p> |             <p>通常利用と同様、1分以内のチェックインは禁止されていることを考慮してください。また、テスト目的であれば非公開チェックインをご活用ください。</p> | ||||||
|             <hr> |             <hr> | ||||||
|  |             @if (count($webhooks) >= $webhooksLimit) | ||||||
|  |                 <p class="my-0 text-danger">1ユーザーが作成可能なWebhookは、{{ $webhooksLimit }}件までに制限されています。</p> | ||||||
|  |             @else | ||||||
|                 <form action="{{ route('setting.webhooks.store') }}" method="post"> |                 <form action="{{ route('setting.webhooks.store') }}" method="post"> | ||||||
|                     {{ csrf_field() }} |                     {{ csrf_field() }} | ||||||
|                     <div class="form-group"> |                     <div class="form-group"> | ||||||
| @@ -22,6 +25,7 @@ | |||||||
|                     </div> |                     </div> | ||||||
|                     <button class="btn btn-primary" type="submit">新規作成</button> |                     <button class="btn btn-primary" type="submit">新規作成</button> | ||||||
|                 </form> |                 </form> | ||||||
|  |             @endif | ||||||
|         </div> |         </div> | ||||||
|     </div> |     </div> | ||||||
|     @if (!empty($webhooks)) |     @if (!empty($webhooks)) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 shibafu
					shibafu