new: Various new features for the objects

pull/2489/head
iglocska 2017-08-23 11:57:40 +02:00
parent 412b2bcfb1
commit d3d6566b16
12 changed files with 146 additions and 25 deletions

View File

@ -46,7 +46,7 @@ class AppController extends Controller {
public $helpers = array('Utility');
private $__queryVersion = '17';
private $__queryVersion = '18';
public $pyMispVersion = '2.4.77';
public $phpmin = '5.6.5';
public $phprec = '7.0.16';

View File

@ -863,6 +863,14 @@ class EventsController extends AppController {
unset($event['EventTag'][$k]);
}
}
if (!empty($event['Object'])) {
$objectReferences = array('Attribute' => array(), 'Object' => array());
foreach ($event['Object'] as $objectKey => $object) {
if (!empty($object['ObjectReference'])) {
foreach ($object['ObjectReference'] as $refKey => $reference);
}
}
}
$params = $this->Event->rearrangeEventForView($event);
$this->params->params['paging'] = array($this->modelClass => $params);
$this->set('event', $event);

View File

@ -15,7 +15,7 @@ class ObjectReferencesController extends AppController {
public function add($objectId) {
if (Validation::uuid($objectId)) {
$temp = $this->ObjectReference->MispObject->find('first', array(
$temp = $this->ObjectReference->Object->find('first', array(
'recursive' => -1,
'fields' => array('Object.id'),
'conditions' => array('Object.uuid' => $id)
@ -25,7 +25,7 @@ class ObjectReferencesController extends AppController {
} else if (!is_numeric($objectId)) {
throw new NotFoundException(__('Invalid object'));
}
$object = $this->ObjectReference->MispObject->find('first', array(
$object = $this->ObjectReference->Object->find('first', array(
'conditions' => array('Object.id' => $objectId),
'recursive' => -1,
'contain' => array(
@ -47,7 +47,7 @@ class ObjectReferencesController extends AppController {
$this->request->data['ObjectReference'] = $this->request->data;
}
$referenced_type = 1;
$target_object = $this->ObjectReference->MispObject->find('first', array(
$target_object = $this->ObjectReference->Object->find('first', array(
'conditions' => array('Object.uuid' => $this->request->data['ObjectReference']['uuid']),
'recursive' => -1,
'fields' => array('Object.id', 'Object.uuid', 'Object.event_id')
@ -58,7 +58,7 @@ class ObjectReferencesController extends AppController {
throw new NotFoundException('Invalid target. Target has to be within the same event.');
}
} else {
$target_attribute = $this->ObjectReference->MispObject->Attribute->find('first', array(
$target_attribute = $this->ObjectReference->Object->Attribute->find('first', array(
'conditions' => array('Attribute.uuid' => $this->request->data['ObjectReference']['uuid']),
'recursive' => -1,
'fields' => array('Attribute.id', 'Attribute.uuid', 'Attribute.event_id')
@ -110,7 +110,7 @@ class ObjectReferencesController extends AppController {
if ($this->_isRest()) {
return $this->RestResponse->describe('ObjectReferences', 'add', false, $this->response->type());
} else {
$event = $this->ObjectReference->MispObject->Event->find('first', array(
$event = $this->ObjectReference->Object->Event->find('first', array(
'conditions' => array('Event.id' => $object['Event']['id']),
'recursive' => -1,
'fields' => array('Event.id'),
@ -162,7 +162,49 @@ class ObjectReferencesController extends AppController {
}
public function delete($id, $hard = false) {
if (Validation::uuid($id)) {
$temp = $this->ObjectReference->find('first', array(
'recursive' => -1,
'fields' => array('ObjectReference.id'),
'conditions' => array('ObjectReference.uuid' => $id)
));
if (empty($temp)) throw new NotFoundException('Invalid object reference');
$id = $temp['ObjectReference']['id'];
} else if (!is_numeric($id)) {
throw new NotFoundException(__('Invalid object reference'));
}
$objectReference = $this->ObjectReference->find('first', array(
'conditions' => array('ObjectReference.id' => $id),
'recursive' => -1,
'contain' => array('Object' => array('Event'))
));
if (empty($objectReference)) {
throw new MethodNotAllowedException('Invalid object reference.');
}
if (!$this->_isSiteAdmin() && $this->Auth->user('org_id') != $objectReference['Object']['Event']['orgc_id']) {
throw new MethodNotAllowedException('Invalid object reference.');
}
if ($this->request->is('post') || $this->request->is('put') || $this->request->is('delete')) {
$result = $this->ObjectReference->smartDelete($objectReference['ObjectReference']['id'], $hard);
if ($result === true) {
if ($this->_isRest()) {
return $this->RestResponse->saveSuccessResponse('ObjectReferences', 'delete', $id, $this->response->type());
} else {
return new CakeResponse(array('body'=> json_encode(array('saved' => true, 'success' => 'Object reference deleted.')), 'status'=>200, 'type' => 'json'));
}
} else {
if ($this->_isRest()) {
return $this->RestResponse->saveFailResponse('ObjectReferences', 'delete', $id, $result, $this->response->type());
} else {
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'Object reference was not deleted.')), 'status'=>200, 'type' => 'json'));
}
}
} else {
$this->set('hard', $hard);
$this->set('id', $id);
$this->set('event_id', $objectReference['Object']['Event']['id']);
$this->render('ajax/delete');
}
}
public function view($id) {

View File

@ -662,7 +662,7 @@ class ShadowAttributesController extends AppController {
'static' => array('old_id' => 'Attribute.id', 'uuid' => 'Attribute.uuid', 'event_id' => 'Attribute.event_id', 'event_uuid' => 'Event.uuid', 'event_org_id' => 'Event.orgc_id'),
'optional' => array('category', 'type', 'value', 'to_ids', 'comment')
);
if ($existingAttribute['object_id']) {
if ($existingAttribute['Attribute']['object_id']) {
unset($fields['optional']['type']);
$fields['static']['type'] = 'Attribute.type';
}
@ -744,7 +744,7 @@ class ShadowAttributesController extends AppController {
foreach ($this->ShadowAttribute->Event->Attribute->typeDefinitions as $key => $value) {
$info['type'][$key] = array('key' => $key, 'desc' => isset($value['formdesc'])? $value['formdesc'] : $value['desc']);
}
$categoryDefinitions = $this->ShadowAttribute->Event->Attribute->categoryDefinitions;
if ($existingAttribute['Attribute']['object_id']) {
foreach ($categoryDefinitions as $k => $v) {
if (!in_array($existingAttribute['Attribute']['type'], $v['types'])) {

View File

@ -2240,6 +2240,28 @@ class Attribute extends AppModel {
return $this->find('list', $params);
}
public function fetchAttributesSimple($user, $options = array()) {
$params = array(
'conditions' => $this->buildConditions($user),
'fields' => array(),
'recursive' => -1
);
if (isset($options['conditions'])) {
$params['conditions']['AND'][] = $options['conditions'];
}
if (isset($options['fields'])) {
$params['fields'] = $options['fields'];
}
$results = $this->find('all', array(
'conditions' => $params['conditions'],
'recursive' => -1,
'fields' => $params['fields'],
'sort' => false
));
return $results;
}
// Method that fetches all attributes for the various exports
// very flexible, it's basically a replacement for find, with the addition that it restricts access based on user
// options:
@ -2256,7 +2278,7 @@ class Attribute extends AppModel {
'Event' => array(
'fields' => array('id', 'info', 'org_id', 'orgc_id', 'uuid'),
),
),
)
);
$params['contain']['AttributeTag'] = array('Tag' => array('conditions' => array()));
if (empty($options['includeAllTags'])) $params['contain']['AttributeTag']['Tag']['conditions']['exportable'] = 1;

View File

@ -1482,6 +1482,11 @@ class Event extends AppModel {
$this->Sighting = ClassRegistry::init('Sighting');
}
$userEmails = array();
$fields = array(
'common' => array('distribution', 'sharing_group_id', 'uuid'),
'Attribute' => array('value', 'type', 'category', 'to_ids'),
'Object' => array('name', 'meta-category')
);
foreach ($results as $eventKey => &$event) {
if (!empty($event['Object'])) {
foreach ($event['Object'] as $k => $object) {
@ -1490,7 +1495,7 @@ class Event extends AppModel {
$type = array('Attribute', 'Object')[$reference['referenced_type']];
$temp = $this->{$type}->find('first', array(
'recursive' => -1,
'fields' => array('distribution', 'sharing_group_id', 'uuid'),
'fields' => array_merge($fields['common'], $fields[array('Attribute', 'Object')[$reference['referenced_type']]]),
'conditions' => array('id' => $reference['referenced_id'])
));
if (!empty($temp)) {

View File

@ -12,7 +12,7 @@ class ObjectReference extends AppModel {
);
public $belongsTo = array(
'MispObject' => array(
'Object' => array(
'className' => 'MispObject',
'foreignKey' => 'object_id'
),
@ -38,7 +38,6 @@ class ObjectReference extends AppModel {
public $validate = array(
);
public function beforeValidate($options = array()) {
parent::beforeValidate();
if (empty($this->data['ObjectReference']['uuid'])) {
@ -49,4 +48,19 @@ class ObjectReference extends AppModel {
return true;
}
public function smartDelete($id, $hard = false) {
if ($hard) {
return $this->delete($id);
} else {
$reference = $this->find('first', array(
'conditions' => array('ObjectReference.id' => $id),
'recursive' => -1
));
if (empty($reference)) return array('Invalid object reference.');
$reference['ObjectReference']['deleted'] = 1;
$result = $this->save($reference);
if ($result) return true;
return $this->validationErrors;
}
}
}

View File

@ -39,7 +39,22 @@
</div>
<span class="bold">References: </span>
<?php
echo count($object['ObjectReference']);
$refCount = count($object['ObjectReference']);
if ($deleted) {
$temp = array(0, 0);
foreach ($object['ObjectReference'] as $objectRef) {
if ($objectRef['deleted']) {
$temp[1]++;
} else {
$temp[0]++;
}
}
$refCount = $temp[0];
if ($temp[1] != 0) {
$refCount .= ' <span class="strikethrough">' . $temp[1] . '</span>';
}
}
echo $refCount;
if (!empty($object['ObjectReference'])):
?>
<span class="fa fa-expand useCursorPointer" title="Expand or Collapse" role="button" tabindex="0" aria-label="Expand or Collapse" data-toggle="collapse" data-target="#Object_<?php echo h($object['id']); ?>_references_collapsible"></span>
@ -50,9 +65,19 @@
<div id="Object_<?php echo $object['id']; ?>_references_collapsible" class="collapse">
<?php
foreach ($object['ObjectReference'] as $reference):
if (!empty($reference['Object'])) {
$uuid = $reference['Object']['uuid'];
$output = ' (' . $reference['Object']['name'] . ': ' . $reference['Object']['name'] . ')';
} else {
$uuid = $reference['Attribute']['uuid'];
$output = ' (' . $reference['Attribute']['category'] . '/' . $reference['Attribute']['type'] . ': "' . $reference['Attribute']['value'] . '")';
}
$uuid = empty($reference['Object']) ? $reference['Attribute']['uuid'] : $reference['Object']['uuid'];
$idref = $reference['deleted'] ? $reference['id'] . '/1' : $reference['id'];
?>
&nbsp;&nbsp;<a class="bold white useCursorPointer" onClick="pivotObjectReferences('<?php echo h($currentUri); ?>', '<?php echo $uuid; ?>')"><?php echo h($reference['relationship_type']) . ' ' . array('Attribute', 'Object')[$reference['referenced_type']];?></a><br />
&nbsp;&nbsp;<a class="bold white useCursorPointer <?php echo $reference['deleted'] ? 'strikethrough' : ''; ?>" onClick="pivotObjectReferences('<?php echo h($currentUri); ?>', '<?php echo $uuid; ?>')"><?php echo h($reference['relationship_type']) . ' ' . array('Attribute', 'Object')[$reference['referenced_type']] . h($output);?></a>
<span class="icon-trash icon-white useCursorPointer" title="Delete object reference" role="button" tabindex="0" aria-label="Delete object reference" onClick="deleteObject('object_references', 'delete', '<?php echo h($idref); ?>', '<?php echo h($event['Event']['id']); ?>');"></span>
<br />
<?php
endforeach;
?>

View File

@ -12,10 +12,10 @@
} else {
$tr_class .= ' tableInsetOrange';
}
if ($objectContainer === true) {
$tr_class .= ' tableHighlightBorderCenter borderBlue';
} else {
if ($child === 'last') {
$tr_class .= ' tableHighlightBorderBottom borderBlue';
} else {
$tr_class .= ' tableHighlightBorderCenter borderBlue';
}
} else {
if (!empty($child)) {

View File

@ -12,10 +12,10 @@
} else {
$tr_class .= ' tableInsetOrange';
}
if ($objectContainer === true) {
$tr_class .= ' tableHighlightBorderCenter borderBlue';
} else {
if ($child === 'last') {
$tr_class .= ' tableHighlightBorderBottom borderBlue';
} else {
$tr_class .= ' tableHighlightBorderCenter borderBlue';
}
} else {
if (!empty($child)) {

View File

@ -1,5 +1,5 @@
/* bootstrap changes */
body{
body {
font-size: 12px;
}
@ -7,11 +7,11 @@ input, button, select, textarea{
}
input[type="file"]{
input[type="file"] {
margin-bottom: 10px;
}
button .full-width{
button .full-width {
width:100%;
}
@ -1882,6 +1882,10 @@ tr.blank_table_row td {
background-color: #ffffff !important;
}
.strikethrough {
text-decoration: line-through;
}
@-webkit-keyframes rotation {
from {-webkit-transform: rotate(0deg);}
to {-webkit-transform: rotate(359deg);}

View File

@ -4,8 +4,9 @@ String.prototype.ucfirst = function() {
function deleteObject(type, action, id, event) {
var destination = 'attributes';
var alternateDestinations = ['shadow_attributes', 'template_elements', 'taxonomies', 'objects'];
var alternateDestinations = ['shadow_attributes', 'template_elements', 'taxonomies', 'objects', 'object_references'];
if (alternateDestinations.indexOf(type) > -1) destination = type;
else destination = type;
url = "/" + destination + "/" + action + "/" + id;
$.get(url, function(data) {
openPopup("#confirmation_box");