diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php index 2f944ee..ace5453 100644 --- a/app/Http/Controllers/Admin/UserController.php +++ b/app/Http/Controllers/Admin/UserController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin; use App\Facade\Theme; use App\Facade\UserConfig; +use App\Group; use App\User; use App\Http\Requests; @@ -119,7 +120,14 @@ class UserController extends Controller App::abort(404); } - return Theme::render('admin.edit_user', ['user' => $user]); + $groups = Group::orderBy('name')->get(); + $usersGroups = []; + foreach ($user->groups()->get() as $group) + { + $usersGroups[] = $group->id; + } + + return Theme::render('admin.edit_user', ['user' => $user, 'groups' => $groups, 'users_groups' => $usersGroups]); } /** @@ -167,6 +175,24 @@ class UserController extends Controller $user->activation_token = null; } + // Sync the group memberships + $data = $request->all(); + $syncData = []; + + if (isset($data['user_group_id'])) + { + foreach ($data['user_group_id'] as $groupID) + { + $syncData[$groupID] = ['created_at' => new \DateTime(), 'updated_at' => new \DateTime()]; + } + + $user->groups()->sync($syncData); + } + else + { + $user->groups()->detach(); + } + $user->save(); return redirect(route('users.index')); diff --git a/app/User.php b/app/User.php index 6121de8..8aee66a 100644 --- a/app/User.php +++ b/app/User.php @@ -40,4 +40,9 @@ class User extends Authenticatable return $user; } + + public function groups() + { + return $this->belongsToMany(Group::class, 'user_groups'); + } } diff --git a/database/migrations/2017_02_13_154940_create_user_groups_table.php b/database/migrations/2017_02_13_154940_create_user_groups_table.php new file mode 100644 index 0000000..f742719 --- /dev/null +++ b/database/migrations/2017_02_13_154940_create_user_groups_table.php @@ -0,0 +1,40 @@ +unsignedInteger('user_id'); + $table->unsignedInteger('group_id'); + + $table->foreign('user_id') + ->references('id')->on('users') + ->onDelete('cascade'); + $table->foreign('group_id') + ->references('id')->on('groups') + ->onDelete('cascade'); + + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('user_groups'); + } +} diff --git a/resources/build/build.php b/resources/build/build.php index 5ec23ac..3cba6ca 100644 --- a/resources/build/build.php +++ b/resources/build/build.php @@ -24,7 +24,7 @@ $ignoredFiles = [ ]; echo 'Blue Twilight Packaging Script' . PHP_EOL; -echo '(c) Andy Heathershaw 2016' . PHP_EOL; +echo '(c) Andy Heathershaw 2016-2017' . PHP_EOL; echo '------------------------------' . PHP_EOL . PHP_EOL; if ($argc != 2) @@ -34,7 +34,7 @@ if ($argc != 2) } echo 'Checking current folder...' . PHP_EOL . PHP_EOL; -$appRoot = __DIR__; +$appRoot = dirname(dirname(__DIR__)); if (getcwd() != $appRoot) { echo sprintf('The build script must be run in the application root - %s', $appRoot) . PHP_EOL; @@ -45,7 +45,7 @@ echo 'Updating app.version config value...' . PHP_EOL . PHP_EOL; $appConfigFile = sprintf('%s/config/app.php', $appRoot); file_put_contents($appConfigFile, str_replace('**DEV**', $argv[1], file_get_contents($appConfigFile))); -echo 'Downloading Composer...' . PHP_EOL . PHP_EOL; +/*echo 'Downloading Composer...' . PHP_EOL . PHP_EOL; copy('https://getcomposer.org/installer', 'composer-setup.php'); if (hash_file('SHA384', 'composer-setup.php') === trim(file_get_contents('https://composer.github.io/installer.sig'))) { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); exit; } echo PHP_EOL; @@ -66,7 +66,7 @@ $sgCommand = sprintf( PROJECT_ID, PROJECT_KEY ); -system($sgCommand); +system($sgCommand);*/ echo 'Creating the release archive...' . PHP_EOL . PHP_EOL; diff --git a/resources/lang/en/admin.php b/resources/lang/en/admin.php index 51dc8ba..9613678 100644 --- a/resources/lang/en/admin.php +++ b/resources/lang/en/admin.php @@ -160,6 +160,9 @@ return [ 'upload_single_file_text2' => 'Your web server is configured to allow files up to :file_size. If you browser does not support HTML 5 (most modern browsers do), the combined size of all selected files must be less than :max_upload_size.', 'user_deletion_failed' => 'An error occurred while removing :name\'s user account: :error_message', 'user_deletion_successful' => 'The user account for :name was removed successfully.', + 'user_details_tab' => 'Details', + 'user_groups_list_select' => 'Select the group(s) this user will belong to. :name will then inherit all permissions from these groups.', + 'user_groups_tab' => 'Groups', 'user_pending' => 'Pending activation', 'users_title' => 'User accounts', 'visitor_analytics_heading' => 'Visitor analytics', diff --git a/resources/views/themes/base/admin/edit_user.blade.php b/resources/views/themes/base/admin/edit_user.blade.php index 6008a2b..6fdc71b 100644 --- a/resources/views/themes/base/admin/edit_user.blade.php +++ b/resources/views/themes/base/admin/edit_user.blade.php @@ -23,82 +23,113 @@
{!! Form::model($user, ['route' => ['users.update', $user->id], 'method' => 'PUT']) !!} -
-
-
- {!! Form::label('name', trans('forms.name_label'), ['class' => 'control-label']) !!} - {!! Form::text('name', old('name'), ['class' => 'form-control']) !!} +
+ {{-- Nav tabs --}} + - @if ($errors->has('name')) - - {{ $errors->first('name') }} - + {{-- Tab panes --}} +
+ {{-- Details --}} +
+
+
+
+ {!! Form::label('name', trans('forms.name_label'), ['class' => 'control-label']) !!} + {!! Form::text('name', old('name'), ['class' => 'form-control']) !!} + + @if ($errors->has('name')) + + {{ $errors->first('name') }} + + @endif +
+
+ +
+
+ {!! Form::label('email', trans('forms.email_label'), ['class' => 'control-label']) !!} + {!! Form::text('email', old('email'), ['class' => 'form-control']) !!} + + @if ($errors->has('email')) + + {{ $errors->first('email') }} + + @endif +
+
+
+ +
+
+
+ {!! Form::label('password', trans('forms.password_label'), ['class' => 'control-label']) !!} + {!! Form::password('password', ['class' => 'form-control']) !!} + + @if ($errors->has('password')) + + {{ $errors->first('password') }} + + @endif +
+
+ +
+
+ {!! Form::label('password_confirmation', trans('forms.password_confirm_label'), ['class' => 'control-label']) !!} + {!! Form::password('password_confirmation', ['class' => 'form-control']) !!} + + @if ($errors->has('password_confirmation')) + + {{ $errors->first('password_confirmation') }} + + @endif +
+
+
+ +
+ +
+ + @if (!$user->is_activated) +
+ +
+ @endif +
+ + {{-- Groups --}} +
+ @if ($groups->count() > 0) +

@lang('admin.user_groups_list_select', ['name' => $user->name])

+ + @foreach ($groups as $group) +
+ +
+ @endforeach + @else @endif
-
-
- {!! Form::label('email', trans('forms.email_label'), ['class' => 'control-label']) !!} - {!! Form::text('email', old('email'), ['class' => 'form-control']) !!} - - @if ($errors->has('email')) - - {{ $errors->first('email') }} - - @endif -
+
+ @lang('forms.cancel_action') + {!! Form::submit(trans('forms.save_action'), ['class' => 'btn btn-success']) !!}
- -
-
-
- {!! Form::label('password', trans('forms.password_label'), ['class' => 'control-label']) !!} - {!! Form::password('password', ['class' => 'form-control']) !!} - - @if ($errors->has('password')) - - {{ $errors->first('password') }} - - @endif -
-
- -
-
- {!! Form::label('password_confirmation', trans('forms.password_confirm_label'), ['class' => 'control-label']) !!} - {!! Form::password('password_confirmation', ['class' => 'form-control']) !!} - - @if ($errors->has('password_confirmation')) - - {{ $errors->first('password_confirmation') }} - - @endif -
-
-
- -
- -
- - @if (!$user->is_activated) -
- -
- @endif - -
- @lang('forms.cancel_action') - {!! Form::submit(trans('forms.save_action'), ['class' => 'btn btn-success']) !!} -
{!! Form::close() !!}