new: [Roles, Users] added

remotes/origin/main
iglocska 2020-06-19 00:42:10 +02:00
parent 21ad2e8b5e
commit 5d36c7d730
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
12 changed files with 506 additions and 0 deletions

View File

@ -0,0 +1,58 @@
<?php
namespace App\Controller;
use App\Controller\AppController;
use Cake\Utility\Hash;
use Cake\Utility\Text;
use \Cake\Database\Expression\QueryExpression;
class RolesController extends AppController
{
public function index()
{
$this->CRUD->index([
'filters' => ['name', 'uuid', 'perm_admin'],
'quickFilters' => ['name'],
'contain' => $this->checkPermission('admin') ? ['Users'] : []
]);
$this->set('metaGroup', $this->isAdmin ? 'Administration' : 'Cerebrate');
}
public function add()
{
$this->CRUD->add();
if ($this->ParamHandler->isRest()) {
return $this->restResponsePayload;
}
$this->set('metaGroup', $this->isAdmin ? 'Administration' : 'Cerebrate');
}
public function view($id)
{
$this->CRUD->view($id);
if ($this->ParamHandler->isRest()) {
return $this->restResponsePayload;
}
$this->set('metaGroup', $this->isAdmin ? 'Administration' : 'Cerebrate');
}
public function edit($id)
{
$this->CRUD->edit($id);
if ($this->ParamHandler->isRest()) {
return $this->restResponsePayload;
}
$this->set('metaGroup', $this->isAdmin ? 'Administration' : 'Cerebrate');
$this->render('add');
}
public function delete($id)
{
$this->CRUD->delete($id);
if ($this->ParamHandler->isRest()) {
return $this->restResponsePayload;
}
$this->set('metaGroup', $this->isAdmin ? 'Administration' : 'Cerebrate');
}
}

View File

@ -0,0 +1,79 @@
<?php
namespace App\Controller;
use App\Controller\AppController;
use Cake\Utility\Hash;
use Cake\Utility\Text;
use \Cake\Database\Expression\QueryExpression;
class UsersController extends AppController
{
public function index()
{
$this->CRUD->index([
'contain' => ['Individuals', 'Roles'],
'filters' => ['Users.email', 'uuid']
]);
if ($this->ParamHandler->isRest()) {
return $this->restResponsePayload;
}
$this->set('metaGroup', $this->isAdmin ? 'Administration' : 'Cerebrate');
}
public function add()
{
$this->CRUD->add();
if ($this->ParamHandler->isRest()) {
return $this->restResponsePayload;
}
$dropdownData = [
'role' => $this->Users->Roles->find('list', [
'sort' => ['name' => 'asc']
]),
'individual' => $this->Users->Individuals->find('list', [
'sort' => ['email' => 'asc']
])
];
$this->set(compact('dropdownData'));
$this->set('metaGroup', $this->isAdmin ? 'Administration' : 'Cerebrate');
}
public function view($id)
{
$this->CRUD->view($id, [
'contain' => ['Individuals' => ['Alignments' => 'Organisations'], 'Roles']
]);
if ($this->ParamHandler->isRest()) {
return $this->restResponsePayload;
}
$this->set('metaGroup', $this->isAdmin ? 'Administration' : 'Cerebrate');
}
public function edit($id)
{
$this->CRUD->edit($id);
if ($this->ParamHandler->isRest()) {
return $this->restResponsePayload;
}
$dropdownData = [
'role' => $this->Users->Roles->find('list', [
'sort' => ['name' => 'asc']
]),
'individual' => $this->Users->Individuals->find('list', [
'sort' => ['email' => 'asc']
])
];
$this->set(compact('dropdownData'));
$this->set('metaGroup', $this->isAdmin ? 'Administration' : 'Cerebrate');
$this->render('add');
}
public function delete($id)
{
$this->CRUD->delete($id);
if ($this->ParamHandler->isRest()) {
return $this->restResponsePayload;
}
$this->set('metaGroup', $this->isAdmin ? 'Administration' : 'Cerebrate');
}
}

