diff --git a/libraries/default/InboxProcessors/UserInboxProcessor.php b/libraries/default/InboxProcessors/UserInboxProcessor.php
index 96656c1..dd167df 100644
--- a/libraries/default/InboxProcessors/UserInboxProcessor.php
+++ b/libraries/default/InboxProcessors/UserInboxProcessor.php
@@ -73,8 +73,28 @@ class RegistrationProcessor extends UserInboxProcessor implements GenericInboxPr
]),
'individual' => [-1 => __('-- New individual --')] + $this->Users->Individuals->find('list', [
'sort' => ['email' => 'asc']
- ])->toArray()
+ ])->toArray(),
+ 'organisation' => $this->Users->Organisations->find('list', [
+ 'sort' => ['email' => 'asc']
+ ])->toArray(),
];
+
+ $defaultRole = $this->Users->Roles->find()->select(['id'])->where(['is_default' => true])->first()->toArray();
+
+ $conditions = [];
+ if (!empty($request['data']['org_uuid'])) {
+ $conditions['uuid'] = $request['data']['org_uuid'];
+ } else if (!empty($request['data']['org_name'])) {
+ $conditions['name'] = $request['data']['org_name'];
+ }
+ $desiredOrg = null;
+ if (!empty($conditions)) {
+ $desiredOrg = $this->Users->Organisations->find()
+ ->where($conditions)
+ ->first()
+ ->toArray();
+ }
+
$individualEntity = $this->Users->Individuals->newEntity([
'email' => !empty($request['data']['email']) ? $request['data']['email'] : '',
'first_name' => !empty($request['data']['first_name']) ? $request['data']['first_name'] : '',
@@ -86,6 +106,7 @@ class RegistrationProcessor extends UserInboxProcessor implements GenericInboxPr
'username' => !empty($request['data']['username']) ? $request['data']['username'] : '',
'role_id' => !empty($request['data']['role_id']) ? $request['data']['role_id'] : '',
'disabled' => !empty($request['data']['disabled']) ? $request['data']['disabled'] : '',
+ 'org_id' => !empty($desiredOrg) ? $desiredOrg['id'] : '',
'email' => !empty($request['data']['email']) ? $request['data']['email'] : '',
'first_name' => !empty($request['data']['first_name']) ? $request['data']['first_name'] : '',
@@ -95,7 +116,12 @@ class RegistrationProcessor extends UserInboxProcessor implements GenericInboxPr
return [
'dropdownData' => $dropdownData,
'userEntity' => $userEntity,
- 'individualEntity' => $individualEntity
+ 'individualEntity' => $individualEntity,
+ 'desiredOrganisation' => [
+ 'org_name' => $request['data']['org_name'],
+ 'org_uuid' => $request['data']['org_uuid'],
+ ],
+ 'defaultRole' => $defaultRole,
];
}
@@ -120,6 +146,7 @@ class RegistrationProcessor extends UserInboxProcessor implements GenericInboxPr
'password' => '~PASSWORD_TO_BE_REPLACED~',
'role_id' => $requestData['role_id'],
'disabled' => $requestData['disabled'],
+ 'organisation_id' => $requestData['org_id'],
]);
$user->set('password', $hashedPassword, ['setter' => false]); // ignore default password hashing as it has already been hashed
$user = $this->Users->save($user);
diff --git a/libraries/default/InboxProcessors/templates/User/Registration.php b/libraries/default/InboxProcessors/templates/User/Registration.php
index 5480862..d24ea5b 100644
--- a/libraries/default/InboxProcessors/templates/User/Registration.php
+++ b/libraries/default/InboxProcessors/templates/User/Registration.php
@@ -1,10 +1,23 @@
Bootstrap->alert([
+ 'variant' => 'info',
+ 'html' => sprintf('
+
',
+ __('Requested Organisation name'), $desiredOrganisation['org_name'],
+ __('Requested Organisation UUID'), $desiredOrganisation['org_uuid']
+ ),
+ 'dismissible' => false,
+]);
+
$combinedForm = $this->element('genericElements/Form/genericForm', [
'entity' => $userEntity,
'ajax' => false,
'raw' => true,
'data' => [
- 'description' => __('Create user account'),
+ 'descriptionHtml' => __('Create user account') . sprintf('%s
', $infoAlert),
'model' => 'User',
'fields' => [
[
@@ -17,19 +30,26 @@ $combinedForm = $this->element('genericElements/Form/genericForm', [
'field' => 'username',
'autocomplete' => 'off',
],
+ [
+ 'field' => 'org_id',
+ 'type' => 'dropdown',
+ 'label' => __('Associated organisation'),
+ 'options' => $dropdownData['organisation'],
+ ],
[
'field' => 'role_id',
'type' => 'dropdown',
'label' => __('Role'),
- 'options' => $dropdownData['role']
+ 'options' => $dropdownData['role'],
+ 'default' => $defaultRole,
],
[
'field' => 'disabled',
'type' => 'checkbox',
'label' => 'Disable'
],
-
- sprintf('%s
', __('Create individual')),
+ '',
+ sprintf('
%s
', __('Create a new individual')),
[
'field' => 'email',
'autocomplete' => 'off'
@@ -52,6 +72,7 @@ $combinedForm = $this->element('genericElements/Form/genericForm', [
'field' => 'position',
'autocomplete' => 'off'
],
+ '
',
],
'submit' => [
'action' => $this->request->getParam('action')
@@ -86,15 +107,19 @@ echo $this->Bootstrap->modal([
}
$(document).ready(function() {
- $('div.user-container #individual_id-field').change(function() {
- if ($(this).val() == -1) {
- $('div.individual-container').show()
- } else {
- $('div.individual-container').hide()
- }
+ $('form #individual_id-field').change(function() {
+ toggleIndividualContainer($(this).val() == -1)
})
})
+ function toggleIndividualContainer(show) {
+ if (show) {
+ $('div.individual-container').show()
+ } else {
+ $('div.individual-container').hide()
+ }
+ }
+
function getFormData(form) {
return Object.values(form).reduce((obj, field) => {
if (field.type === 'checkbox') {
@@ -105,11 +130,4 @@ echo $this->Bootstrap->modal([
return obj
}, {})
}
-
-
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/src/Controller/UsersController.php b/src/Controller/UsersController.php
index 771672d..f2636e6 100644
--- a/src/Controller/UsersController.php
+++ b/src/Controller/UsersController.php
@@ -68,7 +68,7 @@ class UsersController extends AppController
} else {
$validRoles = $this->Users->Roles->find('list')->order(['name' => 'asc'])->all()->toArray();
}
- $defaultRole = $this->Users->Roles->find()->select(['id'])->first()->toArray();
+ $defaultRole = $this->Users->Roles->find()->select(['id'])->where(['is_default' => true])->first()->toArray();
$individuals = $this->Users->Individuals->find('list', $individuals_params)->toArray();
$this->CRUD->add([
'beforeMarshal' => function($data) {
@@ -442,6 +442,8 @@ class UsersController extends AppController
'first_name' => $data['first_name'],
'last_name' => $data['last_name'],
'password' => $data['password'],
+ 'org_name' => $data['org_name'],
+ 'org_uuid' => $data['org_uuid'],
],
];
$processorResult = $processor->create($data);
diff --git a/templates/Users/register.php b/templates/Users/register.php
index dd1cba4..0ecb39e 100644
--- a/templates/Users/register.php
+++ b/templates/Users/register.php
@@ -34,6 +34,20 @@ use Cake\Core\Configure;
echo '';
echo '';
+ echo '';
+ echo $this->Form->control('org_name', ['label' => __('Organisation Name'), 'class' => 'form-control']);
+ echo $this->Form->control('org_uuid', [
+ 'label' => __('UUID'),
+ 'class' => 'form-control form-control-sm mb-2',
+ 'style' => 'font-size: 0.815rem;',
+ 'div' => ['class' => 'test'],
+ 'templates' => [
+ 'inputContainer' => '
{{content}}
',
+ 'label' => '
',
+ ],
+ ]);
+ echo '
';
+
echo $this->Form->control('password', ['type' => 'password', 'label' => __('Password'), 'class' => 'form-control mb-4']);
echo $this->Form->control(__('Sign up'), ['type' => 'submit', 'class' => 'btn btn-primary']);
@@ -42,4 +56,16 @@ use Cake\Core\Configure;
echo '';
echo $this->Form->end();
?>
-
\ No newline at end of file
+
+
+
\ No newline at end of file
diff --git a/templates/element/genericElements/Form/formLayouts/formDefault.php b/templates/element/genericElements/Form/formLayouts/formDefault.php
index 56a439a..1658889 100644
--- a/templates/element/genericElements/Form/formLayouts/formDefault.php
+++ b/templates/element/genericElements/Form/formLayouts/formDefault.php
@@ -4,12 +4,12 @@
= $formCreate ?>
= $ajaxFlashMessage ?>
-
+
- = h($data['description']) ?>
+ = !empty($data['descriptionHtml']) ? $data['descriptionHtml'] : h($data['description']) ?>
-
+
= $fieldsString ?>
diff --git a/templates/element/genericElements/Form/formLayouts/formRaw.php b/templates/element/genericElements/Form/formLayouts/formRaw.php
index 1e445f7..8b66bae 100644
--- a/templates/element/genericElements/Form/formLayouts/formRaw.php
+++ b/templates/element/genericElements/Form/formLayouts/formRaw.php
@@ -1,6 +1,6 @@
-
+
- = h($data['description']) ?>
+ = !empty($data['descriptionHtml']) ? $data['descriptionHtml'] : h($data['description']) ?>
= $ajaxFlashMessage ?>