Skip to content

Commit

Permalink
1.1.1: Users can now be added to groups.
Browse files Browse the repository at this point in the history
  • Loading branch information
daftspunk committed Aug 15, 2015
1 parent 378e8dc commit 764cce6
Show file tree
Hide file tree
Showing 20 changed files with 449 additions and 16 deletions.
9 changes: 8 additions & 1 deletion Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public function registerComponents()
public function registerPermissions()
{
return [
'rainlab.users.access_users' => ['tab' => 'rainlab.user::lang.plugin.tab', 'label' => 'rainlab.user::lang.plugin.access_users']
'rainlab.users.access_users' => ['tab' => 'rainlab.user::lang.plugin.tab', 'label' => 'rainlab.user::lang.plugin.access_users'],
'rainlab.users.access_groups' => ['tab' => 'rainlab.user::lang.plugin.tab', 'label' => 'rainlab.user::lang.plugin.access_groups']
];
}

Expand All @@ -74,6 +75,12 @@ public function registerNavigation()
'icon' => 'icon-user',
'url' => Backend::url('rainlab/user/users'),
'permissions' => ['rainlab.users.access_users']
],
'usergroups' => [
'label' => 'rainlab.user::lang.groups.all_groups',
'icon' => 'icon-users',
'url' => Backend::url('rainlab/user/usergroups'),
'permissions' => ['rainlab.groups.access_groups']
]
]
]
Expand Down
7 changes: 0 additions & 7 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,3 @@ In short, to retain the old functionaliy simply install the following plugins:

- RainLab.Location
- RainLab.UserPlus

# Notes

1.1.0:
- !!! Profile fields and Locations have been removed.
1.1.1:
- Introduce User Groups.
29 changes: 29 additions & 0 deletions controllers/UserGroups.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php namespace RainLab\User\Controllers;

use Flash;
use BackendMenu;
use Backend\Classes\Controller;
use RainLab\User\Models\UserGroup;

/**
* User Groups Back-end Controller
*/
class UserGroups extends Controller
{
public $implement = [
'Backend.Behaviors.FormController',
'Backend.Behaviors.ListController'
];

public $formConfig = 'config_form.yaml';
public $listConfig = 'config_list.yaml';

public $requiredPermissions = ['rainlab.users.access_groups'];

public function __construct()
{
parent::__construct();

BackendMenu::setContext('RainLab.User', 'user', 'usergroups');
}
}
22 changes: 17 additions & 5 deletions controllers/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Backend\Classes\Controller;
use System\Classes\SettingsManager;
use RainLab\User\Models\User;
use RainLab\User\Models\UserGroup;
use RainLab\User\Models\Settings as UserSettings;

