Distribution

distribution changes conform func.spec.
pull/63/head
noud 2012-10-29 16:49:04 +01:00
parent bf6f86c5aa
commit 39abe9e589
3 changed files with 71 additions and 15 deletions

View File

@ -33,7 +33,7 @@ class EventsController extends AppController {
);
public $helpers = array('Js' => array('Jquery'));
public function beforeFilter() {
parent::beforeFilter();
@ -80,16 +80,16 @@ class EventsController extends AppController {
}
}
// do not show cluster outside server
if ('true' == Configure::read('CyDefSIG.private')) {
if ($this->_isRest()) {
$this->paginate = Set::merge($this->paginate,array(
'conditions' =>
array(array('Event.cluster !=' => true)),
//array("AND" => array(array('Event.private !=' => 2))),
));
}
}
// // do not show cluster outside server
// if ('true' == Configure::read('CyDefSIG.private')) {
// if ($this->_isRest()) {
// $this->paginate = Set::merge($this->paginate,array(
// 'conditions' =>
// array(array('Event.cluster !=' => true)),
// //array("AND" => array(array('Event.private !=' => 2))),
// ));
// }
// }
}
public function isAuthorized($user) {
@ -283,6 +283,10 @@ class EventsController extends AppController {
// TODO or massageData here
if ('true' == Configure::read('CyDefSIG.private')) {
if ($this->_isRest()) {
// Distribution, reporter for the events pushed will be the owner of the authentication key
$this->request->data['Event']['user_id'] = $this->Auth->user('id');
}
$this->request->data = $this->Event->massageData(&$this->request->data);
}

View File

@ -176,7 +176,36 @@ class ServersController extends AppController {
$this->Server->data);
if (null != $event) {
// we have an Event array
$event['Event']['private'] = true;
if ('true' == Configure::read('CyDefSIG.private')) {
// Distribution, no Org only in Event
if ($event['Event']['distribution'] == 'Org') {
continue;
}
// Distribution, correct Community to Org only in Event
if ($event['Event']['distribution'] == 'Community') {
$event['Event']['distribution'] = 'Org';
}
// Distribution, correct All to Community in Event
if ($event['Event']['distribution'] == 'All') {
$event['Event']['distribution'] = 'Community';
}
if (is_array($event['Event']['Attribute'])) {
foreach ($event['Event']['Attribute'] as &$attribute) {
// Distribution, correct Community to Org only in Attribute
if ($attribute['distribution'] == 'Community') {
$attribute['distribution'] = 'Org';
}
// Distribution, correct All to Community in Attribute
if ($attribute['distribution'] == 'All') {
$attribute['distribution'] = 'Community';
}
}
}
// Distribution, set reporter of the event, being the admin that initiated the pull
$event['Event']['user_id'] = $this->Auth->user('id');
} else {
$event['Event']['private'] = true;
}
$event['Event']['info'] .= "\n Imported from " . $this->Server->data['Server']['url'];
$eventsController = new EventsController();
try {

View File

@ -367,11 +367,11 @@ class Event extends AppModel {
* @return bool true if success, error message if failed
*/
public function uploadEventToServer($event, $server, $HttpSocket=null) {
if (('true' != Configure::read('CyDefSIG.private')) && (true == $event['Event']['private'])) { // never upload private events
if (true == $event['Event']['private']) { // never upload private events
return "Event is private and non exportable";
}
if (('true' == Configure::read('CyDefSIG.private')) && (true == $event['Event']['pull'])) {
return "Event is pull only and non exportable";
if (('true' == Configure::read('CyDefSIG.private')) && ($event['Event']['pull'])) {
return "Event is No push so non exportable";
}
$url = $server['Server']['url'];
@ -405,6 +405,17 @@ class Event extends AppModel {
unset($event['Event']['Attribute'][$key]);
continue; // stop processing this
}
// Distribution, correct Community to Org only in Attribute
if ($attribute['cluster'] && !$attribute['private']) {
$attribute['private'] = true;
$attribute['cluster'] = false;
$attribute['distribution'] = 'Org';
}
// Distribution, correct All to Community in Attribute
if (!$attribute['cluster'] && !$attribute['private'] && !$attribute['pull']) {
$attribute['cluster'] = true;
$attribute['distribution'] = 'Community';
}
// remove value1 and value2 from the output
unset($attribute['value1']);
unset($attribute['value2']);
@ -414,6 +425,17 @@ class Event extends AppModel {
$attribute['data'] = $encodedFile;
}
}
// Distribution, correct Community to Org only in Event
if ($event['Event']['cluster'] && !$event['Event']['private']) {
$event['Event']['private'] = true;
$event['Event']['cluster'] = false;
$event['Event']['distribution'] = 'Org';
}
// Distribution, correct All to Community in Event
if (!$event['Event']['cluster'] && !$event['Event']['private'] && !$event['Event']['pull']) {
$event['Event']['cluster'] = true;
$event['Event']['distribution'] = 'Community';
}
// display the XML to the user
$xmlArray['Event'][] = $event['Event'];
@ -541,6 +563,7 @@ class Event extends AppModel {
$response = $HttpSocket->get($uri, $data = '', $request);
if ($response->isOk()) {
//debug($response->body);
$xml = Xml::build($response->body);
$eventArray = Xml::toArray($xml);
$eventIds = array();