Merge branch 'main' into develop

refacto/CRUDComponent
iglocska 2023-09-04 15:22:42 +02:00
commit 78152a884a
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
3 changed files with 28 additions and 11 deletions

View File

@ -32,13 +32,13 @@ sudo add-apt-repository ppa:ondrej/php
- for apache - for apache
```bash ```bash
sudo apt install apache2 mariadb-server git php8.2-intl php8.2-mbstring php8.2-dom php8.2-xml unzip php8.2-ldap php8.2-sqlite3 ph8.2p-curl sqlite libapache2-mod-php php8.2-mysql sudo apt install apache2 mariadb-server git php8.2 php8.2-intl php8.2-mbstring php8.2-dom php8.2-xml unzip php8.2-ldap php8.2-sqlite3 php8.2-curl sqlite libapache2-mod-php php8.2-mysql
``` ```
- for nginx - for nginx
```bash ```bash
sudo apt install nginx mariadb-server git php8.2-intl php8.2-mbstring php8.2-dom php8.2-xml unzip php8.2-ldap php8.2-sqlite3 ph8.2p-curl sqlite php8.2-mysql sudo apt install nginx mariadb-server git php8.2 php8.2-intl php8.2-mbstring php8.2-dom php8.2-xml unzip php8.2-ldap php8.2-sqlite3 php8.2-curl sqlite php8.2-mysql
``` ```
@ -48,7 +48,6 @@ Install composer:
~~~bash ~~~bash
cd cd
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php php composer-setup.php
php -r "unlink('composer-setup.php');" php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer sudo mv composer.phar /usr/local/bin/composer

View File

@ -100,21 +100,34 @@ class UserSettingsController extends AppController
'id' => $id 'id' => $id
])->first(); ])->first();
if (!$this->isLoggedUserAllowedToEdit($entity)) { $currentUser = $this->ACL->getUser();
throw new NotFoundException(__('Invalid {0}.', 'user setting')); $validUsers = [];
$individual_ids = [];
if (!$currentUser['role']['perm_admin']) {
if ($currentUser['role']['perm_org_admin']) {
$validUsers = $this->Users->find('list')->select(['id', 'username'])->order(['username' => 'asc'])->where(['organisation_id' => $currentUser['organisation']['id']])->all()->toArray();
} else {
$validUsers = [$currentUser['id'] => $currentUser['username']];
}
} else {
$validUsers = $this->Users->find('list')->select(['id', 'username'])->order(['username' => 'asc'])->all()->toArray();
} }
$entity = $this->CRUD->edit($id, [ $entity = $this->CRUD->edit($id, [
'redirect' => ['action' => 'index', $entity->user_id] 'redirect' => ['action' => 'index', $entity->user_id],
'beforeSave' => function ($data) use ($validUsers) {
if (!in_array($data['user_id'], array_keys($validUsers))) {
throw new MethodNotAllowedException(__('You cannot edit the given user.'));
}
return $data;
}
]); ]);
$responsePayload = $this->CRUD->getResponsePayload(); $responsePayload = $this->CRUD->getResponsePayload();
if (!empty($responsePayload)) { if (!empty($responsePayload)) {
return $responsePayload; return $responsePayload;
} }
$dropdownData = [ $dropdownData = [
'user' => $this->UserSettings->Users->find('list', [ 'user' => $validUsers,
'sort' => ['username' => 'asc']
])->toArray(),
]; ];
$this->set(compact('dropdownData')); $this->set(compact('dropdownData'));
$this->set('user_id', $this->entity->user_id); $this->set('user_id', $this->entity->user_id);
@ -259,8 +272,9 @@ class UserSettingsController extends AppController
if (empty($setting)) { if (empty($setting)) {
return false; return false;
} }
} else {
$isAllowed = $setting->user_id == $currentUser->id;
} }
$isAllowed = $setting->user_id == $currentUser->id;
} }
return $isAllowed; return $isAllowed;
} }

View File

@ -74,7 +74,11 @@ class UsersController extends AppController
} else { } else {
$validRoles = $this->Users->Roles->find('list')->order(['name' => 'asc'])->all()->toArray(); $validRoles = $this->Users->Roles->find('list')->order(['name' => 'asc'])->all()->toArray();
} }
$defaultRole = $this->Users->Roles->find()->select(['id'])->where(['is_default' => true])->first()->toArray(); $defaultRole = $this->Users->Roles->find()->select(['id'])->where(['is_default' => true])->first();
if (empty($defaultRole)) {
$defaultRole = $this->Users->Roles->find()->select(['id'])->first();
}
$defaultRole = $defaultRole->toArray();
$individuals = $this->Users->Individuals->find('list', $individuals_params)->toArray(); $individuals = $this->Users->Individuals->find('list', $individuals_params)->toArray();
$this->CRUD->add([ $this->CRUD->add([
'beforeMarshal' => function($data) { 'beforeMarshal' => function($data) {