Files
librenms-librenms/app/Http/Controllers/Form/CopyDashboardController.php
Tony Murray 28d69c5230 Update php packages and fix composer warnings (#12526)
composer/ca-bundle (1.2.8 => 1.2.9)
composer/composer (2.0.8 => 2.0.9)
facade/ignition (2.5.8 => 2.5.11)
filp/whoops (2.9.1 => 2.9.2)
friendsofphp/php-cs-fixer (v2.17.3 => v2.18.2)
laravel/dusk (v6.11.0 => v6.11.3)
laravel/framework (v8.24.0 => v8.27.0)
laravel/tinker (v2.5.0 => v2.6.0)
maximebf/debugbar (v1.16.4 => v1.16.5)
nesbot/carbon (2.44.0 => 2.45.1)
nunomaduro/collision (v5.1.0 => v5.3.0)
phpunit/phpunit (9.5.1 => 9.5.2)
psy/psysh (v0.10.5 => v0.10.6)
symfony/console (v5.2.2 => v5.2.3)
symfony/css-selector (v5.2.2 => v5.2.3)
symfony/error-handler (v5.2.2 => v5.2.3)
symfony/event-dispatcher (v5.2.2 => v5.2.3)
symfony/filesystem (v5.2.1 => v5.2.3)
symfony/finder (v5.2.2 => v5.2.3)
symfony/http-foundation (v5.2.2 => v5.2.3)
symfony/http-kernel (v5.2.2 => v5.2.3)
symfony/mime (v5.2.2 => v5.2.3)
symfony/options-resolver (v5.2.1 => v5.2.3)
symfony/process (v5.2.2 => v5.2.3)
symfony/routing (v5.2.2 => v5.2.3)
symfony/stopwatch (v5.2.1 => v5.2.3)
symfony/string (v5.2.2 => v5.2.3)
symfony/translation (v5.2.2 => v5.2.3)
symfony/var-dumper (v5.2.2 => v5.2.3)
symfony/yaml (v4.4.18 => v4.4.19)
2021-02-14 21:50:32 -06:00

82 lines
2.5 KiB
PHP

<?php
/**
* CopyDashboardController.php
*
* -Description-
*
* 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/>.
*
* @link https://www.librenms.org
* @copyright 2020 Thomas Berberich
* @author Thomas Berberich <sourcehhdoctor@gmail.com>
*/
namespace App\Http\Controllers\Form;
use App\Http\Controllers\Controller;
use App\Models\Dashboard;
use App\Models\UserWidget;
use Auth;
use Illuminate\Http\Request;
class CopyDashboardController extends Controller
{
public function store(Request $request)
{
$target_user_id = $request->get('target_user_id');
$dashboard_id = $request->get('dashboard_id');
$dashboard = Dashboard::where(['dashboard_id' => $dashboard_id, 'user_id' => Auth::id()])->first();
$success = true;
if ((empty($dashboard)) || (empty($target_user_id))) {
$success = false;
}
if ($success) {
$dashboard_copy = $dashboard->replicate()->fill([
'user_id' => $target_user_id,
'dashboard_name' => $dashboard['dashboard_name'] .= '_' . Auth::user()->username,
]);
$success = $dashboard_copy->save();
}
if ($success) {
$widgets = UserWidget::where(['dashboard_id' => $dashboard_id, 'user_id' => Auth::id()])->get();
foreach ($widgets as $widget) {
$widget_copy = $widget->replicate()->fill([
'user_id' => $target_user_id,
'dashboard_id' => $dashboard_copy->dashboard_id,
]);
$success &= $widget_copy->save();
}
}
if ($success) {
$status = 'ok';
$message = 'Dashboard copied';
} else {
$status = 'error';
$message = 'ERROR: Could not copy Dashboard';
}
return response()->json([
'status' => $status,
'message' => $message,
]);
}
}