new: [dashboard] added template delete functionality

pull/5705/head
iglocska 2020-03-09 00:08:23 +01:00
parent 6773b8d799
commit bf2694c490
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
2 changed files with 30 additions and 0 deletions

View File

@ -382,4 +382,32 @@ class DashboardsController extends AppController
$this->set('data', $data);
}
}
public function deleteTemplate($id)
{
$conditions = array();
if (Validation::uuid($id)) {
$conditions['AND'][] = array('Dashboard.uuid' => $id);
} else {
$conditions['AND'][] = array('Dashboard.id' => $id);
}
if (!$this->_isSiteAdmin()) {
$conditions['AND'][] = array('Dashboard.user_id' => $this->Auth->user('id'));
}
$dashboard = $this->Dashboard->find('first', array(
'conditions' => $conditions,
'recursive' => -1
));
if (empty($dashboard)) {
throw new NotFoundException(__('Invalid dashboard template.'));
}
$this->Dashboard->delete($dashboard['Dashboard']['id']);
$message = __('Dashboard template removed.');
if ($this->_isRest()) {
return $this->RestResponse->saveSuccessResponse('Dashboard', 'delete', $id, false, $message);
} else {
$this->Flash->success($message);
$this->redirect($this->baseurl . '/dashboards/listTemplates');
}
}
}

View File

@ -76,6 +76,8 @@
'url_params_data_paths' => array(
'Dashboard.uuid'
),
'postLink' => 1,
'postLinkConfirm' => __('Are you sure you want to remove this dashboard template?'),
'icon' => 'trash'
)
)