chg: [eventReport:edit] Allow to edit individual fields and better error

reporting
pull/6412/head
mokaddem 2020-09-17 09:55:13 +02:00
parent 23bbe2e730
commit c888403289
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
2 changed files with 16 additions and 10 deletions

View File

@ -119,12 +119,18 @@ class EventReportsController extends AppController
public function edit($id)
{
$report = $this->EventReport->fetchIfAuthorized($this->Auth->user(), $id, 'edit', $throwErrors=true, $full=true);
if ($this->request->is('post') || $this->request->is('put')) {
$report = $this->request->data;
if (!isset($report['EventReport'])) {
$report = array('EventReport' => $report);
$newReport = $this->request->data;
if (!isset($newReport['EventReport'])) {
$newReport = array('EventReport' => $newReport);
}
$fieldList = array('id', 'name', 'content', 'timestamp', 'distribution', 'sharing_group_id', 'deleted');
foreach ($fieldList as $field) {
if (!empty($newReport['EventReport'][$field])) {
$report['EventReport'][$field] = $newReport['EventReport'][$field];
}
}
$report['EventReport']['id'] = $id;
$errors = $this->EventReport->editReport($this->Auth->user(), $report);
if (!empty($errors)) {
$flashErrorMessage = implode(', ', $errors);
@ -147,10 +153,10 @@ class EventReportsController extends AppController
}
}
} else {
$report = $this->EventReport->fetchIfAuthorized($this->Auth->user(), $id, 'edit', $throwErrors=true, $full=true);
$this->request->data = $report;
}
$this->set('id', $report['EventReport']['id']);
$this->set('event_id', $report['EventReport']['event_id']);
$distributionLevels = $this->EventReport->Event->Attribute->distributionLevels;
$this->set('distributionLevels', $distributionLevels);

View File

@ -26,11 +26,6 @@ class EventReport extends AppModel
'rule' => array('inList', array('0', '1', '2', '3', '4', '5')),
'message' => 'Options: Your organisation only, This community only, Connected communities, All communities, Sharing group, Inherit event',
'required' => true
),
'value' => array(
'stringNotEmpty' => array(
'rule' => array('stringNotEmpty')
),
)
);
@ -112,6 +107,11 @@ class EventReport extends AppModel
}
$fieldList = array('name', 'content', 'timestamp', 'distribution', 'sharing_group_id', 'deleted');
$saveSuccess = $this->save($report, array('fieldList' => $fieldList));
if (!$saveSuccess) {
foreach ($this->validationErrors as $validationError) {
$errors[] = $validationError[0];
}
}
return $errors;
}