Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 0 additions & 56 deletions ajax/dropdownZone.php

This file was deleted.

69 changes: 0 additions & 69 deletions ajax/toggleZoneDownload.php

This file was deleted.

3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"php-http/message-factory": "^1.1"
},
"require-dev": {
"glpi-project/tools": "^0.8.1",
"marcocesarato/php-conventional-changelog": "^1.17"
"glpi-project/tools": "^0.8.1"
},
"config": {
"optimize-autoloader": true,
Expand Down
80 changes: 1 addition & 79 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ parameters:
paths:
- src
- front
- ajax
- install
- hook.php
- setup.php
Expand Down
1 change: 0 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

return RectorConfig::configure()
->withPaths([
__DIR__ . '/ajax',
__DIR__ . '/front',
__DIR__ . '/install',
__DIR__ . '/public',
Expand Down
106 changes: 106 additions & 0 deletions src/Controller/AjaxController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php

/**
* -------------------------------------------------------------------------
* Carbon plugin for GLPI
*
* @copyright Copyright (C) 2024-2025 Teclib' and contributors.
* @license https://www.gnu.org/licenses/gpl-3.0.txt GPLv3+
* @link https://github.com/pluginsGLPI/carbon
*
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of Carbon plugin for GLPI.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* -------------------------------------------------------------------------
*/

namespace GlpiPlugin\Carbon\Controller;

use Config as GlpiConfig;
use Glpi\Controller\AbstractController;
use Glpi\Http\Firewall;
use Glpi\Security\Attribute\SecurityStrategy;
use GlpiPlugin\Carbon\Source;
use GlpiPlugin\Carbon\Source_Zone;
use GlpiPlugin\Carbon\Zone;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;

class AjaxController extends AbstractController
{
#[SecurityStrategy(Firewall::STRATEGY_AUTHENTICATED)]
#[Route(
path: 'ajax/dropdownZone.php',
name: 'ajax dropdownZone',
methods: ['GET', 'POST']
)]
public function showDropdownBySourceCondition(Request $request): Response
{
// if method is GET, then throw an exception, workaround bug in GLPI up to 11.0.7
if ($request->isMethod('GET')) {
return new Response('', 403);
}

if (!Zone::canView()) {
return new Response('', 403);
}

$source_id = (int) $_POST['plugin_carbon_sources_id'];
$html = Zone::dropdown([
'display' => false,
'rand' => (int) $request->request->get('dom_id'),
'condition' => Zone::getRestrictBySourceCondition($source_id),
'specific_tags' => ($source_id === 0 ? ['disabled' => 'disabled'] : []),
]);
return new Response($html);
}

#[SecurityStrategy(Firewall::STRATEGY_AUTHENTICATED)]
#[Route(
path: 'ajax/toggleZoneDownload.php',
name: 'ajax toggle zone download flag',
methods: ['GET', 'POST']
)]
public function toggleZoneDownload(Request $request): Response
{
// if method is GET, then throw an exception, workaround bug in GLPI up to 11.0.7
if ($request->isMethod('GET')) {
return new Response('', 403);
}

if (!Source::canView() || ! GlpiConfig::canUpdate()) {
return new Response(__('Access denied.', 'carbon'), 403);
}

if (!isset($_POST['id'])) {
return new Response(__('Bad request.', 'carbon'), 400);
}

$source_zone = new Source_Zone();
if (!$source_zone->getFromDB($request->request->get('id'))) {
return new Response(__('Item not found.', 'carbon'), 403);
}
if (!$source_zone->toggleZone()) {
return new Response(__('Update failed.', 'carbon'), 500);
}

return new Response();
}
}
2 changes: 1 addition & 1 deletion src/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function prepareInputForUpdate($input)
}
}

if (($input['plugin_carbon_sources_id'] ?? 0) == 0) {
if (isset($input['plugin_carbon_sources_id']) && $input['plugin_carbon_sources_id'] == 0) {
$input['plugin_carbon_sources_zones_id'] = 0;
}

Expand Down
Loading
Loading