From d40289fbc912415ce35bb74911c1522274a52a5d Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 28 Apr 2016 21:59:43 -0700 Subject: [PATCH] Fixes #1997 and #1996 - replace sentry functions --- app/Http/Controllers/UsersController.php | 42 +++++++++--------------- app/Models/Group.php | 2 +- app/Models/User.php | 6 ++++ resources/views/users/edit.blade.php | 33 ++++++++++++------- 4 files changed, 44 insertions(+), 39 deletions(-) diff --git a/app/Http/Controllers/UsersController.php b/app/Http/Controllers/UsersController.php index 229d55901d..83c57c508d 100755 --- a/app/Http/Controllers/UsersController.php +++ b/app/Http/Controllers/UsersController.php @@ -7,6 +7,7 @@ use App\Helpers\Helper; use App\Models\Accessory; use App\Models\Actionlog; use App\Models\Asset; +use App\Models\Group; use App\Models\Company; use App\Models\Location; use App\Models\Setting; @@ -64,24 +65,21 @@ class UsersController extends Controller { // Selected groups - $userGroups = Input::old('groups', array()); + if (Input::has('groups')) { + $userGroups = Group::pluck('name', 'id')->whereIn('id',Input::get('groups')); + } else { + $userGroups = collect(); + } - // Get all the available permissions $permissions = config('permissions'); + $groups = Group::pluck('name', 'id'); + $userPermissions = Helper::selectedPermissionsArray($permissions, Input::old('groups', array())); + - // Selected permissions - $userPermissions = Input::old('permissions', array('superuser' => -1)); $location_list = Helper::locationsList(); $manager_list = Helper::managerList(); $company_list = Helper::companyList(); - /* echo '
';
-          print_r($userPermissions);
-          echo '
'; - exit; - */ - - // Show the page return View::make('users/edit', compact('groups', 'userGroups', 'permissions', 'userPermissions')) ->with('location_list', $location_list) ->with('manager_list', $manager_list) @@ -132,9 +130,9 @@ class UsersController extends Controller } /** - * JSON handler for creating a user through a modal + * JSON handler for creating a user through a modal popup * - * @author [A. Gianotto] [] + * @author [B. Wetherington] [] * @since [v1.8] * @return string JSON */ @@ -185,25 +183,17 @@ class UsersController extends Controller try { // Get the user information $user = User::find($id); + $permissions = config('permissions'); if (!Company::isCurrentUserHasAccess($user)) { return redirect()->route('users')->with('error', trans('general.insufficient_permissions')); } - // Get this user groups - $userGroups = $user->groups()->lists('group_id', 'name'); - //$userGroups = null; + $groups = Group::pluck('name', 'id'); - // Get this user permissions - $userPermissions = null; - //$this->encodePermissions($userPermissions); - - // Get a list of all the available groups - //$groups = Sentry::getGroupProvider()->findAll(); - - // Get all the available permissions - $permissions = config('permissions'); - //$this->encodeAllPermissions($permissions); + $userGroups = $user->groups()->pluck('name', 'id'); + $user->permissions = $user->decodePermissions(); + $userPermissions = Helper::selectedPermissionsArray($permissions, $user->permissions); $location_list = Helper::locationsList(); $company_list = Helper::companyList(); diff --git a/app/Models/Group.php b/app/Models/Group.php index 7f5597c626..b54668ff6d 100755 --- a/app/Models/Group.php +++ b/app/Models/Group.php @@ -39,5 +39,5 @@ class Group extends Model } - + } diff --git a/app/Models/User.php b/app/Models/User.php index e0abe41e60..289a5b3460 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -307,6 +307,12 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon } + + public function decodePermissions() + { + return json_decode($this->permissions, true); + } + /** * Query builder scope to search on text * diff --git a/resources/views/users/edit.blade.php b/resources/views/users/edit.blade.php index d98674759e..efd850cfb9 100755 --- a/resources/views/users/edit.blade.php +++ b/resources/views/users/edit.blade.php @@ -162,7 +162,7 @@ input[type='text'][disabled], input[disabled], textarea[disabled], input[readonl - +
@@ -242,7 +242,7 @@ input[type='text'][disabled], input[disabled], textarea[disabled], input[readonl
-
+
@@ -251,19 +251,28 @@ input[type='text'][disabled], input[disabled], textarea[disabled], input[readonl
-
- -
-
+
+ +
+
- - {{ trans('admin/users/table.groupnotes') }} + + + {{ trans('admin/users/table.groupnotes') }} + + +
+
+
@if (!$user->id)