<?php declare(strict_types=1);
/*
** Copyright (C) 2021-2026 initMAX s.r.o.
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/


namespace Modules\uxMAX\Includes;

/**
 * Opt a READ-ONLY action out of the frontend's request guard.
 *
 * Zabbix 6.0/6.2 guard requests with a `sid` form field
 * (CController::checkSID / disableSIDvalidation); 6.4 replaced that with a CSRF
 * token and renamed the opt-out to disableCsrfValidation(). Calling the wrong
 * one is not a warning: on 6.0/6.2 the action answers "Access denied" and the
 * page is simply gone, with nothing in the console to say why.
 *
 * Only read-only actions use this. The write actions keep the guard on and let
 * the form supply whatever the frontend asks for - see Compat::csrfVars(),
 * plus CForm, which adds `sid` by itself on 6.0/6.2.
 */
trait RequestGuard {

    protected function disableUxmaxRequestGuard(): void {
        if (method_exists($this, 'disableCsrfValidation')) {
            $this->disableCsrfValidation();

            return;
        }

        if (method_exists($this, 'disableSIDvalidation')) {
            $this->disableSIDvalidation();
        }
    }
}