View File

@ -0,0 +1,11 @@
<?php
namespace App\Model\Entity;
use App\Model\Entity\AppModel;
use Cake\ORM\Entity;
class Role extends AppModel
{
}

View File

@ -0,0 +1,11 @@
<?php
namespace App\Model\Entity;
use App\Model\Entity\AppModel;
use Cake\ORM\Entity;
class User extends AppModel
{
}

View File

@ -0,0 +1,32 @@
<?php
namespace App\Model\Table;
use App\Model\Table\AppTable;
use Cake\ORM\Table;
use Cake\Validation\Validator;
class RolesTable extends AppTable
{
public function initialize(array $config): void
{
parent::initialize($config);
$this->addBehavior('UUID');
$this->hasMany(
'Users',
[
'dependent' => false,
'cascadeCallbacks' => false
]
);
$this->setDisplayField('name');
}
public function validationDefault(Validator $validator): Validator
{
$validator
->notEmptyString('name')
->requirePresence(['name'], 'create');
return $validator;
}
}

View File

@ -0,0 +1,38 @@
<?php
namespace App\Model\Table;
use App\Model\Table\AppTable;
use Cake\ORM\Table;
use Cake\Validation\Validator;
class UsersTable extends AppTable
{
public function initialize(array $config): void
{
parent::initialize($config);
$this->addBehavior('UUID');
$this->belongsTo(
'Individuals',
[
'dependent' => false,
'cascadeCallbacks' => false
]
);
$this->belongsTo(
'Roles',
[
'dependent' => false,
'cascadeCallbacks' => false
]
);
$this->setDisplayField('id');
}
public function validationDefault(Validator $validator): Validator
{
$validator
->requirePresence(['password'], 'create');
return $validator;
}
}

View File

@ -0,0 +1,27 @@
<?php
echo $this->element('genericElements/Form/genericForm', [
'data' => [
'description' => __('Roles define global rules for a set of users, including first and foremost access controls to certain functionalities.'),
'model' => 'Roles',
'fields' => [
[
'field' => 'name'
],
[
'field' => 'perm_admin',
'type' => 'checkbox',
'label' => 'Full admin privilege'
],
[
'field' => 'is_default',
'type' => 'checkbox',
'label' => 'Default role'
]
],
'submit' => [
'action' => $this->request->getParam('action')
]
]
]);
?>
</div>

View File

@ -0,0 +1,70 @@
<?php
echo $this->element('genericElements/IndexTable/index_table', [
'data' => [
'data' => $data,
'top_bar' => [
'pull' => 'right',
'children' => [
[
'type' => 'search',
'button' => __('Filter'),
'placeholder' => __('Enter value to search'),
'data' => '',
'searchKey' => 'value'
]
]
],
'fields' => [
[
'name' => '#',
'sort' => 'id',
'data_path' => 'id',
],
[
'name' => __('Name'),
'sort' => 'name',
'data_path' => 'name',
],
[
'name' => __('UUID'),
'sort' => 'uuid',
'data_path' => 'uuid',
'placeholder' => __('Leave empty to auto generate')
],
[
'name' => __('Admin'),
'sort' => 'perm_admin',
'data_path' => 'perm_admin',
'element' => 'boolean'
],
[
'name' => 'Default',
'sort' => 'is_default',
'data_path' => 'is_default',
'element' => 'boolean'
],
],
'title' => __('Roles Index'),
'description' => __('A list of configurable user roles. Create or modify user access roles based on the settings below.'),
'pull' => 'right',
'actions' => [
[
'url' => '/roles/view',
'url_params_data_paths' => ['id'],
'icon' => 'eye'
],
[
'url' => '/roles/edit',
'url_params_data_paths' => ['id'],
'icon' => 'edit'
],
[
'onclick' => 'populateAndLoadModal(\'/roles/delete/[onclick_params_data_path]\');',
'onclick_params_data_path' => 'id',
'icon' => 'trash'
]
]
]
]);
echo '</div>';
?>

