chg: [decayingModels:enable/disable] Return a better API response

pull/8796/head
Sami Mokaddem 2022-11-28 10:16:06 +01:00
parent fb2fb83682
commit f3bd901f4e
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
1 changed files with 15 additions and 11 deletions

View File

@ -377,13 +377,15 @@ class DecayingModelController extends AppController
$decaying_model['DecayingModel']['enabled'] = 1;
if ($this->DecayingModel->save($decaying_model)) {
$model = $this->DecayingModel->fetchModel($this->Auth->user(), $id, true, array(), true);
if (empty($model)) {
throw new NotFoundException(__('No Decaying Model with the provided ID exists'));
}
$response = array('data' => $model, 'action' => 'enable');
if ($this->request->is('ajax')) {
$model = $this->DecayingModel->fetchModel($this->Auth->user(), $id, true, array(), true);
if (empty($model)) {
throw new NotFoundException(__('No Decaying Model with the provided ID exists'));
}
$response = array('data' => $model, 'action' => 'enable');
return $this->RestResponse->viewData($response, $this->response->type());
} else if ($this->_isRest()) {
return $this->RestResponse->successResponse($id, __('Decaying model enabled'), $model);
}
$this->Flash->success(__('Decaying Model enabled.'));
} else {
@ -400,7 +402,7 @@ class DecayingModelController extends AppController
}
$this->Flash->error(__('Error while enabling decaying model'));
}
$this->redirect($this->referer());
$this->redirect(array('action' => 'index'));
} else {
$this->set('model', $decaying_model['DecayingModel']);
$this->render('ajax/enable_form');
@ -420,13 +422,15 @@ class DecayingModelController extends AppController
$decaying_model['DecayingModel']['enabled'] = 0;
if ($this->DecayingModel->save($decaying_model)) {
$model = $this->DecayingModel->fetchModel($this->Auth->user(), $id, true, array(), true);
if (empty($model)) {
throw new NotFoundException(__('No Decaying Model with the provided ID exists'));
}
$response = array('data' => $model, 'action' => 'disable');
if ($this->request->is('ajax')) {
$model = $this->DecayingModel->fetchModel($this->Auth->user(), $id, true, array(), true);
if (empty($model)) {
throw new NotFoundException(__('No Decaying Model with the provided ID exists'));
}
$response = array('data' => $model, 'action' => 'disable');
return $this->RestResponse->viewData($response, $this->response->type());
} else if ($this->_isRest()) {
return $this->RestResponse->successResponse($id, __('Decaying model disabled'), $model);
}
$this->Flash->success(__('Decaying Model disabled.'));
} else {