fix: [api] minor fix to the blacklist responses

pull/6172/head
iglocska 2020-08-03 16:39:38 +02:00
parent 7d068121e7
commit d54c707cbe
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
1 changed files with 10 additions and 13 deletions

View File

@ -163,23 +163,20 @@ class BlackListComponent extends Component
public function delete($rest = false, $id)
{
if (strlen($id) == 36) {
$blockEntry = $this->controller->{$this->controller->defaultModel}->find('first', array(
'fields' => array('id'),
'conditions' => array('event_uuid' => $id),
));
$id = $blockEntry[$this->controller->defaultModel]['id'];
if (Validation::uuid($id)) {
$blockEntry = $this->controller->{$this->controller->defaultModel}->find('first', [
'conditions' => array(
$this->controller->{$this->controller->defaultModel}->blacklistTarget . '_uuid' => $id
)
]);
} else {
$blockEntry = $this->controller->{$this->controller->defaultModel}->find('first', array('conditions' => array('id' => $id)));
}
if (!$this->controller->request->is('post') && !$rest) {
throw new MethodNotAllowedException();
}
$this->controller->{$this->controller->defaultModel}->id = $id;
if (!$this->controller->{$this->controller->defaultModel}->exists()) {
if (empty($blockEntry)) {
throw new NotFoundException(__('Invalid blacklist entry'));
}
if ($this->controller->{$this->controller->defaultModel}->delete()) {
if ($this->controller->{$this->controller->defaultModel}->delete($blockEntry[$this->controller->defaultModel]['id'])) {
$message = __('Blacklist entry removed');
if ($rest) {
return $this->RestResponse->saveSuccessResponse($this->controller->defaultModel, 'delete', $id, false, $message);