View File

@ -0,0 +1,28 @@
<?php
echo $this->element(
'/genericElements/SingleViews/single_view',
[
'data' => $entity,
'fields' => [
[
'key' => __('ID'),
'path' => 'id'
],
[
'key' => __('Name'),
'path' => 'name'
],
[
'key' => __('Admin permission'),
'path' => 'perm_admin',
'type' => 'boolean'
],
[
'key' => __('Default role'),
'path' => 'is_default',
'type' => 'boolean'
]
],
'children' => []
]
);

View File

@ -0,0 +1,39 @@
<?php
echo $this->element('genericElements/Form/genericForm', [
'data' => [
'description' => __('Roles define global rules for a set of users, including first and foremost access controls to certain functionalities.'),
'model' => 'Roles',
'fields' => [
[
'field' => 'individual_id',
'type' => 'dropdown',
'label' => __('Associated individual'),
'options' => $dropdownData['individual']
],
[
'field' => 'role_id',
'type' => 'dropdown',
'label' => __('Role'),
'options' => $dropdownData['role']
],
[
'field' => 'password',
'label' => __('Password')
],
[
'field' => 'confirm_password',
'label' => __('Confirm Password')
],
[
'field' => 'disabled',
'type' => 'checkbox',
'label' => 'Disable'
]
],
'submit' => [
'action' => $this->request->getParam('action')
]
]
]);
?>
</div>

View File

@ -0,0 +1,71 @@
<?php
echo $this->element('genericElements/IndexTable/index_table', [
'data' => [
'data' => $data,
'top_bar' => [
'pull' => 'right',
'children' => [
[
'type' => 'search',
'button' => __('Filter'),
'placeholder' => __('Enter value to search'),
'data' => '',
'searchKey' => 'value'
]
]
],
'fields' => [
[
'name' => '#',
'sort' => 'id',
'data_path' => 'id',
],
[
'name' => __('Email'),
'sort' => 'individual.email',
'data_path' => 'individual.email',
'url' => '/individuals/view/{{0}}',
'url_vars' => ['individual.id']
],
[
'name' => __('First Name'),
'sort' => 'individual.first_name',
'data_path' => 'individual.first_name',
],
[
'name' => __('Last Name'),
'sort' => 'individual.last_name',
'data_path' => 'individual.last_name'
],
[
'name' => __('Role'),
'sort' => 'role.name',
'data_path' => 'role.name',
'url' => '/roles/view/{{0}}',
'url_vars' => ['role.id']
],
],
'title' => __('User index'),
'description' => __('The list of enrolled users in this Cerebrate instance. All of the users have or at one point had access to the system.'),
'pull' => 'right',
'actions' => [
[
'url' => '/users/view',
'url_params_data_paths' => ['id'],
'icon' => 'eye'
],
[
'url' => '/users/edit',
'url_params_data_paths' => ['id'],
'icon' => 'edit'
],
[
'onclick' => 'populateAndLoadModal(\'/users/delete/[onclick_params_data_path]\');',
'onclick_params_data_path' => 'id',
'icon' => 'trash'
]
]
]
]);
echo '</div>';
?>

View File

@ -0,0 +1,42 @@
<?php
echo $this->element(
'/genericElements/SingleViews/single_view',
[
'data' => $entity,
'fields' => [
[
'key' => __('ID'),
'path' => 'id'
],
[
'key' => __('UUID'),
'path' => 'uuid'
],
[
'key' => __('Email'),
'path' => 'individual.email'
],
[
'key' => __('Role'),
'path' => 'role.name',
'url' => '/roles/view/{{0}}',
'url_vars' => 'role.id'
],
[
'key' => __('First name'),
'path' => 'individual.first_name'
],
[
'key' => __('Last name'),
'path' => 'individual.last_name'
],
[
'key' => __('Alignments'),
'type' => 'alignment',
'path' => 'individual',
'scope' => 'individuals'
]
],
'children' => []
]
);