Merge pull request #6117 from JakubOnderka/delete-object-proposal

fix: [proposals] Delete proposals for object attributes
pull/6118/head
Jakub Onderka 2020-07-14 16:01:58 +02:00 committed by GitHub
commit c161e25372
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 33 deletions

View File

@ -803,20 +803,18 @@ class ShadowAttributesController extends AppController
public function delete($id)
{
if (strlen($id) == 36) {
$this->ShadowAttribute->Event->recursive = -1;
$temp = $this->ShadowAttribute->Event->Attribute->find('first', array('recursive' => -1, 'conditions' => array('Attribute.uuid' => $id), 'fields' => array('id')));
if ($temp == null) {
throw new NotFoundException(__('Invalid attribute'));
}
$id = $temp['Attribute']['id'];
}
$existingAttribute = $this->ShadowAttribute->Event->Attribute->fetchAttributes($this->Auth->user(), array('conditions' => array('Attribute.id' => $id)));
if (empty($existingAttribute)) {
throw new NotFoundException(__('Invalid attribute.'));
if (is_numeric($id)) {
$conditions = ['Attribute.id' => $id];
} else if (Validation::uuid($id)) {
$conditions = ['Attribute.uuid' => $id];
} else {
throw new NotFoundException(__('Invalid attribute'));
}
$existingAttribute = $this->ShadowAttribute->Event->Attribute->fetchAttributes(
$this->Auth->user(),
array('conditions' => $conditions, 'flatten' => true)
);
if ($this->request->is('post')) {
if (empty($existingAttribute)) {
return new CakeResponse(array('body'=> json_encode(array('false' => true, 'errors' => 'Invalid Attribute.')), 'status'=>200, 'type' => 'json'));
@ -850,7 +848,7 @@ class ShadowAttributesController extends AppController
}
} else {
if (empty($existingAttribute)) {
throw new NotFoundException(__('Invalid Attribute'));
throw new NotFoundException(__('Invalid attribute'));
}
$existingAttribute = $existingAttribute[0];
$this->set('id', $id);

View File

@ -23,16 +23,22 @@ function stringToRGB(str){
return "#" + "00000".substring(0, 6 - c.length) + c;
}
function deleteObject(type, action, id, event) {
var destination = 'attributes';
var alternateDestinations = ['shadow_attributes', 'template_elements', 'taxonomies', 'galaxy_clusters', 'objects', 'object_references'];
if (alternateDestinations.indexOf(type) > -1) destination = type;
else destination = type;
url = "/" + destination + "/" + action + "/" + id;
function xhrFailCallback(xhr) {
if (xhr.status === 403) {
showMessage('fail', 'Not allowed.');
} else if (xhr.status === 404) {
showMessage('fail', 'Resource not found.');
} else {
showMessage('fail', 'Something went wrong - the queried function returned an exception. Contact your administrator for further details.');
}
}
function deleteObject(type, action, id) {
var url = "/" + type + "/" + action + "/" + id;
$.get(url, function(data) {
openPopup("#confirmation_box");
$("#confirmation_box").html(data);
});
}).fail(xhrFailCallback)
}
function quickDeleteSighting(id, rawId, context) {
@ -40,7 +46,7 @@ function quickDeleteSighting(id, rawId, context) {
$.get(url, function(data) {
$("#confirmation_box").html(data);
openPopup("#confirmation_box");
});
}).fail(xhrFailCallback)
}
function fetchAddSightingForm(type, attribute_id, page, onvalue) {
@ -1767,11 +1773,7 @@ function getPopup(id, context, target, admin, popupType) {
error:function(xhr) {
$(".loading").hide();
$("#gray_out").fadeOut();
if (xhr.status === 403) {
showMessage('fail', 'Not allowed.');
} else {
showMessage('fail', 'Something went wrong - the queried function returned an exception. Contact your administrator for further details (the exception has been logged).');
}
xhrFailCallback(xhr);
},
url: url
});
@ -1893,13 +1895,7 @@ function simplePopup(url) {
error:function(xhr) {
$(".loading").hide();
$("#gray_out").fadeOut();
if (xhr.status == 403) {
showMessage('fail', 'Not allowed.');
} else if (xhr.status == 404) {
showMessage('fail', 'Resource not found.');
} else {
showMessage('fail', 'Something went wrong - the queried function returned an exception. Contact your administrator for further details (the exception has been logged).');
}
xhrFailCallback(xhr);
},
url: url,
});