Webhook作成数を制限
This commit is contained in:
		@@ -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';
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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', '作成しました。');
 | 
			
		||||
 
 | 
			
		||||
@@ -13,15 +13,19 @@
 | 
			
		||||
            <p>Webhook APIは予告なく仕様変更を行う場合がございます。また、サーバに対する過剰なリクエストや、不審な公開チェックインを繰り返している場合には管理者の裁量によって予告なく無効化(削除)する場合があります。</p>
 | 
			
		||||
            <p>通常利用と同様、1分以内のチェックインは禁止されていることを考慮してください。また、テスト目的であれば非公開チェックインをご活用ください。</p>
 | 
			
		||||
            <hr>
 | 
			
		||||
            <form action="{{ route('setting.webhooks.store') }}" method="post">
 | 
			
		||||
                {{ csrf_field() }}
 | 
			
		||||
                <div class="form-group">
 | 
			
		||||
                    <label for="name">名前 (メモ)</label>
 | 
			
		||||
                    <input id="name" class="form-control" name="name" type="text" required>
 | 
			
		||||
                    <small class="form-text text-muted">後で分かるように名前を付けておいてください。</small>
 | 
			
		||||
                </div>
 | 
			
		||||
                <button class="btn btn-primary" type="submit">新規作成</button>
 | 
			
		||||
            </form>
 | 
			
		||||
            @if (count($webhooks) >= $webhooksLimit)
 | 
			
		||||
                <p class="my-0 text-danger">1ユーザーが作成可能なWebhookは、{{ $webhooksLimit }}件までに制限されています。</p>
 | 
			
		||||
            @else
 | 
			
		||||
                <form action="{{ route('setting.webhooks.store') }}" method="post">
 | 
			
		||||
                    {{ csrf_field() }}
 | 
			
		||||
                    <div class="form-group">
 | 
			
		||||
                        <label for="name">名前 (メモ)</label>
 | 
			
		||||
                        <input id="name" class="form-control" name="name" type="text" required>
 | 
			
		||||
                        <small class="form-text text-muted">後で分かるように名前を付けておいてください。</small>
 | 
			
		||||
                    </div>
 | 
			
		||||
                    <button class="btn btn-primary" type="submit">新規作成</button>
 | 
			
		||||
                </form>
 | 
			
		||||
            @endif
 | 
			
		||||
        </div>
 | 
			
		||||
    </div>
 | 
			
		||||
    @if (!empty($webhooks))
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user