fix: [Component:CRUD] Removed confusing `get` parameter

- It was confusing and using it could lead to unwanted consequences
- It's clearer to implement the desired logic on controller's side
pull/93/head
Sami Mokaddem 2022-03-01 14:02:26 +01:00
parent 3d0fdeba81
commit 0fb03aae91
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
2 changed files with 5 additions and 11 deletions

View File

@ -473,7 +473,6 @@ class CRUDComponent extends Component
$params['contain'][] = 'Tags'; $params['contain'][] = 'Tags';
$this->setAllTags(); $this->setAllTags();
} }
$params = isset($params['get']) ? $params['get'] : $params;
if ($this->metaFieldsSupported()) { if ($this->metaFieldsSupported()) {
if (empty($params['contain'])) { if (empty($params['contain'])) {
$params['contain'] = []; $params['contain'] = [];
@ -485,9 +484,6 @@ class CRUDComponent extends Component
} }
} }
$query = $this->Table->find()->where(['id' => $id]); $query = $this->Table->find()->where(['id' => $id]);
if (!empty($params['get'])) {
$query->select($params['get']);
}
if (!empty($params['contain'])) { if (!empty($params['contain'])) {
$query->contain($params['contain']); $query->contain($params['contain']);
} }

View File

@ -160,11 +160,6 @@ class UsersController extends AppController
} }
$params = [ $params = [
'get' => [
'fields' => [
'id', 'individual_id', 'role_id', 'disabled', 'username'
]
],
'removeEmpty' => [ 'removeEmpty' => [
'password' 'password'
], ],
@ -172,12 +167,15 @@ class UsersController extends AppController
'password', 'confirm_password' 'password', 'confirm_password'
] ]
]; ];
if (!empty($this->ACL->getUser()['role']['perm_admin'])) { if ($this->request->is(['get'])) {
$params['fields'] = array_merge($params['fields'], ['individual_id', 'role_id', 'disabled', 'username']);
}
if ($this->request->is(['post', 'put']) && !empty($this->ACL->getUser()['role']['perm_admin'])) {
$params['fields'][] = 'individual_id'; $params['fields'][] = 'individual_id';
$params['fields'][] = 'role_id'; $params['fields'][] = 'role_id';
$params['fields'][] = 'organisation_id'; $params['fields'][] = 'organisation_id';
$params['fields'][] = 'disabled'; $params['fields'][] = 'disabled';
} else if (!empty($this->ACL->getUser()['role']['perm_org_admin'])) { } else if ($this->request->is(['post', 'put']) && !empty($this->ACL->getUser()['role']['perm_org_admin'])) {
$params['fields'][] = 'role_id'; $params['fields'][] = 'role_id';
$params['fields'][] = 'disabled'; $params['fields'][] = 'disabled';
if (!$currentUser['role']['perm_admin']) { if (!$currentUser['role']['perm_admin']) {