class Users extends Controller
Expand Down Expand Up @@ -52,13 +53,24 @@ public function update_onActivate($recordId = null)
*/
protected function formExtendFields($form)
{
$loginAttribute = UserSettings::get('login_attribute', UserSettings::LOGIN_EMAIL);
if ($loginAttribute != UserSettings::LOGIN_USERNAME) {
return;
/*
* Show the username field if it is configured for use
*/
if (
UserSettings::get('login_attribute') == UserSettings::LOGIN_USERNAME &&
array_key_exists('username', $form->getFields())
) {
$form->getField('username')->hidden = false;
}

if (array_key_exists('username', $form->getFields())) {
$form->getField('username')->hidden = false;
/*
* Mark default groups
*/
if (!$form->model->exists) {
$defaultGroupIds = UserGroup::where('is_new_user_default', true)->lists('id');

$groupField = $form->getField('groups');
$groupField->value = $defaultGroupIds;
}
}

Expand Down
7 changes: 7 additions & 0 deletions controllers/usergroups/_list_toolbar.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div data-control="toolbar">
<a
href="<?= Backend::url('rainlab/user/usergroups/create') ?>"
class="btn btn-primary oc-icon-plus">
New User Group
</a>
</div>
31 changes: 31 additions & 0 deletions controllers/usergroups/config_form.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# ===================================
# Form Behavior Config
# ===================================

# Record name
name: User Group

# Model Form Field configuration
form: $/rainlab/user/models/usergroup/fields.yaml

# Model Class name
modelClass: RainLab\User\Models\UserGroup

# Default redirect location
defaultRedirect: rainlab/user/usergroups

# Create page
create:
title: Create User Group
redirect: rainlab/user/usergroups/update/:id
redirectClose: rainlab/user/usergroups

# Update page
update:
title: Edit User Group
redirect: rainlab/user/usergroups
redirectClose: rainlab/user/usergroups

# Preview page
preview:
title: Preview User Group
44 changes: 44 additions & 0 deletions controllers/usergroups/config_list.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# ===================================
# List Behavior Config
# ===================================

# Model List Column configuration
list: $/rainlab/user/models/usergroup/columns.yaml

# Model Class name
modelClass: RainLab\User\Models\UserGroup

# List Title
title: Manage User Groups

# Link URL for each record
recordUrl: rainlab/user/usergroups/update/:id

# Message to display if the list is empty
noRecordsMessage: backend::lang.list.no_records

# Records to display per page
recordsPerPage: 20

# Displays the list column set up button
showSetup: true

# Displays the sorting link on each column
showSorting: true

# Default sorting column
# defaultSort:
# column: created_at
# direction: desc

# Display checkboxes next to each record
# showCheckboxes: true

# Toolbar widget configuration
toolbar:
# Partial for toolbar buttons
buttons: list_toolbar

# Search widget configuration
search:
prompt: backend::lang.list.search_prompt
48 changes: 48 additions & 0 deletions controllers/usergroups/create.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php Block::put('breadcrumb') ?>
<ul>
<li><a href="<?= Backend::url('rainlab/user/usergroups') ?>">User Groups</a></li>
<li><?= e($this->pageTitle) ?></li>
</ul>
<?php Block::endPut() ?>

<?php if (!$this->fatalError): ?>

<?= Form::open(['class' => 'layout']) ?>

<div class="layout-row">
<?= $this->formRender() ?>
</div>

<div class="form-buttons">
<div class="loading-indicator-container">
<button
type="submit"
data-request="onSave"
data-hotkey="ctrl+s, cmd+s"
data-load-indicator="Creating UserGroup..."
class="btn btn-primary">
Create
</button>
<button
type="button"
data-request="onSave"
data-request-data="close:1"
data-hotkey="ctrl+enter, cmd+enter"
data-load-indicator="Creating UserGroup..."
class="btn btn-default">
Create and Close
</button>
<span class="btn-text">
or <a href="<?= Backend::url('rainlab/user/usergroups') ?>">Cancel</a>
</span>
</div>
</div>

<?= Form::close() ?>

<?php else: ?>

<p class="flash-message static error"><?= e($this->fatalError) ?></p>
<p><a href="<?= Backend::url('rainlab/user/usergroups') ?>" class="btn btn-default">Return to user groups list</a></p>

<?php endif ?>
2 changes: 2 additions & 0 deletions controllers/usergroups/index.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

<?= $this->listRender() ?>
19 changes: 19 additions & 0 deletions controllers/usergroups/preview.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php Block::put('breadcrumb') ?>
<ul>
<li><a href="<?= Backend::url('rainlab/user/usergroups') ?>">User Groups</a></li>
<li><?= e($this->pageTitle) ?></li>
</ul>
<?php Block::endPut() ?>

<?php if (!$this->fatalError): ?>

<div class="form-preview">
<?= $this->formRenderPreview() ?>
</div>

<?php else: ?>

<p class="flash-message static error"><?= e($this->fatalError) ?></p>
<p><a href="<?= Backend::url('rainlab/user/usergroups') ?>" class="btn btn-default">Return to user groups list</a></p>

<?php endif ?>
56 changes: 56 additions & 0 deletions controllers/usergroups/update.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php Block::put('breadcrumb') ?>
<ul>
<li><a href="<?= Backend::url('rainlab/user/usergroups') ?>">User Groups</a></li>
<li><?= e($this->pageTitle) ?></li>
</ul>
<?php Block::endPut() ?>

<?php if (!$this->fatalError): ?>

<?= Form::open(['class' => 'layout']) ?>

<div class="layout-row">
<?= $this->formRender() ?>
</div>

<div class="form-buttons">
<div class="loading-indicator-container">
<button
type="submit"
data-request="onSave"
data-request-data="redirect:0"
data-hotkey="ctrl+s, cmd+s"
data-load-indicator="Saving UserGroup..."
class="btn btn-primary">
<u>S</u>ave
</button>
<button
type="button"
data-request="onSave"
data-request-data="close:1"
data-hotkey="ctrl+enter, cmd+enter"
data-load-indicator="Saving UserGroup..."
class="btn btn-default">
Save and Close
</button>
<button
type="button"
class="oc-icon-trash-o btn-icon danger pull-right"
data-request="onDelete"
data-load-indicator="Deleting UserGroup..."
data-request-confirm="Do you really want to delete this usergroup?">
</button>
<span class="btn-text">
or <a href="<?= Backend::url('rainlab/user/usergroups') ?>">Cancel</a>
</span>
</div>
</div>

<?= Form::close() ?>

<?php else: ?>

<p class="flash-message static error"><?= e($this->fatalError) ?></p>
<p><a href="<?= Backend::url('rainlab/user/usergroups') ?>" class="btn btn-default">Return to user groups list</a></p>

<?php endif ?>
25 changes: 24 additions & 1 deletion lang/en/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
'name' => 'User',
'description' => 'Front-end user management.',
'tab' => 'Users',
'access_users' => 'Manage Users'
'access_users' => 'Manage Users',
'access_groups' => 'Manage User Groups'
],
'users' => [
'menu_label' => 'Users',
Expand Down Expand Up @@ -65,6 +66,28 @@
'details' => 'Details',
'account' => 'Account'
],
'group' => [
'label' => 'Group',
'id' => 'ID',
'name' => 'Name',
'description_field' => 'Description',
'code' => 'Code',
'code_comment' => 'Enter a unique code if you want to access it with the API.',
'created_at' => 'Created',
'is_new_user_default_field' => 'Add new administrators to this group by default.',
'users_count' => 'Users'
],
'groups' => [
'menu_label' => 'Groups',
'all_groups' => 'User Groups',
'new_group' => 'New Group',
'delete_selected_confirm' => 'Do you really want to delete selected groups?',
'list_title' => 'Manage Groups',
'delete_confirm' => 'Do you really want to delete this group?',
'delete_selected_success' => 'Successfully deleted the selected groups.',
'delete_selected_empty' => 'There are no selected groups to delete.',
'return_to_list' => 'Back to groups list',
],
'login' => [
'attribute_email' => 'Email',
'attribute_username' => 'Username'
Expand Down
2 changes: 1 addition & 1 deletion models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class User extends UserBase
* @var array Relations
*/
public $belongsToMany = [
// 'groups' => ['RainLab\User\Models\Group', 'table' => 'users_groups']
'groups' => ['RainLab\User\Models\UserGroup', 'table' => 'users_groups']
];

public $attachOne = [
Expand Down
Loading

0 comments on commit 764cce6

Please sign in to comment.