Back-end user groups can now be marked to add new administrators by default
Streamline naming of backend user groups Add description field to backend user group table
This commit is contained in:
parent
25f9b7f63c
commit
e3dae22758
|
|
@ -1,5 +1,6 @@
|
|||
* **Build 16x** (2014-12-x)
|
||||
- Native `alert` and `confirm` functions have been styled in the back-end.
|
||||
- Back-end user groups can now be marked to add new administrators by default. This affects when a group is created (if checked, all administrators are added to the group) and creating a new administrator (the default groups are checked by default).
|
||||
|
||||
* **Build 168** (2014-12-14)
|
||||
- Config item `cms.customErrorPage` is deprecated, the setting `app.debug` should be used instead.
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ use Backend\Classes\Controller;
|
|||
* @author Alexey Bobkov, Samuel Georges
|
||||
*
|
||||
*/
|
||||
class Groups extends Controller
|
||||
class UserGroups extends Controller
|
||||
{
|
||||
public $implement = [
|
||||
'Backend.Behaviors.FormController',
|
||||
|
|
@ -4,6 +4,7 @@ use Backend;
|
|||
use Redirect;
|
||||
use BackendMenu;
|
||||
use BackendAuth;
|
||||
use Backend\Models\UserGroup;
|
||||
use Backend\Classes\Controller;
|
||||
use System\Classes\SettingsManager;
|
||||
|
||||
|
|
@ -85,6 +86,7 @@ class Users extends Controller
|
|||
|
||||
/**
|
||||
* Add available permission fields to the User form.
|
||||
* Mark default groups as checked for new Users.
|
||||
*/
|
||||
protected function formExtendFields($form)
|
||||
{
|
||||
|
|
@ -121,5 +123,15 @@ class Users extends Controller
|
|||
}
|
||||
|
||||
$form->addTabFields($permissionFields);
|
||||
|
||||
/*
|
||||
* Mark default groups
|
||||
*/
|
||||
if (!$form->model->exists) {
|
||||
$defaultGroupIds = UserGroup::where('is_new_user_default', true)->lists('id');
|
||||
|
||||
$groupField = $form->getField('groups');
|
||||
$groupField->value = $defaultGroupIds;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +0,0 @@
|
|||
<div data-control="toolbar">
|
||||
<a href="<?= Backend::url('backend/groups/create') ?>" class="btn btn-primary oc-icon-plus"><?= e(trans('backend::lang.user.group.new')) ?></a>
|
||||
</div>
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
# ===================================
|
||||
# Form Behavior Config
|
||||
# ===================================
|
||||
|
||||
name: backend::lang.user.group.name
|
||||
form: @/modules/backend/models/group/fields.yaml
|
||||
modelClass: Backend\Models\UserGroup
|
||||
defaultRedirect: backend/groups
|
||||
|
||||
create:
|
||||
redirect: backend/groups/update/:id
|
||||
redirectClose: backend/groups
|
||||
|
||||
update:
|
||||
redirect: backend/groups
|
||||
redirectClose: backend/groups
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
<div data-control="toolbar">
|
||||
<a href="<?= Backend::url('backend/usergroups/create') ?>" class="btn btn-primary oc-icon-plus"><?= e(trans('backend::lang.user.group.new')) ?></a>
|
||||
</div>
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
# ===================================
|
||||
# Form Behavior Config
|
||||
# ===================================
|
||||
|
||||
name: backend::lang.user.group.name
|
||||
form: @/modules/backend/models/usergroup/fields.yaml
|
||||
modelClass: Backend\Models\UserGroup
|
||||
defaultRedirect: backend/usergroups
|
||||
|
||||
create:
|
||||
redirect: backend/usergroups/update/:id
|
||||
redirectClose: backend/usergroups
|
||||
|
||||
update:
|
||||
redirect: backend/usergroups
|
||||
redirectClose: backend/usergroups
|
||||
|
|
@ -3,9 +3,9 @@
|
|||
# ===================================
|
||||
|
||||
title: backend::lang.user.group.list_title
|
||||
list: @/modules/backend/models/group/columns.yaml
|
||||
list: @/modules/backend/models/usergroup/columns.yaml
|
||||
modelClass: Backend\Models\UserGroup
|
||||
recordUrl: backend/groups/update/:id
|
||||
recordUrl: backend/usergroups/update/:id
|
||||
noRecordsMessage: backend::lang.list.no_records
|
||||
recordsPerPage: 5
|
||||
showCheckboxes: true
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
<?php Block::put('breadcrumb') ?>
|
||||
<ul>
|
||||
<li><a href="<?= Backend::url('backend/users') ?>"><?= e(trans('backend::lang.user.menu_label')) ?></a></li>
|
||||
<li><a href="<?= Backend::url('backend/groups') ?>"><?= e(trans('backend::lang.user.group.menu_label')) ?></a></li>
|
||||
<li><a href="<?= Backend::url('backend/usergroups') ?>"><?= e(trans('backend::lang.user.group.menu_label')) ?></a></li>
|
||||
<li><?= e(trans($this->pageTitle)) ?></li>
|
||||
</ul>
|
||||
<?php Block::endPut() ?>
|
||||
|
|
@ -40,5 +40,5 @@
|
|||
|
||||
<?php else: ?>
|
||||
<p class="flash-message static error"><?= e(trans($this->fatalError)) ?></p>
|
||||
<p><a href="<?= Backend::url('backend/groups') ?>" class="btn btn-default"><?= e(trans('backend::lang.user.group.return')) ?></a></p>
|
||||
<p><a href="<?= Backend::url('backend/usergroups') ?>" class="btn btn-default"><?= e(trans('backend::lang.user.group.return')) ?></a></p>
|
||||
<?php endif ?>
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
<?php Block::put('breadcrumb') ?>
|
||||
<ul>
|
||||
<li><a href="<?= Backend::url('backend/users') ?>"><?= e(trans('backend::lang.user.menu_label')) ?></a></li>
|
||||
<li><a href="<?= Backend::url('backend/groups') ?>"><?= e(trans('backend::lang.user.group.menu_label')) ?></a></li>
|
||||
<li><a href="<?= Backend::url('backend/usergroups') ?>"><?= e(trans('backend::lang.user.group.menu_label')) ?></a></li>
|
||||
<li><?= e(trans($this->pageTitle)) ?></li>
|
||||
</ul>
|
||||
<?php Block::endPut() ?>
|
||||
|
|
@ -49,5 +49,5 @@
|
|||
|
||||
<?php else: ?>
|
||||
<p class="flash-message static error"><?= e(trans($this->fatalError)) ?></p>
|
||||
<p><a href="<?= Backend::url('backend/groups') ?>" class="btn btn-default"><?= e(trans('backend::lang.user.group.return')) ?></a></p>
|
||||
<p><a href="<?= Backend::url('backend/usergroups') ?>" class="btn btn-default"><?= e(trans('backend::lang.user.group.return')) ?></a></p>
|
||||
<?php endif ?>
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<div data-control="toolbar">
|
||||
<a href="<?= Backend::url('backend/users/create') ?>" class="btn btn-primary oc-icon-plus"><?= e(trans('backend::lang.user.new')) ?></a>
|
||||
<a href="<?= Backend::url('backend/groups') ?>" class="btn btn-default oc-icon-group"><?= e(trans('backend::lang.user.group.list_title')) ?></a>
|
||||
<a href="<?= Backend::url('backend/usergroups') ?>" class="btn btn-default oc-icon-group"><?= e(trans('backend::lang.user.group.list_title')) ?></a>
|
||||
<?php /* @todo
|
||||
<div class="btn-group">
|
||||
<button
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class DbBackendAddDescriptionField extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
Schema::table('backend_user_groups', function (Blueprint $table) {
|
||||
$table->text('description')->nullable();
|
||||
$table->boolean('is_new_user_default')->default(false);
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::table('backend_user_groups', function (Blueprint $table) {
|
||||
$table->dropColumn('description');
|
||||
$table->dropColumn('is_new_user_default');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -26,7 +26,9 @@ class SeedSetupAdmin extends Seeder
|
|||
public function run()
|
||||
{
|
||||
$group = UserGroup::create([
|
||||
'name' => 'Admins'
|
||||
'name' => 'Admins',
|
||||
'description' => 'Default group for new administrators',
|
||||
'is_new_user_default' => true
|
||||
]);
|
||||
|
||||
$user = User::create([
|
||||
|
|
@ -42,4 +44,5 @@ class SeedSetupAdmin extends Seeder
|
|||
|
||||
$user->addGroup($group);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,6 +97,8 @@ return [
|
|||
'group' => [
|
||||
'name' => 'Group',
|
||||
'name_field' => 'Name',
|
||||
'description_field' => 'Description',
|
||||
'is_new_user_default_field' => 'Add new administrators to this group by default',
|
||||
'menu_label' => 'Groups',
|
||||
'list_title' => 'Manage Groups',
|
||||
'new' => 'New Administrator Group',
|
||||
|
|
|
|||
|
|
@ -96,6 +96,8 @@ class User extends UserBase
|
|||
if ($this->send_invite) {
|
||||
$this->sendInvitation();
|
||||
}
|
||||
|
||||
UserGroup::addUserToDefaultGroups($this);
|
||||
}
|
||||
|
||||
public function sendInvitation()
|
||||
|
|
@ -111,4 +113,13 @@ class User extends UserBase
|
|||
$message->to($this->email, $this->full_name);
|
||||
});
|
||||
}
|
||||
|
||||
public function getGroupsOptions()
|
||||
{
|
||||
$result = [];
|
||||
foreach (UserGroup::all() as $group) {
|
||||
$result[$group->id] = [$group->name, $group->description];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,4 +28,22 @@ class UserGroup extends GroupBase
|
|||
public $belongsToMany = [
|
||||
'users' => ['Backend\Models\User', 'table' => 'backend_users_groups']
|
||||
];
|
||||
|
||||
public function afterCreate()
|
||||
{
|
||||
if ($this->is_new_user_default) {
|
||||
$this->addAllUsersToGroup();
|
||||
}
|
||||
}
|
||||
|
||||
public function addAllUsersToGroup()
|
||||
{
|
||||
$this->users()->sync(User::lists('id'));
|
||||
}
|
||||
|
||||
public static function addUserToDefaultGroups($user, $detaching = false)
|
||||
{
|
||||
$user->groups()->sync(self::where('is_new_user_default', true)->lists('id'), $detaching);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
# ===================================
|
||||
# Field Definitions
|
||||
# ===================================
|
||||
|
||||
fields:
|
||||
name:
|
||||
label: backend::lang.user.group.name_field
|
||||
|
||||
tabs:
|
||||
stretch: true
|
||||
|
|
@ -52,7 +52,7 @@ tabs:
|
|||
span: right
|
||||
label: backend::lang.user.groups
|
||||
commentAbove: backend::lang.user.groups_comment
|
||||
type: relation
|
||||
type: checkboxlist
|
||||
|
||||
secondaryTabs:
|
||||
fields:
|
||||
|
|
|
|||
|
|
@ -6,3 +6,7 @@ columns:
|
|||
name:
|
||||
label: backend::lang.user.group.name_field
|
||||
searchable: yes
|
||||
|
||||
description:
|
||||
label: backend::lang.user.group.description_field
|
||||
searchable: yes
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
# ===================================
|
||||
# Field Definitions
|
||||
# ===================================
|
||||
|
||||
fields:
|
||||
|
||||
name:
|
||||
label: backend::lang.user.group.name_field
|
||||
|
||||
description:
|
||||
label: backend::lang.user.group.description_field
|
||||
type: textarea
|
||||
size: tiny
|
||||
|
||||
is_new_user_default:
|
||||
label: backend::lang.user.group.is_new_user_default_field
|
||||
type: checkbox
|
||||
|
||||
tabs:
|
||||
stretch: true
|
||||
|
|
@ -5,7 +5,6 @@ use Illuminate\Database\Migrations\Migration;
|
|||
|
||||
class DbSystemAddDisabledFlag extends Migration
|
||||
{
|
||||
|
||||
public function up()
|
||||
{
|
||||
Schema::table('system_plugin_versions', function (Blueprint $table) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue