Merge branch 'feature/sg_api' into 2.4

pull/2831/head
iglocska 2018-01-13 14:26:57 +01:00
commit f0f9f121d6
8 changed files with 256 additions and 120 deletions

View File

@ -89,6 +89,18 @@ class RestResponseComponent extends Component {
'mandatory' => array('OR' => array('values', 'id')),
'optional' => array('type', 'source', 'timestamp', 'date', 'time')
)
),
'SharingGroup' => array(
'add' => array(
'description' => "POST a Sharing Group object in JSON format to this API to add a Sharing Group. The API will also try to capture attached organisations and servers if applicable to the current user.",
'mandatory' => array('name', 'releasability'),
'optional' => array('description', 'uuid', 'organisation_uuid (sync/site admin only)', 'active', 'created', 'modified', 'roaming', 'Server' => array('url', 'name', 'all_orgs'), 'Organisation' => array('uuid', 'name', 'extend'))
),
'edit' => array(
'description' => "POST a Sharing Group object in JSON format to this API to edit a Sharing Group. The API will also try to capture attached organisations and servers if applicable to the current user.",
'mandatory' => array(),
'optional' => array('name', 'releasability', 'description', 'uuid', 'organisation_uuid (sync/site admin only)', 'active', 'created', 'modified', 'roaming', 'SharingGroupServer' => array('url', 'name', 'all_orgs'), 'SharingGroupOrg' => array('uuid', 'name', 'extend'))
)
)
);
@ -146,7 +158,8 @@ class RestResponseComponent extends Component {
}
private function __generateURL($action, $controller, $id) {
return ($action['admin'] ? '/admin' : '') . '/' . strtolower($controller) . '/' . $action['action'] . ($id ? '/' . $id : '');
$controller = Inflector::underscore(Inflector::pluralize($controller));
return ($action['admin'] ? '/admin' : '') . '/' . $controller . '/' . $action['action'] . ($id ? '/' . $id : '');
}
private function __dissectAdminRouting($action) {

View File

@ -36,25 +36,52 @@ class SharingGroupsController extends AppController {
public function add() {
if (!$this->userRole['perm_sharing_group']) throw new MethodNotAllowedException('You don\'t have the required privileges to do that.');
$orgs = $this->SharingGroup->Organisation->find('all', array(
'conditions' => array('local' => 1),
'recursive' => -1,
'fields' => array('id', 'name', 'uuid')
));
if ($this->request->is('post')) {
$json = json_decode($this->request->data['SharingGroup']['json'], true);
if ($this->_isRest()) {
$sg = $this->request->data;
if (isset($this->request->data['SharingGroup'])) {
$this->request->data = $this->request->data['SharingGroup'];
}
$id = $this->SharingGroup->captureSG($this->request->data, $this->Auth->user());
if ($id) {
$sg = $this->SharingGroup->fetchAllAuthorised($this->Auth->user(), 'simplified', false, $id);
return $this->RestResponse->viewData($sg, $this->response->type());
} else {
return $this->RestResponse->saveFailResponse('SharingGroup', 'add', false, 'Could not save sharing group.', $this->response->type());
}
} else {
$json = json_decode($this->request->data['SharingGroup']['json'], true);
$sg = $json['sharingGroup'];
if (!empty($json['organisations'])) {
$sg['Organisation'] = $json['organisations'];
}
if (!empty($json['servers'])) {
$sg['Server'] = $json['servers'];
}
}
$this->SharingGroup->create();
$sg = $json['sharingGroup'];
$sg['organisation_uuid'] = $this->Auth->user('Organisation')['uuid'];
$sg['local'] = 1;
$sg['org_id'] = $this->Auth->user('org_id');
$this->request->data['SharingGroup']['organisation_uuid'] = $this->Auth->user('Organisation')['uuid'];
if ($this->SharingGroup->save(array('SharingGroup' => $sg))) {
foreach ($json['organisations'] as $org) {
$this->SharingGroup->SharingGroupOrg->create();
$this->SharingGroup->SharingGroupOrg->save(array(
'sharing_group_id' => $this->SharingGroup->id,
'org_id' => $org['id'],
'extend' => $org['extend']
));
if (!empty($sg['Organisation'])) {
foreach ($sg['Organisation'] as $org) {
$this->SharingGroup->SharingGroupOrg->create();
$this->SharingGroup->SharingGroupOrg->save(array(
'sharing_group_id' => $this->SharingGroup->id,
'org_id' => $org['id'],
'extend' => $org['extend']
));
}
}
if (!$json['sharingGroup']['roaming']) {
foreach ($json['servers'] as $server) {
if (!$sg['roaming'] && !empty($sg['Server'])) {
foreach ($sg['Server'] as $server) {
$this->SharingGroup->SharingGroupServer->create();
$this->SharingGroup->SharingGroupServer->save(array(
'sharing_group_id' => $this->SharingGroup->id,
@ -74,20 +101,18 @@ class SharingGroupsController extends AppController {
foreach ($validationReplacements as $k => $vR) if ($reason == $k) $reason = $vR;
$this->Session->setFlash('The sharing group could not be added. ' . ucfirst($failedField) . ': ' . $reason);
}
} else if ($this->_isRest()) {
return $this->RestResponse->describe('SharingGroup', 'add', false, $this->response->type());
}
$orgs = $this->SharingGroup->Organisation->find('all', array(
'conditions' => array('local' => 1),
'recursive' => -1,
'fields' => array('id', 'name')
));
$this->set('orgs', $orgs);
$this->set('localInstance', Configure::read('MISP.baseurl'));
// We just pass true and allow the user to edit, since he/she is just about to create the SG. This is needed to reuse the view for the edit
$this->set('user', $this->Auth->user());
}
public function edit($id) {
public function edit($id = false) {
if (!$this->userRole['perm_sharing_group']) throw new MethodNotAllowedException('You don\'t have the required privileges to do that.');
if (empty($id)) throw new NotFoundException('Invalid sharing group.');
// add check for perm_sharing_group
$this->SharingGroup->id = $id;
if (!$this->SharingGroup->exists()) throw new NotFoundException('Invalid sharing group.');
@ -112,27 +137,43 @@ class SharingGroupsController extends AppController {
),
));
if ($this->request->is('post')) {
$json = json_decode($this->request->data['SharingGroup']['json'], true);
$sg = $json['sharingGroup'];
$sg['id'] = $id;
$fields = array('name', 'releasability', 'description', 'active', 'roaming');
$existingSG = $this->SharingGroup->find('first', array('recursive' => -1, 'conditions' => array('SharingGroup.id' => $id)));
foreach ($fields as $field) $existingSG['SharingGroup'][$field] = $sg[$field];
unset($existingSG['SharingGroup']['modified']);
if ($this->SharingGroup->save($existingSG)) {
$this->SharingGroup->SharingGroupOrg->updateOrgsForSG($id, $json['organisations'], $sharingGroup['SharingGroupOrg'], $this->Auth->user());
$this->SharingGroup->SharingGroupServer->updateServersForSG($id, $json['servers'], $sharingGroup['SharingGroupServer'], $json['sharingGroup']['roaming'], $this->Auth->user());
$this->redirect('/SharingGroups/view/' . $id);
if ($this->_isRest()) {
if (isset($this->request->data['SharingGroup'])) {
$this->request->data = $this->request->data['SharingGroup'];
}
$this->request->data['uuid'] = $sharingGroup['SharingGroup']['uuid'];
$id = $this->SharingGroup->captureSG($this->request->data, $this->Auth->user());
if ($id) {
$sg = $this->SharingGroup->fetchAllAuthorised($this->Auth->user(), 'simplified', false, $id);
return $this->RestResponse->viewData($sg, $this->response->type());
} else {
return $this->RestResponse->saveFailResponse('SharingGroup', 'add', false, 'Could not save sharing group.', $this->response->type());
}
} else {
$validationReplacements = array(
'notempty' => 'This field cannot be left empty.',
);
$validationErrors = $this->SharingGroup->validationErrors;
$failedField = array_keys($validationErrors)[0];
$reason = reset($this->SharingGroup->validationErrors)[0];
foreach ($validationReplacements as $k => $vR) if ($reason == $k) $reason = $vR;
$this->Session->setFlash('The sharing group could not be edited. ' . ucfirst($failedField) . ': ' . $reason);
$json = json_decode($this->request->data['SharingGroup']['json'], true);
$sg = $json['sharingGroup'];
$sg['id'] = $id;
$fields = array('name', 'releasability', 'description', 'active', 'roaming');
$existingSG = $this->SharingGroup->find('first', array('recursive' => -1, 'conditions' => array('SharingGroup.id' => $id)));
foreach ($fields as $field) $existingSG['SharingGroup'][$field] = $sg[$field];
unset($existingSG['SharingGroup']['modified']);
if ($this->SharingGroup->save($existingSG)) {
$this->SharingGroup->SharingGroupOrg->updateOrgsForSG($id, $json['organisations'], $sharingGroup['SharingGroupOrg'], $this->Auth->user());
$this->SharingGroup->SharingGroupServer->updateServersForSG($id, $json['servers'], $sharingGroup['SharingGroupServer'], $json['sharingGroup']['roaming'], $this->Auth->user());
$this->redirect('/SharingGroups/view/' . $id);
} else {
$validationReplacements = array(
'notempty' => 'This field cannot be left empty.',
);
$validationErrors = $this->SharingGroup->validationErrors;
$failedField = array_keys($validationErrors)[0];
$reason = reset($this->SharingGroup->validationErrors)[0];
foreach ($validationReplacements as $k => $vR) if ($reason == $k) $reason = $vR;
$this->Session->setFlash('The sharing group could not be edited. ' . ucfirst($failedField) . ': ' . $reason);
}
}
} else if ($this->_isRest()) {
return $this->RestResponse->describe('SharingGroup', 'edit', false, $this->response->type());
}
$orgs = $this->SharingGroup->Organisation->find('all', array(
'conditions' => array('local' => 1),
@ -156,8 +197,17 @@ class SharingGroupsController extends AppController {
'recursive' => -1,
'fields' => array('active')
));
if ($this->SharingGroup->delete($id)) $this->Session->setFlash(__('Sharing Group deleted'));
else $this->Session->setFlash(__('Sharing Group could not be deleted. Make sure that there are no events, attributes or threads belonging to this sharing group.'));
if ($this->SharingGroup->delete($id)) {
if ($this->_isRest()) {
return $this->RestResponse->saveSuccessResponse('SharingGroups', 'delete', $id, $this->response->type());
}
$this->Session->setFlash(__('Sharing Group deleted'));
} else {
if ($this->_isRest()) {
return $this->RestResponse->saveFailResponse('SharingGroups', 'delete', $id, 'The sharing group could not be deleted.', $this->response->type());
}
$this->Session->setFlash(__('Sharing Group could not be deleted. Make sure that there are no events, attributes or threads belonging to this sharing group.'));
}
if ($deletedSg['SharingGroup']['active']) $this->redirect('/SharingGroups/index');
else $this->redirect('/SharingGroups/index/true');
@ -193,12 +243,26 @@ class SharingGroupsController extends AppController {
public function view($id) {
if (!$this->SharingGroup->checkIfAuthorised($this->Auth->user(), $id)) throw new MethodNotAllowedException('Sharing group doesn\'t exist or you do not have permission to access it.');
$this->SharingGroup->id = $id;
$this->SharingGroup->contain(array('SharingGroupOrg' => array('Organisation'), 'Organisation', 'SharingGroupServer' => array('Server')));
$this->SharingGroup->contain(
array(
'SharingGroupOrg' => array(
'Organisation' => array(
'fields' => array('id', 'name', 'uuid')
)
),
'Organisation',
'SharingGroupServer' => array(
'Server' => array(
'fields' => array('id', 'name', 'url',)
)
)
)
);
$this->SharingGroup->read();
$sg = $this->SharingGroup->data;
if (isset($sg['SharingGroupServer'])) {
foreach ($sg['SharingGroupServer'] as $key => $sgs) {
if ($sgs['server_id'] == 0) $sg['SharingGroupServer'][$key]['Server'] = array('name' => 'Local instance', 'url' => Configure::read('MISP.baseurl'));
if ($sgs['server_id'] == 0) $sg['SharingGroupServer'][$key]['Server'] = array('id' => "0", 'name' => 'Local instance', 'url' => Configure::read('MISP.baseurl'));
}
}
if ($sg['SharingGroup']['sync_user_id']) {
@ -214,6 +278,9 @@ class SharingGroupsController extends AppController {
if (empty($sync_user)) $sg['SharingGroup']['sync_org_name'] = 'N/A';
$sg['SharingGroup']['sync_org_name'] = $sync_user['Organisation']['name'];
}
if ($this->_isRest()) {
return $this->RestResponse->viewData($sg, $this->response->type());
}
$this->set('mayModify', $this->SharingGroup->checkIfAuthorisedExtend($this->Auth->user(), $id));
$this->set('id', $id);
$this->set('sg', $sg);

View File

@ -3933,6 +3933,7 @@ class Event extends AppModel {
$sharingGroupDataTemp = $this->SharingGroup->fetchAllAuthorised($user, 'simplified');
$sharingGroupData = array();
foreach ($sharingGroupDataTemp as $k => $v) {
if (isset($v['Organisation'])) $v['SharingGroup']['Organisation'] = $v['Organisation'];
if (isset($v['SharingGroupOrg'])) $v['SharingGroup']['SharingGroupOrg'] = $v['SharingGroupOrg'];
if (isset($v['SharingGroupServer'])) {
$v['SharingGroup']['SharingGroupServer'] = $v['SharingGroupServer'];

View File

@ -67,7 +67,6 @@ class SharingGroup extends AppModel {
$this->data['SharingGroup']['active'] = 0;
}
$this->data['SharingGroup']['modified'] = $date;
$sameNameSG = $this->find('first', array(
'conditions' => array('SharingGroup.name' => $this->data['SharingGroup']['name']),
'recursive' => -1,
@ -107,9 +106,14 @@ class SharingGroup extends AppModel {
// full: Entire SG object with all organisations and servers attached
// name: array in ID => name key => value format
// false: array with all IDs
public function fetchAllAuthorised($user, $scope = false, $active = false) {
public function fetchAllAuthorised($user, $scope = false, $active = false, $id = false) {
$conditions = array();
if ($active !== false) $conditions['AND'][] = array('SharingGroup.active' => $active);
if ($id) {
$conditions['AND']['SharingGroup.id'] = $id;
}
if ($active !== false) {
$conditions['AND']['SharingGroup.active'] = $active;
}
if ($user['Role']['perm_site_admin']) {
$sgs = $this->find('all', array(
'recursive' => -1,
@ -121,7 +125,9 @@ class SharingGroup extends AppModel {
} else {
$ids = array_unique(array_merge($this->SharingGroupServer->fetchAllAuthorised(), $this->SharingGroupOrg->fetchAllAuthorised($user['Organisation']['id'])));
}
if (!empty($ids)) $conditions['And'][] = array('SharingGroup.id' => $ids);
if (!empty($ids)) {
$conditions['AND'][] = array('SharingGroup.id' => $ids);
}
else return array();
if ($scope === 'full') {
$sgs = $this->find('all', array(
@ -378,33 +384,76 @@ class SharingGroup extends AppModel {
if (!$user['Role']['perm_sharing_group']) return false;
$this->create();
$newSG = array();
$attributes = array('name', 'releasability', 'description', 'uuid', 'organisation_uuid', 'created', 'modified');
foreach ($attributes as $a) $newSG[$a] = isset($sg[$a]) ? $sg[$a] : null;
$attributes = array(
'name' => array(),
'releasability' => array(),
'description' => array('default' => ''),
'uuid' => array('default' => CakeText::uuid()),
'organisation_uuid' => array('default' => $user['Organisation']['uuid']),
'created' => array('default' => $date = date('Y-m-d H:i:s')),
'modified' => array('default' => $date = date('Y-m-d H:i:s')),
'active' => array('default' => 1)
);
foreach (array_keys($attributes) as $a) {
if (isset($sg[$a])) {
$newSG[$a] = $sg[$a];
} else {
if (!isset($attributes[$a]['default'])) {
return false;
} else {
$newSG[$a] = $attributes[$a]['default'];
}
}
}
$newSG['local'] = 0;
$newSG['sync_user_id'] = $user['id'];
if (!isset($sg['Organisation'])) {
if (!isset($sg['SharingGroupOrg'])) return false;
foreach ($sg['SharingGroupOrg'] as $k => $org) {
if (isset($org['Organisation'][0])) $org['Organisation'] = $org['Organisation'][0];
if ($org['Organisation']['uuid'] == $sg['organisation_uuid']) $newSG['org_id'] = $this->Organisation->captureOrg($org['Organisation'], $user);
}
if (!$user['Role']['perm_sync']) {
$newSG['org_id'] = $user['org_id'];
} else {
$newSG['org_id'] = $this->Organisation->captureOrg($sg['Organisation'], $user);
if (!isset($sg['Organisation'])) {
if (!isset($sg['SharingGroupOrg'])) {
$sg['SharingGroupOrg'] = array(array(
'extend' => 1,
'uuid' => $user['Organisation']['uuid'],
'name' => $user['Organisation']['name'],
));
$newSG['org_id'] = $user['org_id'];
} else {
// Try to capture the creator organisation using the organisation_uuid if the org is contained in the SG (in some rare cases pre 2.4.86 the lack of this could occur)
foreach ($sg['SharingGroupOrg'] as $k => $org) {
if (!isset($org['Organisation'])) $org['Organisation'] = $org;
if (isset($org['Organisation'][0])) $org['Organisation'] = $org['Organisation'][0];
if (isset($sg['organisation_uuid'])) {
if ($org['Organisation']['uuid'] == $sg['organisation_uuid']) $newSG['org_id'] = $this->Organisation->captureOrg($org['Organisation'], $user);
} else {
$newSG['org_id'] = $user['org_id'];
}
}
}
} else {
$newSG['org_id'] = $this->Organisation->captureOrg($sg['Organisation'], $user);
}
}
if (empty($newSG['org_id'])) return false;
if (!$this->save($newSG)) return false;
$sgids = $this->id;
} else {
if (!$this->checkIfAuthorised($user, $existingSG['SharingGroup']['id']) && !$user['Role']['perm_sync']) {
return false;
}
if ($sg['modified'] > $existingSG['SharingGroup']['modified']) {
if ($user['Role']['perm_sync'] && $existingSG['SharingGroup']['local'] == 0) $force = true;
if (empty($sg['modified']) || $sg['modified'] > $existingSG['SharingGroup']['modified']) {
if (
($user['Role']['perm_sync'] && isset($existingSG['SharingGroup']['local']) && $existingSG['SharingGroup']['local'] == 0) ||
((!$user['Role']['perm_sync'] && $existingSG['org_id'] == $user['org_id']) || $user['Role']['perm_site_admin'])
) {
$force = true;
}
if ($force) {
$sgids = $existingSG['SharingGroup']['id'];
$editedSG = $existingSG['SharingGroup'];
$attributes = array('name', 'releasability', 'description', 'created', 'modified');
$attributes = array('name', 'releasability', 'description', 'created', 'modified', 'active');
foreach ($attributes as $a) {
$editedSG[$a] = $sg[$a];
if (isset($sg[$a])) $editedSG[$a] = $sg[$a];
}
$this->save($editedSG);
} else {
@ -415,75 +464,81 @@ class SharingGroup extends AppModel {
}
}
unset($sg['Organisation']);
if (isset($sg['SharingGroupOrg']['id'])) {
$temp = $sg['SharingGroupOrg'];
unset($sg['SharingGroupOrg']);
$sg['SharingGroupOrg'][0] = $temp;
}
$creatorOrgFound = false;
foreach ($sg['SharingGroupOrg'] as $k => $org) {
if (isset($org['Organisation'][0])) $org['Organisation'] = $org['Organisation'][0];
$sg['SharingGroupOrg'][$k]['org_id'] = $this->Organisation->captureOrg($org['Organisation'], $user, $force);
if ($sg['SharingGroupOrg'][$k]['org_id'] == $user['org_id']) $creatorOrgFound = true;
unset($sg['SharingGroupOrg'][$k]['Organisation']);
if ($force) {
// we are editing not creating here
$temp = $this->SharingGroupOrg->find('first', array(
'recursive' => -1,
'conditions' => array(
'sharing_group_id' => $existingSG['SharingGroup']['id'],
'org_id' => $sg['SharingGroupOrg'][$k]['org_id']
),
));
if (empty($temp)) {
$this->SharingGroupOrg->create();
$this->SharingGroupOrg->save(array('sharing_group_id' => $sgids, 'org_id' => $sg['SharingGroupOrg'][$k]['org_id'], 'extend' => $org['extend']));
} else {
if ($temp['SharingGroupOrg']['extend'] != $sg['SharingGroupOrg'][$k]['extend']) {
$temp['SharingGroupOrg']['extend'] = $sg['SharingGroupOrg'][$k]['extend'];
$this->SharingGroupOrg->save($temp['SharingGroupOrg']);
}
}
} else {
$this->SharingGroupOrg->create();
$this->SharingGroupOrg->save(array('sharing_group_id' => $sgids, 'org_id' => $sg['SharingGroupOrg'][$k]['org_id'], 'extend' => $org['extend']));
if (!empty($sg['SharingGroupOrg'])) {
$creatorOrgFound = false;
if (isset($sg['SharingGroupOrg']['id'])) {
$temp = $sg['SharingGroupOrg'];
unset($sg['SharingGroupOrg']);
$sg['SharingGroupOrg'][0] = $temp;
}
}
if (isset($sg['SharingGroupServer']['id'])) {
$temp = $sg['SharingGroupServer'];
unset($sg['SharingGroupServer']);
$sg['SharingGroupServer'][0] = $temp;
}
foreach ($sg['SharingGroupServer'] as $k => $server) {
if (isset($server[0])) $server = $server[0];
$sg['SharingGroupServer'][$k]['server_id'] = $this->SharingGroupServer->Server->captureServer($server['Server'], $user, $force);
if ($sg['SharingGroupServer'][$k]['server_id'] == 0 && $sg['SharingGroupServer'][$k]['all_orgs']) $creatorOrgFound = true;
if ($sg['SharingGroupServer'][$k]['server_id'] === false) unset($sg['SharingGroupServer'][$k]);
else {
foreach ($sg['SharingGroupOrg'] as $k => $org) {
if (empty($org['Organisation'])) $org['Organisation'] = $org;
if (isset($org['Organisation'][0])) $org['Organisation'] = $org['Organisation'][0];
$sg['SharingGroupOrg'][$k]['org_id'] = $this->Organisation->captureOrg($org['Organisation'], $user, $force);
if ($sg['SharingGroupOrg'][$k]['org_id'] == $user['org_id']) $creatorOrgFound = true;
unset($sg['SharingGroupOrg'][$k]['Organisation']);
if ($force) {
// we are editing not creating here
$temp = $this->SharingGroupServer->find('first', array(
$temp = $this->SharingGroupOrg->find('first', array(
'recursive' => -1,
'conditions' => array(
'sharing_group_id' => $existingSG['SharingGroup']['id'],
'server_id' => $sg['SharingGroupServer'][$k]['server_id']
'org_id' => $sg['SharingGroupOrg'][$k]['org_id']
),
));
if ($temp['SharingGroupServer']['all_orgs'] != $sg['SharingGroupServer'][$k]['all_orgs']) {
$temp['SharingGroupServer']['all_orgs'] = $sg['SharingGroupServer'][$k]['all_orgs'];
$this->SharingGroupServer->save($temp['SharingGroupServer']);
if (empty($temp)) {
$this->SharingGroupOrg->create();
$this->SharingGroupOrg->save(array('sharing_group_id' => $sgids, 'org_id' => $sg['SharingGroupOrg'][$k]['org_id'], 'extend' => $org['extend']));
} else {
if ($temp['SharingGroupOrg']['extend'] != $sg['SharingGroupOrg'][$k]['extend']) {
$temp['SharingGroupOrg']['extend'] = $sg['SharingGroupOrg'][$k]['extend'];
$this->SharingGroupOrg->save($temp['SharingGroupOrg']);
}
}
} else {
$this->SharingGroupServer->create();
$this->SharingGroupServer->save(array('sharing_group_id' => $sgids, 'server_id' => $sg['SharingGroupServer'][$k]['server_id'], 'all_orgs' => $server['all_orgs']));
$this->SharingGroupOrg->create();
$this->SharingGroupOrg->save(array('sharing_group_id' => $sgids, 'org_id' => $sg['SharingGroupOrg'][$k]['org_id'], 'extend' => $org['extend']));
}
}
}
if (!$creatorOrgFound && $user['Role']['perm_sync']) {
$this->SharingGroupOrg->create();
$this->SharingGroupOrg->save(array('sharing_group_id' => $sgids, 'org_id' => $user['org_id'], 'extend' => false));
if (!empty($sg['SharingGroupServer'])) {
if (isset($sg['SharingGroupServer']['id'])) {
$temp = $sg['SharingGroupServer'];
unset($sg['SharingGroupServer']);
$sg['SharingGroupServer'][0] = $temp;
}
foreach ($sg['SharingGroupServer'] as $k => $server) {
if (isset($server['Server'])) $server = $server['Server'];
if (isset($server[0])) $server = $server[0];
if (!isset($server['all_orgs'])) $sg['SharingGroupServer'][$k]['all_orgs'] = 0;
$sg['SharingGroupServer'][$k]['server_id'] = $this->SharingGroupServer->Server->captureServer($server, $user, $force);
if ($sg['SharingGroupServer'][$k]['server_id'] == 0 && !empty($sg['SharingGroupServer'][$k]['all_orgs'])) $creatorOrgFound = true;
if ($sg['SharingGroupServer'][$k]['server_id'] === false) unset($sg['SharingGroupServer'][$k]);
else {
if ($force) {
// we are editing not creating here
$temp = $this->SharingGroupServer->find('first', array(
'recursive' => -1,
'conditions' => array(
'sharing_group_id' => $existingSG['SharingGroup']['id'],
'server_id' => $sg['SharingGroupServer'][$k]['server_id']
),
));
if (empty($temp)) {
$this->SharingGroupServer->create();
$this->SharingGroupServer->save(array('sharing_group_id' => $sgids, 'server_id' => $sg['SharingGroupServer'][$k]['server_id'], 'all_orgs' => empty($server['all_orgs']) ? 0 : $server['all_orgs']));
} else {
if ($temp['SharingGroupServer']['all_orgs'] != $sg['SharingGroupServer'][$k]['all_orgs']) {
$temp['SharingGroupServer']['all_orgs'] = $sg['SharingGroupServer'][$k]['all_orgs'];
$this->SharingGroupServer->save($temp['SharingGroupServer']);
}
}
} else {
$this->SharingGroupServer->create();
$this->SharingGroupServer->save(array('sharing_group_id' => $sgids, 'server_id' => $sg['SharingGroupServer'][$k]['server_id'], 'all_orgs' => empty($server['all_orgs']) ? 0 : $server['all_orgs']));
}
}
}
}
if (!empty($existingSG)) return $existingSG[$this->alias]['id'];
return $this->id;

View File

@ -13,7 +13,7 @@
$debugMode == 'debugOn';
}
echo $this->Html->meta('icon');
echo $this->Html->css('roboto');
//echo $this->Html->css('roboto');
echo $this->Html->css('bootstrap');
echo $this->Html->css('bootstrap-datepicker');
echo $this->Html->css('bootstrap-timepicker');

View File

@ -10,7 +10,7 @@
</title>
<?php
echo $this->Html->meta('icon');
echo $this->Html->css('roboto');
//echo $this->Html->css('roboto');
echo $this->Html->css('bootstrap'); // see http://twitter.github.io/bootstrap/base-css.html
echo $this->Html->css('bootstrap-datepicker');
echo $this->Html->css('bootstrap-timepicker');

View File

@ -17,7 +17,7 @@
*/
?>
<?php
echo $this->Html->css('roboto');
//echo $this->Html->css('roboto');
echo $this->Html->css('bootstrap');
echo $this->Html->css('bootstrap-datepicker');
echo $this->Html->css('bootstrap-timepicker');

View File

@ -2754,9 +2754,9 @@ function getFormInfoContent(property, field) {
function formCategoryChanged(id) {
// fill in the types
var options = $('#AttributeType').prop('options');
$('option', $('#AttributeType')).remove();
$.each(category_type_mapping[$('#AttributeCategory').val()], function(val, text) {
var options = $('#' + id +'Type').prop('options');
$('option', $('#' + id +'Type')).remove();
$.each(category_type_mapping[$('#' + id +'Category').val()], function(val, text) {
options[options.length] = new Option(text, val);
});
// enable the form element