mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-11 13:57:41 -08:00
296de34e8a
I'm going ahead and merging this, since the upgrade doesn't break Flysystem any worse than the current develop is broken, so far as I can tell. * Upgraded framework to Laravel 6 ### TO DO: - Fix password restriction rules- the old library isn’t compatible with Laravel 6 :( - Figure out why in-app API calls are returning “Unauthorized” * More updates from Input:: to Request:: helper * Switch to Request:: from Input * Added passport config * Fixed goofy password minimum in seeder * Added laravel/helpers * Changed ($item) to ($item->id) in forms I have no idea why this is necessary * Changed ($item) to ($item->id) in forms * Updated API middleware to auth:api * Updated with added laravel auth.php values * FIxed *&!^$%^&$^%!!!! ajax issue * Switch to Request::get from Input::get * Switched to Request facade * Added password security minimums back in The package we were using has not been updated to Laravel v6, so I created custom validators instead * Added language strings for error messages for password rules * Fixed `($item)` issue in formActions for partials
165 lines
5.4 KiB
PHP
Executable file
165 lines
5.4 KiB
PHP
Executable file
<?php
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Helpers\Helper;
|
|
use App\Models\Group;
|
|
use Illuminate\Support\Facades\Input;
|
|
|
|
/**
|
|
* This controller handles all actions related to User Groups for
|
|
* the Snipe-IT Asset Management application.
|
|
*
|
|
* @version v1.0
|
|
*/
|
|
class GroupsController extends Controller
|
|
{
|
|
/**
|
|
* Returns a view that invokes the ajax tables which actually contains
|
|
* the content for the user group listing, which is generated in getDatatable.
|
|
*
|
|
* @author [A. Gianotto] [<snipe@snipe.net]
|
|
* @see GroupsController::getDatatable() method that generates the JSON response
|
|
* @since [v1.0]
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function index()
|
|
{
|
|
// Show the page
|
|
return view('groups/index');
|
|
}
|
|
|
|
/**
|
|
* Returns a view that displays a form to create a new User Group.
|
|
*
|
|
* @author [A. Gianotto] [<snipe@snipe.net]
|
|
* @see GroupsController::postCreate()
|
|
* @since [v1.0]
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function create()
|
|
{
|
|
$group = new Group;
|
|
// Get all the available permissions
|
|
$permissions = config('permissions');
|
|
$groupPermissions = Helper::selectedPermissionsArray($permissions, $permissions);
|
|
$selectedPermissions = Request::old('permissions', $groupPermissions);
|
|
|
|
// Show the page
|
|
return view('groups/edit', compact('permissions', 'selectedPermissions', 'groupPermissions'))->with('group', $group);
|
|
}
|
|
|
|
/**
|
|
* Validates and stores the new User Group data.
|
|
*
|
|
* @author [A. Gianotto] [<snipe@snipe.net]
|
|
* @see GroupsController::getCreate()
|
|
* @since [v1.0]
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
*/
|
|
public function store()
|
|
{
|
|
// create a new group instance
|
|
$group = new Group();
|
|
$group->name = e(Request::get('name'));
|
|
$group->permissions = json_encode(Request::get('permission'));
|
|
|
|
if ($group->save()) {
|
|
return redirect()->route("groups.index")->with('success', trans('admin/groups/message.success.create'));
|
|
}
|
|
return redirect()->back()->withInput()->withErrors($group->getErrors());
|
|
}
|
|
|
|
/**
|
|
* Returns a view that presents a form to edit a User Group.
|
|
*
|
|
* @author [A. Gianotto] [<snipe@snipe.net]
|
|
* @see GroupsController::postEdit()
|
|
* @param int $id
|
|
* @since [v1.0]
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
$group = Group::find($id);
|
|
|
|
if ($group) {
|
|
$permissions = config('permissions');
|
|
$groupPermissions = $group->decodePermissions();
|
|
$selected_array = Helper::selectedPermissionsArray($permissions, $groupPermissions);
|
|
return view('groups.edit', compact('group', 'permissions', 'selected_array', 'groupPermissions'));
|
|
}
|
|
|
|
return redirect()->route('groups.index')->with('error', trans('admin/groups/message.group_not_found'));
|
|
}
|
|
|
|
/**
|
|
* Validates and stores the updated User Group data.
|
|
*
|
|
* @author [A. Gianotto] [<snipe@snipe.net]
|
|
* @see GroupsController::getEdit()
|
|
* @param int $id
|
|
* @since [v1.0]
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
*/
|
|
public function update($id = null)
|
|
{
|
|
if (!$group = Group::find($id)) {
|
|
return redirect()->route('groups.index')->with('error', trans('admin/groups/message.group_not_found', compact('id')));
|
|
}
|
|
$group->name = e(Request::get('name'));
|
|
$group->permissions = json_encode(Request::get('permission'));
|
|
|
|
if (!config('app.lock_passwords')) {
|
|
if ($group->save()) {
|
|
return redirect()->route('groups.index')->with('success', trans('admin/groups/message.success.update'));
|
|
}
|
|
return redirect()->back()->withInput()->withErrors($group->getErrors());
|
|
}
|
|
return redirect()->route('groups.index')->with('error', trans('general.feature_disabled'));
|
|
}
|
|
|
|
/**
|
|
* Validates and deletes the User Group.
|
|
*
|
|
* @author [A. Gianotto] [<snipe@snipe.net]
|
|
* @see GroupsController::getEdit()
|
|
* @param int $id
|
|
* @since [v1.0]
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
* @throws \Exception
|
|
*/
|
|
public function destroy($id = null)
|
|
{
|
|
if (!config('app.lock_passwords')) {
|
|
if (!$group = Group::find($id)) {
|
|
return redirect()->route('groups.index')->with('error', trans('admin/groups/message.group_not_found', compact('id')));
|
|
}
|
|
$group->delete();
|
|
// Redirect to the group management page
|
|
return redirect()->route('groups.index')->with('success', trans('admin/groups/message.success.delete'));
|
|
}
|
|
return redirect()->route('groups.index')->with('error', trans('general.feature_disabled'));
|
|
}
|
|
|
|
/**
|
|
* Returns a view that invokes the ajax tables which actually contains
|
|
* the content for the group detail page.
|
|
*
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
* @param $id
|
|
* @return \Illuminate\Contracts\View\View
|
|
* @since [v4.0.11]
|
|
*/
|
|
public function show($id)
|
|
{
|
|
$group = Group::find($id);
|
|
|
|
if ($group) {
|
|
return view('groups/view', compact('group'));
|
|
}
|
|
|
|
return redirect()->route('groups.index')->with('error', trans('admin/groups/message.group_not_found', compact('id')));
|
|
}
|
|
|
|
}
|